📄 net::ping.3
字号:
If the number of data bytes ($bytes) is given, that many data bytesare included in the ping packet sent to the remote host. The number ofdata bytes is ignored if the protocol is \*(L"tcp\*(R". The minimum (anddefault) number of data bytes is 1 if the protocol is \*(L"udp\*(R" and 0otherwise. The maximum number of data bytes that can be specified is1024..SpIf \f(CW$device\fR is given, this device is used to bind the source endpointbefore sending the ping packet. I believe this only works withsuperuser privileges and with udp and icmp protocols at this time..SpIf \f(CW$tos\fR is given, this ToS is configured into the socket..ie n .IP "$p\fR\->ping($host [, \f(CW$timeout]);" 4.el .IP "\f(CW$p\fR\->ping($host [, \f(CW$timeout\fR]);" 4.IX Item "$p->ping($host [, $timeout]);"Ping the remote host and wait for a response. \f(CW$host\fR can be either thehostname or the \s-1IP\s0 number of the remote host. The optional timeoutmust be greater than 0 seconds and defaults to whatever was specifiedwhen the ping object was created. Returns a success flag. If thehostname cannot be found or there is a problem with the \s-1IP\s0 number, thesuccess flag returned will be undef. Otherwise, the success flag willbe 1 if the host is reachable and 0 if it is not. For most practicalpurposes, undef and 0 and can be treated as the same case. In arraycontext, the elapsed time as well as the string form of the ip thehost resolved to are also returned. The elapsed time value willbe a float, as retuned by the \fITime::HiRes::time()\fR function, if \fIhires()\fRhas been previously called, otherwise it is returned as an integer..ie n .IP "$p\->source_verify( { 0 | 1 } );" 4.el .IP "\f(CW$p\fR\->source_verify( { 0 | 1 } );" 4.IX Item "$p->source_verify( { 0 | 1 } );"Allows source endpoint verification to be enabled or disabled.This is useful for those remote destinations with multiplesinterfaces where the response may not originate from the sameendpoint that the original destination endpoint was sent to.This only affects udp and icmp protocol pings..SpThis is enabled by default..ie n .IP "$p\->service_check( { 0 | 1 } );" 4.el .IP "\f(CW$p\fR\->service_check( { 0 | 1 } );" 4.IX Item "$p->service_check( { 0 | 1 } );"Set whether or not the connect behavior should enforceremote service availability as well as reachability. Normally,if the remote server reported \s-1ECONNREFUSED\s0, it must have beenreachable because of the status packet that it reported.With this option enabled, the full three-way tcp handshakemust have been established successfully before it willclaim it is reachable. \s-1NOTE:\s0 It still does nothing morethan connect and disconnect. It does not speak any protocol(i.e., \s-1HTTP\s0 or \s-1FTP\s0) to ensure the remote server is sane inany way. The remote server \s-1CPU\s0 could be grinding to a haltand unresponsive to any clients connecting, but if the kernelthrows the \s-1ACK\s0 packet, it is considered alive anyway. Toreally determine if the server is responding well would beapplication specific and is beyond the scope of Net::Ping.For udp protocol, enabling this option demands that theremote server replies with the same udp data that it was sentas defined by the udp echo service..SpThis affects the \*(L"udp\*(R", \*(L"tcp\*(R", and \*(L"syn\*(R" protocols..SpThis is disabled by default..ie n .IP "$p\->tcp_service_check( { 0 | 1 } );" 4.el .IP "\f(CW$p\fR\->tcp_service_check( { 0 | 1 } );" 4.IX Item "$p->tcp_service_check( { 0 | 1 } );"Deprecated method, but does the same as \fIservice_check()\fR method..ie n .IP "$p\->hires( { 0 | 1 } );" 4.el .IP "\f(CW$p\fR\->hires( { 0 | 1 } );" 4.IX Item "$p->hires( { 0 | 1 } );"Causes this module to use Time::HiRes module, allowing millisecondsto be returned by subsequent calls to \fIping()\fR..SpThis is disabled by default..ie n .IP "$p\->bind($local_addr);" 4.el .IP "\f(CW$p\fR\->bind($local_addr);" 4.IX Item "$p->bind($local_addr);"Sets the source address from which pings will be sent. This must bethe address of one of the interfaces on the local host. \f(CW$local_addr\fRmay be specified as a hostname or as a text \s-1IP\s0 address such as\&\*(L"192.168.1.1\*(R"..SpIf the protocol is set to \*(L"tcp\*(R", this method may be called anynumber of times, and each call to the \fIping()\fR method (below) will usethe most recent \f(CW$local_addr\fR. If the protocol is \*(L"icmp\*(R" or \*(L"udp\*(R",then \fIbind()\fR must be called at most once per object, and (if it iscalled at all) must be called before the first call to \fIping()\fR for thatobject..ie n .IP "$p\->open($host);" 4.el .IP "\f(CW$p\fR\->open($host);" 4.IX Item "$p->open($host);"When you are using the \*(L"stream\*(R" protocol, this call pre-opens thetcp socket. It's only necessary to do this if you want toprovide a different timeout when creating the connection, orremove the overhead of establishing the connection from thefirst ping. If you don't call \f(CW\*(C`open()\*(C'\fR, the connection isautomatically opened the first time \f(CW\*(C`ping()\*(C'\fR is called.This call simply does nothing if you are using any protocol otherthan stream..ie n .IP "$p\fR\->ack( [ \f(CW$host ] );" 4.el .IP "\f(CW$p\fR\->ack( [ \f(CW$host\fR ] );" 4.IX Item "$p->ack( [ $host ] );"When using the \*(L"syn\*(R" protocol, use this method to determinethe reachability of the remote host. This method is meantto be called up to as many times as \fIping()\fR was called. Eachcall returns the host (as passed to \fIping()\fR) that came backwith the \s-1TCP\s0 \s-1ACK\s0. The order in which the hosts are returnedmay not necessarily be the same order in which they were\&\s-1SYN\s0 queued using the \fIping()\fR method. If the timeout isreached before the \s-1TCP\s0 \s-1ACK\s0 is received, or if the remotehost is not listening on the port attempted, then the \s-1TCP\s0connection will not be established and \fIack()\fR will returnundef. In list context, the host, the ack time, and thedotted ip string will be returned instead of just the host.If the optional \f(CW$host\fR argument is specified, the returnvalue will be pertaining to that host only.This call simply does nothing if you are using any protocolother than syn..ie n .IP "$p\fR\->nack( \f(CW$failed_ack_host );" 4.el .IP "\f(CW$p\fR\->nack( \f(CW$failed_ack_host\fR );" 4.IX Item "$p->nack( $failed_ack_host );"The reason that host \f(CW$failed_ack_host\fR did not receive avalid \s-1ACK\s0. Useful to find out why when ack( \f(CW$fail_ack_host\fR )returns a false value..ie n .IP "$p\fR\->\fIclose();" 4.el .IP "\f(CW$p\fR\->\fIclose()\fR;" 4.IX Item "$p->close();"Close the network connection for this ping object. The networkconnection is also closed by \*(L"undef \f(CW$p\fR\*(R". The network connection isautomatically closed if the ping object goes out of scope (e.g. \f(CW$p\fR islocal to a subroutine and you leave the subroutine)..ie n .IP "$p\->port_number([$port_number])" 4.el .IP "\f(CW$p\fR\->port_number([$port_number])" 4.IX Item "$p->port_number([$port_number])"When called with a port number, the port number used to ping is set to\&\f(CW$port_number\fR rather than using the echo port. It also has the effectof calling \f(CW\*(C`$p\->service_check(1)\*(C'\fR causing a ping to return a successfulresponse only if that specific port is accessible. This function returnsthe value of the port that \f(CW\*(C`ping()\*(C'\fR will connect to..ie n .IP "pingecho($host [, $timeout]);" 4.el .IP "pingecho($host [, \f(CW$timeout\fR]);" 4.IX Item "pingecho($host [, $timeout]);"To provide backward compatibility with the previous version ofNet::Ping, a \fIpingecho()\fR subroutine is available with the samefunctionality as before. \fIpingecho()\fR uses the tcp protocol. Thereturn values and parameters are the same as described for the \fIping()\fRmethod. This subroutine is obsolete and may be removed in a futureversion of Net::Ping..SH "NOTES".IX Header "NOTES"There will be less network overhead (and some efficiency in yourprogram) if you specify either the udp or the icmp protocol. The tcpprotocol will generate 2.5 times or more traffic for each ping thaneither udp or icmp. If many hosts are pinged frequently, you may wishto implement a small wait (e.g. 25ms or more) between each ping toavoid flooding your network with packets..PPThe icmp protocol requires that the program be run as root or that itbe setuid to root. The other protocols do not require specialprivileges, but not all network devices implement tcp or udp echo..PPLocal hosts should normally respond to pings within milliseconds.However, on a very congested network it may take up to 3 seconds orlonger to receive an echo packet from the remote host. If the timeoutis set too low under these conditions, it will appear that the remotehost is not reachable (which is almost the truth)..PPReachability doesn't necessarily mean that the remote host is actuallyfunctioning beyond its ability to echo packets. tcp is slightly betterat indicating the health of a system than icmp because it uses moreof the networking stack to respond..PPBecause of a lack of anything better, this module uses its ownroutines to pack and unpack \s-1ICMP\s0 packets. It would be better for aseparate module to be written which understands all of the differentkinds of \s-1ICMP\s0 packets..SH "INSTALL".IX Header "INSTALL"The latest source tree is available via cvs:.PP.Vb 2\& cvs \-z3 \-q \-d :pserver:anonymous@cvs.roobik.com.:/usr/local/cvsroot/freeware checkout Net\-Ping\& cd Net\-Ping.Ve.PPThe tarball can be created as follows:.PP.Vb 1\& perl Makefile.PL ; make ; make dist.Ve.PPThe latest Net::Ping release can be found at \s-1CPAN:\s0.PP.Vb 1\& $CPAN/modules/by\-module/Net/.Ve.PP1) Extract the tarball.PP.Vb 2\& gtar \-zxvf Net\-Ping\-xxxx.tar.gz\& cd Net\-Ping\-xxxx.Ve.PP2) Build:.PP.Vb 4\& make realclean\& perl Makefile.PL\& make\& make test.Ve.PP3) Install.PP.Vb 1\& make install.Ve.PPOr install it \s-1RPM\s0 Style:.PP.Vb 1\& rpm \-ta SOURCES/Net\-Ping\-xxxx.tar.gz\&\& rpm \-ih RPMS/noarch/perl\-Net\-Ping\-xxxx.rpm.Ve.SH "BUGS".IX Header "BUGS"For a list of known issues, visit:.PPhttps://rt.cpan.org/NoAuth/Bugs.html?Dist=Net\-Ping.PPTo report a new bug, visit:.PPhttps://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net\-Ping.SH "AUTHORS".IX Header "AUTHORS".Vb 2\& Current maintainer:\& bbb@cpan.org (Rob Brown)\&\& External protocol:\& colinm@cpan.org (Colin McMillen)\&\& Stream protocol:\& bronson@trestle.com (Scott Bronson)\&\& Original pingecho():\& karrer@bernina.ethz.ch (Andreas Karrer)\& pmarquess@bfsec.bt.co.uk (Paul Marquess)\&\& Original Net::Ping author:\& mose@ns.ccsn.edu (Russell Mosemann).Ve.SH "COPYRIGHT".IX Header "COPYRIGHT"Copyright (c) 2002\-2003, Rob Brown. All rights reserved..PPCopyright (c) 2001, Colin McMillen. All rights reserved..PPThis program is free software; you may redistribute it and/ormodify it under the same terms as Perl itself..PP\&\f(CW$Id:\fR Ping.pm,v 1.86 2003/06/27 21:31:07 rob Exp $
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -