in reply to Issues with network connectivity and Net::Ping

I think your problem is 'getservbyname' is not returning what you think it is. This works fine for me (Win7 x64 / Strawberry 5.18.1):

VinsWorldcom@C:\Users\VinsWorldcom\tmp> cat test.pl use strict; use warnings; use Net::Ping; my $p = Net::Ping->new("tcp", 2); printf "GetServByName = %s\n", getservbyname("http", "tcp"); # Explicitly use the HTTP port number $p->port_number(80); if ($p->ping("www.google.com")) { print "Host is reachable\n"; } else { print "Host is not reachable\n"; } VinsWorldcom@C:\Users\VinsWorldcom\tmp> test.pl GetServByName = http Host is reachable

Replies are listed 'Best First'.
Re^2: Issues with network connectivity and Net::Ping
by Steve_BZ (Chaplain) on Jan 30, 2014 at 17:24 UTC

    It's true. I just tested it and it works on Linux too.

    I'll time them both and see if I can get below the 500 ms that upset Karl so much. I think we should try to eliminate the interference of Solar Flares.

Re^2: Issues with network connectivity and Net::Ping
by Steve_BZ (Chaplain) on Jan 31, 2014 at 11:51 UTC

    Hi Guys,

    Well here are the timings (the code is at the bottom for you to critique):

    It is using a mobile router from three.com, so it may be less stable than a fibre optic connection.

    1) Here is a straight ping at t the command prompt (Range 75-400 ms):

    PING www.google.com (173.194.34.146) 56(84) bytes of data. 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=1 t +tl=55 time=394 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=2 t +tl=55 time=332 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=3 t +tl=55 time=362 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=4 t +tl=55 time=276 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=5 t +tl=55 time=92.4 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=6 t +tl=55 time=219 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=7 t +tl=55 time=116 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=8 t +tl=55 time=265 ms 64 bytes from lhr14s21-in-f18.1e100.net (173.194.34.146): icmp_seq=9 t +tl=55 time=75.9 ms ^C
    2) Here is the data from the programmatic pings:
    using Net::Ping (Range 500-1000 ms) 1031.06737136841 ms 729.610681533813 ms 1004.48346138 ms 775.990009307861 ms 600.036859512329 ms 589.807271957397 ms 754.30154800415 ms 605.571508407593 ms 560.036897659302 ms 782.053709030151 ms using Net::Ping::External (Range 400-800 ms) 791.388988494873 ms 570.100784301758 ms 687.773942947388 ms 402.096509933472 ms 430.928707122803 ms 398.749589920044 ms 712.586641311646 ms 837.354421615601 ms 560.385465621948 ms 650.154113769531 ms

    3) Here is the program:

    #!/usr/bin/perl -w use strict; use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep clock_gettime clock_getres clock_nanosleep clock stat lstat ); use strict; use warnings; use Net::Ping; print "using Net::Ping\n"; my $p = Net::Ping->new("tcp", 2); $p->port_number(80); my $basetime = clock_gettime(); my $realtime = clock_gettime(); my $roundtrip = ($realtime-$basetime) * 1000; for (my $i=1; $i<=10 ; $i++){ if ($p->ping("www.google.com")) { $realtime = clock_gettime(); $roundtrip = ($realtime-$basetime) * 1000; print $roundtrip," ms\n"; } else { print "Host is not reachable\n"; } $basetime = clock_gettime(); } use Net::Ping::External qw(ping); print "using Net::Ping::External\n"; #my $p = Net::Ping->new("tcp", 2); #$p->port_number(80); $basetime = clock_gettime(); $realtime = clock_gettime(); $roundtrip = ($realtime-$basetime) * 1000; for (my $i=1; $i<=10 ; $i++){ if (ping(host => "www.google.com")) { $realtime = clock_gettime(); $roundtrip = ($realtime-$basetime) * 1000; print $roundtrip," ms\n"; } else { print "Host is not reachable\n"; } $basetime = clock_gettime(); }

    I'm interested in your opinions.

    Actually everything takes too long. Rather than doing it synchronously, I'm thinking of setting a global variable which I set from a background loop every ten seconds. That way the information is recent, but i don't need to wait for it.

    Then I'll check the variable not the ping.

    Regards

    Steve