check if host is reachable

2,757 views
Skip to first unread message

will

unread,
Aug 10, 2013, 2:55:31 AM8/10/13
to golan...@googlegroups.com
Hi everyone,

I am a newbie to golang and loving it.

Is there a way to find out if a host is up or down.  In java i would do something like this:
 int timeOut = 3000; 
    boolean status = InetAddress.getByName(host).isReachable(timeOut);


Matt Silverlock

unread,
Aug 10, 2013, 6:14:53 AM8/10/13
to golan...@googlegroups.com

will

unread,
Aug 10, 2013, 12:14:02 PM8/10/13
to golan...@googlegroups.com
Hi Matt,

THanks for the reply but java is actually using icmp (ping) which i am not getting in go,. I hop[e there is some way of implementing it

On Saturday, 10 August 2013 12:14:53 UTC+2, Matt Silverlock wrote:
http://golang.org/pkg/net/#DialTimeout

Jan Mercl

unread,
Aug 10, 2013, 12:22:20 PM8/10/13
to will, golang-nuts
On Sat, Aug 10, 2013 at 6:14 PM, will <wma...@gmail.com> wrote:
> Hi Matt,
>
> THanks for the reply but java is actually using icmp (ping) which i am not
> getting in go,. I hop[e there is some way of implementing it

A server can ignore pings but can still serve some services at
specific ports. For example, _no_ publicly visible machine I'm
responsible for ever reacts to pings.

Just attempting to dial with a timeout is the correct approach. Java is wrong.

-j

will

unread,
Aug 10, 2013, 12:44:38 PM8/10/13
to golan...@googlegroups.com, will
Hi Jan,

I hear you but i am not just looking at servers.  I am also looking at client machines like in a network or network devices that may not be running any services

Ross Salas

unread,
Aug 10, 2013, 12:52:25 PM8/10/13
to will, golang-nuts
I was able to make my own ping function with referenced code.

HTH


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

justi...@gmail.com

unread,
Aug 23, 2016, 12:40:10 AM8/23/16
to golang-nuts
You can always call the OS's ping command from within go.  This isn't too terrible.  You can see a cross-platform example here: https://github.com/jcuga/goping
Reply all
Reply to author
Forward
0 new messages