./0000700000175000017500000000000011376400275007752 5ustar tonytony./Net-Ping-External-0.13/0000755000175000017500000000000011122530720013530 5ustar tonytony./Net-Ping-External-0.13/MANIFEST0000644000175000017500000000022511122530721014661 0ustar tonytonyChanges External.pm MANIFEST Makefile.PL README test.pl ToDo META.yml Module meta-data (added by MakeMaker) ./Net-Ping-External-0.13/Makefile.PL0000644000175000017500000000103011122530326015476 0ustar tonytonyuse ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Net::Ping::External', ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'External.pm', # retrieve abstract from module AUTHOR => 'Alexandr Ciornii ') : ()), 'VERSION_FROM' => 'External.pm', # finds $VERSION ($ExtUtils::MakeMaker::VERSION ge '6.31'? ('LICENSE' => 'perl', ) : ()), 'PREREQ_PM' => { Socket => 0, Carp => 0, # perl => '5.4', }, ); ./Net-Ping-External-0.13/test.pl0000644000175000017500000000656510563422374015075 0ustar tonytony# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; $num_tests = 6; print "1..$num_tests\n"; } END {print "not ok 1\n" unless $loaded;} use Net::Ping::External qw(ping); $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): %test_names = (1 => "use Net::Ping::External qw(ping)", 2 => "ping(host => '127.0.0.1')", 3 => "ping(host => '127.0.0.1', timeout => 5)", 4 => "ping(host => 'some.non.existent.host')", 5 => "ping(host => '127.0.0.1', count => 10)", 6 => "ping(host => '127.0.0.1', size => 32)" ); @passed = (); @failed = (); push @passed, 1 if $loaded; push @failed, 1 unless $loaded; eval { $ret = ping(host => '127.0.0.1') }; if (!$@ && $ret) { print "ok 2\n"; push @passed, 2; } else { print "not ok 2\n"; push @failed, 2; } eval { $ret = ping(host => '127.0.0.1', timeout => 5) }; if (!$@ && $ret) { print "ok 3\n"; push @passed, 3; } else { print "not ok 3\n"; push @failed, 3; } eval { $ret = ping(host => 'some.non.existent.host') }; if (!$@ && !$ret) { print "ok 4\n"; push @passed, 4; } else { print "not ok 4\n"; push @failed, 4; } eval { $ret = ping(host => '127.0.0.1', count => 2) }; if (!$@ && $ret) { print "ok 5\n"; push @passed, 5; } else { print "not ok 5\n"; push @failed, 5; } eval { $ret = ping(host => '127.0.0.1', size => 32) }; if (!$@ && $ret) { print "ok 6\n"; push @passed, 6; } else { print "not ok 6\n"; push @failed, 6; } print "\nRunning a more verbose test suite."; print "\n-------------------------------------------------\n"; print "Net::Ping::External version: ", $Net::Ping::External::VERSION, "\n"; print scalar(@passed), "/$num_tests tests passed.\n\n"; if (@passed) { print "Successful tests:\n"; foreach (@passed) { print "$test_names{$_}\n"; } } if (@failed) { print "\nFailed tests:\n"; foreach (@failed) { print "$test_names{$_}\n"; } } my @output = `$^X -v`; my $a=''; $a.= "\nOperating system according to perl: ".$^O."\n"; $a.= "Operating system according to `uname -a` (if available):\n"; $a.= `uname -a`; $a.= "Perl version: "; $a.= @output[1..1]; $a.= "Ping help: "; my $ping=($^O eq 'Netbsd'?Net::Ping::External::_locate_ping_netbsd():'ping'); $a.= `$ping 2>&1`; $a.="\n"; if (@failed and $failed[0]==5 and lc($^O) eq 'linux') { $a.="-\nping -c 1 some.non.existent.host\n"; $a.=`ping -c 1 some.non.existent.host`; $a.="\n-\n"; } open A,'>NPE.out'; print A $a; close A; print $a; print "-------------------------------------------------\n"; print "If any of the above tests failed, please e-mail the bits between the dashed\n"; print "lines or content of 'NPE.out' to alexchorny AT gmail.com This will help me in\n"; print "fixing this code for maximum portability to your platform. Thanks!\n"; print "\nTests: ".(@failed?"fail":"ok")."\n"; exit (@failed?1:0); ./Net-Ping-External-0.13/External.pm0000644000175000017500000003146511122530563015666 0ustar tonytonypackage Net::Ping::External; # Author: Colin McMillen (colinm AT cpan.org) # See also the CREDITS section in the POD below. # # Copyright (c) 2001-2003 Colin McMillen. All rights reserved. This # program is free software; you may redistribute it and/or modify it # under the same terms as Perl itself. # Copyright (c) 2006-2008 Alexandr Ciornii use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); use Carp; use Socket qw(inet_ntoa); require Exporter; $VERSION = "0.13"; @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(ping); sub ping { # Set up defaults & override defaults with parameters sent. my %args = (count => 1, size => 56, @_); # "host" and "hostname" are synonyms. $args{host} = $args{hostname} if defined $args{hostname}; # If we have an "ip" argument, convert it to a hostname and use that. $args{host} = inet_ntoa($args{ip}) if defined $args{ip}; # croak() if no hostname was provided. croak("You must provide a hostname") unless defined $args{host}; $args{timeout} = 5 unless defined $args{timeout} && $args{timeout} > 0; my %dispatch = (linux => \&_ping_linux, mswin32 => \&_ping_win32, cygwin => \&_ping_cygwin, solaris => \&_ping_solaris, bsdos => \&_ping_bsdos, beos => \&_ping_beos, hpux => \&_ping_hpux, dec_osf => \&_ping_dec_osf, bsd => \&_ping_bsd, darwin => \&_ping_darwin, openbsd => \&_ping_unix, freebsd => \&_ping_freebsd, next => \&_ping_next, unicosmk => \&_ping_unicosmk, netbsd => \&_ping_netbsd, irix => \&_ping_unix, aix => \&_ping_aix, ); my $subref = $dispatch{lc $^O}; croak("External ping not supported on your system") unless $subref; return $subref->(%args); } # Win32 is the only system so far for which we actually need to parse the # results of the system ping command. sub _ping_win32 { my %args = @_; $args{timeout} *= 1000; # Win32 ping timeout is specified in milliseconds #for each ping my $command = "ping -l $args{size} -n $args{count} -w $args{timeout} $args{host}"; print "$command\n" if $DEBUG; my $result = `$command`; return 1 if $result =~ /time.*ms/; return 1 if $result =~ /TTL/; return 1 if $result =~ /is alive/; # ppt (from CPAN) ping # return 1 if $result !~ /\(100%/; # 100% packages lost return 0; } # Mac OS X 10.2 ping does not handle -w timeout now does it return a # status code if it fails to ping (unless it cannot resolve the domain # name) # Thanks to Peter N. Lewis for this one. sub _ping_darwin { my %args = @_; my $command = "ping -s $args{size} -c $args{count} $args{host}"; my $devnull = "/dev/null"; $command .= " 2>$devnull"; print "$command\n" if $DEBUG; my $result = `$command`; return 1 if $result =~ /(\d+) packets received/ && $1 > 0; return 0; } # Generic subroutine to handle pinging using the system() function. Generally, # UNIX-like systems return 0 on a successful ping and something else on # failure. If the return value of running $command is equal to the value # specified as $success, the ping succeeds. Otherwise, it fails. sub _ping_system { my ($command, # The ping command to run $success, # What value the system ping command returns on success ) = @_; my $devnull = "/dev/null"; $command .= " 1>$devnull 2>$devnull"; print "#$command\n" if $DEBUG; my $exit_status = system($command) >> 8; return 1 if $exit_status == $success; return 0; } # Below are all the systems on which _ping_system() has been tested # and found OK. # Assumed OK for DEC OSF sub _ping_dec_osf { my %args = @_; my $command = "ping -c $args{count} -s $args{size} -q -u $args{host}"; return _ping_system($command, 0); } # Assumed OK for unicosmk sub _ping_unicosmk { my %args = @_; my $command = "ping -s $args{size} -c $args{count} $args{host}"; return _ping_system($command, 0); } # NeXTStep 3.3/sparc sub _ping_next { my %args = @_; my $command = "ping $args{host} $args{size} $args{count}"; return _ping_system($command, 0); } # Assumed OK for HP-UX. sub _ping_hpux { my %args = @_; my $command = "ping $args{host} $args{size} $args{count}"; return _ping_system($command, 0); } # Assumed OK for BSD/OS 4. sub _ping_bsdos { my %args = @_; my $command = "ping -c $args{count} -s $args{size} $args{host}"; return _ping_system($command, 0); } # Assumed OK for BeOS. sub _ping_beos { my %args = @_; my $command = "ping -c $args{count} -s $args{size} $args{host}"; return _ping_system($command, 0); } # Assumed OK for AIX sub _ping_aix { my %args = @_; my $command = "ping -c $args{count} -s $args{size} -q $args{host}"; return _ping_system($command, 0); } # OpenBSD 2.7 OK, IRIX 6.5 OK # Assumed OK for NetBSD & FreeBSD, but needs testing sub _ping_unix { my %args = @_; my $command = "ping -s $args{size} -c $args{count} -w $args{timeout} $args{host}"; return _ping_system($command, 0); } sub _locate_ping_netbsd { return '/usr/sbin/ping' if (-x '/usr/sbin/ping'); return 'ping'; } sub _ping_netbsd { my %args = @_; my $command = _locate_ping_netbsd()." -s $args{size} -c $args{count} -w $args{timeout} $args{host}"; return _ping_system($command, 0); } #-s size -c count -w timeout #http://netbsd.gw.com/cgi-bin/man-cgi?ping++NetBSD-current # Assumed OK for FreeBSD 3.4 # -s size option supported -- superuser only... fixme sub _ping_bsd { my %args = @_; my $command = "ping -c $args{count} -q $args{hostname}"; return _ping_system($command, 0); } # Debian 2.2 OK, RedHat 6.2 OK # -s size option available to superuser... FIXME? sub _ping_linux { my %args = @_; my $command; #for next version if (-e '/etc/redhat-release' || -e '/etc/SuSE-release') { $command = "ping -c $args{count} -s $args{size} $args{host}"; } else { $command = "ping -c $args{count} $args{host}"; } return _ping_system($command, 0); } # Solaris 2.6, 2.7 OK sub _ping_solaris { my %args = @_; my $command = "ping -s $args{host} $args{size} $args{timeout}"; return _ping_system($command, 0); } # FreeBSD. Tested OK for Freebsd 4.3 # -s size option supported -- superuser only... FIXME? # -w timeout option for BSD replaced by -t sub _ping_freebsd { my %args = @_; my $command = "ping -c $args{count} -t $args{timeout} $args{host}"; return _ping_system($command, 0); } #No timeout #Usage: ping [-dfqrv] host [packetsize [count [preload]]] sub _ping_cygwin { my %args = @_; my $command = "ping $args{host} $args{size} $args{count}"; return _ping_system($command, 0); } #Problem is that we may be running windows ping 1; __END__ =head1 NAME Net::Ping::External - Cross-platform interface to ICMP "ping" utilities =head1 SYNOPSIS In general: use Net::Ping::External qw(ping); ping(%options); Some examples: use Net::Ping::External qw(ping); # Ping a single host my $alive = ping(host => "127.0.0.1"); print "127.0.0.1 is online" if $alive; # Or a list of hosts my @hosts = qw(127.0.0.1 127.0.0.2 127.0.0.3 127.0.0.4); my $num_alive = 0; foreach (@hosts) { $alive = ping(hostname => $_, timeout => 5); print "$_ is alive!\n" if $alive; $num_alive++; } print "$num_alive hosts are alive.\n"; # Using all the fancy options: ping(hostname => "127.0.0.1", count => 5, size => 1024, timeout => 3); =head1 DESCRIPTION Net::Ping::External is a module which interfaces with the "ping" command on many systems. It presently provides a single function, C, that takes in a hostname and (optionally) a timeout and returns true if the host is alive, and false otherwise. Unless you have the ability (and willingness) to run your scripts as the superuser on your system, this module will probably provide more accurate results than Net::Ping will. Why? =over 4 =item * ICMP ping is the most reliable way to tell whether a remote host is alive. =item * However, Net::Ping cannot use an ICMP ping unless you are running your script with privileged (AKA "root") access. =item * The system's "ping" command uses ICMP and does not usually require privileged access. =item * While it is relatively trivial to write a Perl script that parses the output of the "ping" command on a given system, the aim of this module is to encapsulate this functionality and provide a single interface for it that works on many systems. =back =head2 ping() OPTIONS This module is still "alpha"; it is expected that more options to the C function will be added soon. =over 4 =item * C The hostname (or dotted-quad IP address) of the remote host you are trying to ping. You must specify either the "hostname" option or the "ip" option. "host" and "hostname" are synonymous. =item * C A packed bit-string representing the 4-byte packed IP address (as returned by C's C function) of the host that you would like to ping. =item * C The maximum amount of time, in seconds, that C will wait for a response. If the remote system does not respond before the timeout has elapsed, C will return false. Default value: 5. =item * C The number of ICMP ping packets to send to the remote host. Eventually, Net::Ping::External will return the number of packets that were acknowledged by the remote host; for now, however, C still returns just true or false. Default value: 1. =item * C Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data. Default value: 56. =back =head2 SUPPORTED PLATFORMS Support currently exists for interfacing with the standard ping utilities on the following systems. Please note that the path to the `ping' should be somewhere in your PATH environment variable (or your system's closest equivalent thereof.) Otherwise, Net::Ping::External will be unable to locate your system's `ping' command. =over 4 =item * Win32 Tested OK on Win98, Win XP. It should work on other Windows systems as well. =item * Cygwin Tested OK on Cygwin 1.5.21. Problem is that we may be running windows ping. They have different options. =item * Linux Tested OK on Debian 2.2 and Redhat 6.2. It appears that different versions of Linux use different versions of ping, which support different options. Not sure how I'm going to resolve this yet; for now, all the options but C are disabled. =item * BSD Tested OK on OpenBSD 2.7 and 3.0, Netbsd 1.5.3, Freebsd 4.6.2, 5.4. Needs testing for BSDi. =item * Solaris Tested OK on Solaris 2.6 and 2.7. =item * IRIX Tested OK on IRIX 6.5. =item * AIX, DEC OSF, UNICOSMK, NeXTStep, HP-UX, BSD/OS (BSDi), BeOS Support for these systems is integrated into this module but none have been tested yet. If you have successful or unsuccessful test results for any of these systems, please send them to me. On some of these systems, some of the arguments may not be supported. If you'd like to see better support on your system, please e-mail me. =back More systems will be added as soon as any users request them. If your system is not currently supported, e-mail me; adding support to your system is probably trivial. =head1 BUGS This module should be considered beta. Bugs may exist. Although no specific bugs are known at this time, the module could use testing on a greater variety of systems. See the warning below. =head1 WARNING This module calls whatever "ping" program it first finds in your PATH environment variable. If your PATH contains a trojan "ping" program, this module will call that program. This involves a small amount of risk, but no more than simply typing "ping" at a system prompt. Beware Greeks bearing gifts. =head1 AUTHOR Alexandr Ciornii (alexchorny AT gmail.com), Colin McMillen (colinm AT cpan.org) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 CREDITS Dan Moore contributed command-line options and code for NeXT, BeOS, HP-UX, and BSD/OS. Jarkko Hietaniemi contributed a huge list of command-line options and results for the `ping' command on 9 different systems. Randy Moore contributed several patches for Win32 support. Marc-Andre Dumas contributed a patch for FreeBSD support. Jonathan Stowe fixed a bug in 0.09 that prevented the module from running on some systems. Numerous people sent in a patch to fix a bug in 0.10 that broke ping on Windows systems. Peter N. Lewis contributed a patch that works correctly on Mac OS X 10.2 (and hopefully other versions as well). =head1 SEE ALSO Net::Ping =cut ./Net-Ping-External-0.13/Changes0000644000175000017500000000417011122530452015027 0ustar tonytonyRevision history for Perl extension Net::Ping::External. 0.13 Dec 18 2008 - Small fixes in test - Support of count param on RedHat-based systems and SuSE - Other small changes 0.12 = 0.12_02 Feb 08 2007 0.12_02: Feb 01 2007 - Full path to ping specified on NetBSD. 0.12_01: Sep 07 2006 Alexandr Ciornii appointed as comaintainer by CPAN admins - Updated e-mails to point to me. - Fixed ping for Cygwin, national Windows and Windows+ppt - Added more information for report - test.pl returns correct exit code (previously it always passed) 0.11: Feb 11 2003 - Fixed a problem that caused incorrect results in a lot of (and perhaps all?) versions of Windows. - Also fixed the _ping_bsd function to actually call ping and return a value (oops). - Peter N. Lewis submitted a _ping_darwin function that will hopefully work on all versions of Mac OS X. - Changed the test suite to only implore people to send me test results if there were any failures. - Test suite can now run non-interactively, as it doesn't prompt the user to hit enter. 0.10: Nov 10 2001 - Fixed unrecognized characters in _ping_freebsd that caused the module to die on some systems. (Thanks to Jonathan Stowe for the patch.) 0.09: Nov 10 2001 - Some additions and revisions to POD documentation. - Further fixes to Win32 support, by Randy Moore. - Fixes for FreeBSD support, by Marc-Andre Dumas. 0.08: Sep 30 2001 - Added support for cygwin port of perl, thanks to Alexei Gretchaninov. 0.07: Sep 27 2001 - Added support for Mac OS X (darwin) and fixed support for Win NT. (Thanks to Randy Moore for the fix.) 0.06: Apr 25 2001 - Added support for a fair number of new platforms. 0.05: Apr 20 2001 - Whoops, had a relatively major bug in 0.04 that made ping fail on most systems. Fixed that. 0.04: Apr 20 2001 - Added "count" and "size" options. 0.03: Mar 23 2001 - Removed "use warnings" and "use strict" directives. Should still work under warnings and strict, however. 0.02: Mar 21 2001 - Added "ip" option to the ping() function. - Fixed MANIFEST file. 0.01: Mar 11 2001 - Original version. ./Net-Ping-External-0.13/README0000644000175000017500000000061710561465553014435 0ustar tonytonyNet::Ping::External README Author: Alexandr Ciornii (alexchorny AT gmail.com) (2006-2007) Colin McMillen (colinm AT cpan.org) (2001-2003) Installation: ------------- perl Makefile.PL make make test make install ActiveState Installation: ------------- Package available from http://chorny.net/perlmod/ Description: ------------ See the POD in External.pm for more information. ./Net-Ping-External-0.13/ToDo0000644000175000017500000000025511115727051014331 0ustar tonytonyLinux distro detection: http://perlmonks.org/?node_id=578430 http://perlmonks.org/?node_id=578445 #cat /proc/version This task will be handled by Linux::Distribution ./Net-Ping-External-0.13/META.yml0000644000175000017500000000106511122530720015003 0ustar tonytony--- #YAML:1.0 name: Net-Ping-External version: 0.13 abstract: Cross-platform interface to ICMP "ping" utilities author: - Alexandr Ciornii license: perl distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 requires: Carp: 0 Socket: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.48 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4