5 unless ($ENV{PERL_TEST_Net_Ping}) {
6 print "1..0 # Skip: network dependent test\n";
10 unless (eval "require Socket") {
11 print "1..0 \# Skip: no Socket\n";
14 unless (getservbyname('echo', 'tcp')) {
15 print "1..0 \# Skip: no echo port\n";
18 unless (getservbyname('http', 'tcp')) {
19 print "1..0 \# Skip: no http port\n";
24 # Remote network test using syn protocol.
27 # Network connectivity will be required for all tests to pass.
28 # Firewalls may also cause some tests to fail, so test it
29 # on a clear network. If you know you do not have a direct
30 # connection to remote networks, but you still want the tests
31 # to pass, use the following:
33 # $ PERL_CORE=1 make test
35 # Try a few remote servers
39 # Hopefully this is never a routeable host
40 "172.29.249.249" => 0,
42 # Hopefully all these web ports are open
43 "www.geocities.com." => 1,
44 "www.freeservers.com." => 1,
46 "www.yahoo.com." => 1,
47 "www.about.com." => 1,
48 "www.microsoft.com." => 1,
53 use Test::More tests => 3 + 2 * keys %webs;
55 BEGIN {use_ok('Net::Ping')};
57 my $can_alarm = eval {alarm 0; 1;};
60 alarm(shift) if $can_alarm;
65 fail('Alarm timed out');
69 my $p = new Net::Ping "syn", 10;
71 isa_ok($p, 'Net::Ping', 'new() worked');
73 # Change to use the more common web port.
74 # (Make sure getservbyname works in scalar context.)
75 cmp_ok(($p->{port_num} = getservbyname("http", "tcp")), '>', 0, 'valid port');
77 foreach my $host (keys %webs) {
78 # ping() does dns resolution and
79 # only sends the SYN at this point
80 Alarm(50); # (Plenty for a DNS lookup)
81 is($p->ping($host), 1, "Can reach $host $p->{bad}->{$host}");
85 while (my $host = $p->ack()) {
86 is($webs{$host}, 1, "supposed to be up: http://$host/");
91 foreach my $host (keys %webs) {
92 is($webs{$host}, 0, "supposed to be down: http://$host/ [" . ($p->{bad}->{$host} || "") . "]");