1use strict;
2
3BEGIN {
4  if ($ENV{PERL_CORE}) {
5    unless ($ENV{PERL_TEST_Net_Ping}) {
6      print "1..0 # Skip: network dependent test\n";
7        exit;
8    }
9  }
10  unless (eval "require Socket") {
11    print "1..0 \# Skip: no Socket\n";
12    exit;
13  }
14  unless (getservbyname('echo', 'tcp')) {
15    print "1..0 \# Skip: no echo port\n";
16    exit;
17  }
18}
19
20# Remote network test using tcp protocol.
21#
22# NOTE:
23#   Network connectivity will be required for all tests to pass.
24#   Firewalls may also cause some tests to fail, so test it
25#   on a clear network.  If you know you do not have a direct
26#   connection to remote networks, but you still want the tests
27#   to pass, use the following:
28#
29# $ PERL_CORE=1 make test
30
31use Test::More tests => 13;
32BEGIN {use_ok('Net::Ping');}
33
34my $p = new Net::Ping "tcp",9;
35
36isa_ok($p, 'Net::Ping', 'new() worked');
37
38isnt($p->ping("localhost"), 0, 'Test on the default port');
39
40# Change to use the more common web port.
41# This will pull from /etc/services on UNIX.
42# (Make sure getservbyname works in scalar context.)
43isnt($p->{port_num} = (getservbyname("http", "tcp") || 80), undef);
44
45isnt($p->ping("localhost"), 0, 'Test localhost on the web port');
46
47# Hopefully this is never a routeable host
48is($p->ping("172.29.249.249"), 0, "Can't reach 172.29.249.249");
49
50# Test a few remote servers
51# Hopefully they are up when the tests are run.
52
53foreach (qw(www.geocities.com www.wisc.edu
54	    www.freeservers.com ftp.freeservers.com
55	    yahoo.com www.yahoo.com www.about.com)) {
56    isnt($p->ping($_), 0, "Can ping $_");
57}
58