Skip Menu |

This queue is for tickets about the Net-Ping CPAN distribution.

Report information
The Basics
Id: 6809
Status: resolved
Priority: 0/
Queue: Net-Ping

People
Owner: Nobody in particular
Requestors: kir [...] plusweb.ru
mselby [...] longitude.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.31
Fixed in: (no value)



Subject: ping returns true regardless of port_num
I have compiled perl 5.8.3 under RedHat advanced server 3.0 and RedHat Advanced server 2.1. Using the Net::Ping module to test the availibily of services outside of ICMP seems not to work. If I choose the tcp protocol and a port such as httpd or ssh the ping always returns 1 not matter what state the service is in. This is not a problem under perl 5.6.1 This snippet of code returns true even though there is no web server installed on the target host #!/usr/local/bin/perl -w use strict; use Net::Ping; my $p = Net::Ping->new("tcp", 3); $p->{port_num} = 80; return $p->ping("srv1.p.inf7"); Here is the output of perl -V mselby@util1a.h.ops1 /longitude/SOFT/perl5/5.8.3/lib/5.8.3/Net 4279$ /longitude/bin/perl -V Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration: Platform: osname=linux, osvers=2.4.21-9.elsmp, archname=i386-linux uname='linux bld2a.p.ops1.longitude.com 2.4.21-9.elsmp #1 smp thu jan 8 17:08:56 est 2004 i686 i686 i386 gnulinux ' config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dmksymlinks -Dcc=gcc -Dcccdlflags=-fPIC -Dprefix=/longitude/SOFT/perl5/5.8.3 -Dinstallprefix=/longitude/SOFT/perl5/5.8.3 -Dotherlibdirs=/longitude/lib/perl5 -Darchname=i386-linux -Dman3ext=3pm -Dmyhostname=localhost -Dperladmin=root@localhost -Uusethreads -Uuseithreads' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm', optimize='-O2 -g -pipe -march=i386 -mcpu=i686', cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm' ccversion='', gccversion='3.2.3 20030502 (Red Hat Linux 3.2.3-24)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.3.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING USE_LARGE_FILES Built under linux Compiled at Jun 3 2004 17:08:44 @INC: /longitude/SOFT/perl5/5.8.3/lib/5.8.3/i386-linux /longitude/SOFT/perl5/5.8.3/lib/5.8.3 /longitude/SOFT/perl5/5.8.3/lib/site_perl/5.8.3/i386-linux /longitude/SOFT/perl5/5.8.3/lib/site_perl/5.8.3 /longitude/SOFT/perl5/5.8.3/lib/site_perl /longitude/lib/perl5 .
Subject: Net::Ping fail on specified port
It looks like Ping to specific tcp port does not work on Fedora-4 linux. This program prints out the same result whatever http server on myhost:80 is alive or not. #!/usr/bin/perl use Net::Ping; $host= "myhost"; $p = Net::Ping->new("tcp", 2); $p->{port_num} = 80; ($a,$b,$c) = $p->ping($host); print "$a, $b, $c\n"; Kirill Makukhin
From: Simon Liu (yuntao.liu#gmail.com
It seems that only the origin version can work. The others version have same result whatever the port is. I have tested these on FreeBSD 5.4, Solaris 8/9/10, Mandrake Linux 8.2 and Ubuntu 5.10 On 2005-09-21 09:05:07 ζ˜ŸζœŸδΈ‰, guest wrote: Show quoted text
> It looks like Ping to specific tcp port does not work on Fedora-4 > linux. > > This program prints out the same result whatever http server on > myhost:80 is alive or not. > > #!/usr/bin/perl > use Net::Ping; > $host= "myhost"; > $p = Net::Ping->new("tcp", 2); > $p->{port_num} = 80; > ($a,$b,$c) = $p->ping($host); > print "$a, $b, $c\n"; > > Kirill Makukhin
From: riscguru [...] yahoo.com
I'm having the same problem on AIX. Changing to a previous version (copied 2.02... I know, ancient) over the 2.31 module fixed the issue. Thanks, Chris Young On Wed Sep 21 09:05:07 2005, guest wrote: Show quoted text
> It looks like Ping to specific tcp port does not work on Fedora-4 > linux. > > This program prints out the same result whatever http server on > myhost:80 is alive or not. > > #!/usr/bin/perl > use Net::Ping; > $host= "myhost"; > $p = Net::Ping->new("tcp", 2); > $p->{port_num} = 80; > ($a,$b,$c) = $p->ping($host); > print "$a, $b, $c\n"; > > Kirill Makukhin
On Mon Jun 19 15:15:34 2006, guest wrote: Show quoted text
> I'm having the same problem on AIX. Changing to a previous version > (copied 2.02... I know, ancient) over the 2.31 module fixed the issue. > > Thanks, > > Chris Young > > On Wed Sep 21 09:05:07 2005, guest wrote:
> > It looks like Ping to specific tcp port does not work on Fedora-4 > > linux. > > > > This program prints out the same result whatever http server on > > myhost:80 is alive or not. > > > > #!/usr/bin/perl > > use Net::Ping; > > $host= "myhost"; > > $p = Net::Ping->new("tcp", 2); > > $p->{port_num} = 80; > > ($a,$b,$c) = $p->ping($host); > > print "$a, $b, $c\n"; > > > > Kirill Makukhin
> >
This problem can be solved by calling $p->service_check(1); after setting the port number. This, however, seems to be a functionality problem. If you are trying to probe a specific port, most people are trying to see if that port is alive rather than just trying to see if that host is alive. The patch below adds a new method port_number(), automatically sets service_check(1) when specifying a port to probe. Steve Peters steve@fisharerojo.org --- Ping.pm 2007-05-11 22:40:44.000000000 -0500 +++ Ping.pm.new 2007-07-10 10:40:26.000000000 -0500 @@ -1363,6 +1363,15 @@ } } +sub port_number { + my $self = shift; + if(@_) { + $self->{port_num} = shift @_; + $self->service_check(1); + } + return $self->{port_num}; +} + 1; __END__ @@ -1392,7 +1401,7 @@ $p = Net::Ping->new("tcp", 2); # Try connecting to the www port instead of the echo port - $p->{port_num} = getservbyname("http", "tcp"); + $p->port_number(getservbyname("http", "tcp")); while ($stop_time > time()) { print "$host not reachable ", scalar(localtime()), "\n" @@ -1403,7 +1412,7 @@ # Like tcp protocol, but with many hosts $p = Net::Ping->new("syn"); - $p->{port_num} = getservbyname("http", "tcp"); + $p->port_number(getservbyname("http", "tcp")); foreach $host (@host_array) { $p->ping($host); } @@ -1625,6 +1634,14 @@ automatically closed if the ping object goes out of scope (e.g. $p is local to a subroutine and you leave the subroutine). +=item $p->port_number([$port_number]) + +When called with a port number, the port number used to ping is set to +$port_number rather than using the echo port. It also has the effect +of calling C<$p-E<gt>service_check(1)> causing a ping to return a successful +response only if that specific port is accessible. This function returns +the value of the port that C<ping()> will connect to. + =item pingecho($host [, $timeout]); To provide backward compatibility with the previous version of
On Tue Jul 10 11:48:56 2007, SMPETERS wrote: Show quoted text
> On Mon Jun 19 15:15:34 2006, guest wrote:
> > I'm having the same problem on AIX. Changing to a previous version > > (copied 2.02... I know, ancient) over the 2.31 module fixed the issue. > > > > Thanks, > > > > Chris Young > > > > On Wed Sep 21 09:05:07 2005, guest wrote:
> > > It looks like Ping to specific tcp port does not work on Fedora-4 > > > linux. > > > > > > This program prints out the same result whatever http server on > > > myhost:80 is alive or not. > > > > > > #!/usr/bin/perl > > > use Net::Ping; > > > $host= "myhost"; > > > $p = Net::Ping->new("tcp", 2); > > > $p->{port_num} = 80; > > > ($a,$b,$c) = $p->ping($host); > > > print "$a, $b, $c\n"; > > > > > > Kirill Makukhin
> > > >
> > This problem can be solved by calling > > $p->service_check(1); > > after setting the port number. > > This, however, seems to be a functionality problem. If you are trying > to probe a specific port, most people are trying to see if that port is > alive rather than just trying to see if that host is alive. The patch > below adds a new method port_number(), automatically sets > service_check(1) when specifying a port to probe. > > Steve Peters > steve@fisharerojo.org > > > --- Ping.pm 2007-05-11 22:40:44.000000000 -0500 > +++ Ping.pm.new 2007-07-10 10:40:26.000000000 -0500 > @@ -1363,6 +1363,15 @@ > } > } > > +sub port_number { > + my $self = shift; > + if(@_) { > + $self->{port_num} = shift @_; > + $self->service_check(1); > + } > + return $self->{port_num}; > +} > + > > 1; > __END__ > @@ -1392,7 +1401,7 @@ > > $p = Net::Ping->new("tcp", 2); > # Try connecting to the www port instead of the echo port > - $p->{port_num} = getservbyname("http", "tcp"); > + $p->port_number(getservbyname("http", "tcp")); > while ($stop_time > time()) > { > print "$host not reachable ", scalar(localtime()), "\n" > @@ -1403,7 +1412,7 @@ > > # Like tcp protocol, but with many hosts > $p = Net::Ping->new("syn"); > - $p->{port_num} = getservbyname("http", "tcp"); > + $p->port_number(getservbyname("http", "tcp")); > foreach $host (@host_array) { > $p->ping($host); > } > @@ -1625,6 +1634,14 @@ > automatically closed if the ping object goes out of scope (e.g. $p is > local to a subroutine and you leave the subroutine). > > +=item $p->port_number([$port_number]) > + > +When called with a port number, the port number used to ping is set to > +$port_number rather than using the echo port. It also has the effect > +of calling C<$p-E<gt>service_check(1)> causing a ping to return a > successful > +response only if that specific port is accessible. This function returns > +the value of the port that C<ping()> will connect to. > + > =item pingecho($host [, $timeout]); > > To provide backward compatibility with the previous version of
This patch was included in the 2.33 release.