summaryrefslogtreecommitdiff
path: root/dist/Net-Ping/t/200_ping_tcp.t
blob: 0f592341f94252548ff03de1c870f900aee2723f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
BEGIN {
  if ($ENV{PERL_CORE}) {
    unless ($ENV{PERL_TEST_Net_Ping}) {
      print "1..0 # Skip: network dependent test\n";
        exit;
    }
  }
  unless (eval "require Socket") {
    print "1..0 \# Skip: no Socket\n";
    exit;
  }
  unless (getservbyname('echo', 'tcp')) {
    print "1..0 \# Skip: no echo port\n";
    exit;
  }
}

# Remote network test using tcp protocol.
#
# NOTE:
#   Network connectivity will be required for all tests to pass.
#   Firewalls may also cause some tests to fail, so test it
#   on a clear network.  If you know you do not have a direct
#   connection to remote networks, but you still want the tests
#   to pass, use the following:
#
# $ PERL_CORE=1 make test

use Test;
use Net::Ping;
plan tests => 13;

# Everything loaded fine
ok 1;

my $p = new Net::Ping "tcp",9;

# new() worked?
ok !!$p;

# Test on the default port
ok $p -> ping("localhost");

# Change to use the more common web port.
# This will pull from /etc/services on UNIX.
# (Make sure getservbyname works in scalar context.)
ok ($p -> {port_num} = (getservbyname("http", "tcp") || 80));

# Test localhost on the web port
ok $p -> ping("localhost");

# Hopefully this is never a routeable host
ok !$p -> ping("172.29.249.249");

# Test a few remote servers
# Hopefully they are up when the tests are run.

ok $p -> ping("www.geocities.com");
ok $p -> ping("ftp.geocities.com");

ok $p -> ping("www.freeservers.com");
ok $p -> ping("ftp.freeservers.com");

ok $p -> ping("yahoo.com");
ok $p -> ping("www.yahoo.com");
ok $p -> ping("www.about.com");