ping.html
来自「perl教程」· HTML 代码 · 共 448 行 · 第 1/2 页
HTML
448 行
<dd>
<p>Set whether or not the connect behavior should enforce
remote service availability as well as reachability. Normally,
if the remote server reported ECONNREFUSED, it must have been
reachable because of the status packet that it reported.
With this option enabled, the full three-way tcp handshake
must have been established successfully before it will
claim it is reachable. NOTE: It still does nothing more
than connect and disconnect. It does not speak any protocol
(i.e., HTTP or FTP) to ensure the remote server is sane in
any way. The remote server CPU could be grinding to a halt
and unresponsive to any clients connecting, but if the kernel
throws the ACK packet, it is considered alive anyway. To
really determine if the server is responding well would be
application specific and is beyond the scope of Net::Ping.
For udp protocol, enabling this option demands that the
remote server replies with the same udp data that it was sent
as defined by the udp echo service.</p>
</dd>
<dd>
<p>This affects the "udp", "tcp", and "syn" protocols.</p>
</dd>
<dd>
<p>This is disabled by default.</p>
</dd>
</li>
<dt><strong><a name="item_tcp_service_check">$p->tcp_service_check( { 0 | 1 } );</a></strong>
<dd>
<p>Depricated method, but does the same as <a href="#item_service_check"><code>service_check()</code></a> method.</p>
</dd>
</li>
<dt><strong><a name="item_hires">$p->hires( { 0 | 1 } );</a></strong>
<dd>
<p>Causes this module to use Time::HiRes module, allowing milliseconds
to be returned by subsequent calls to ping().</p>
</dd>
<dd>
<p>This is disabled by default.</p>
</dd>
</li>
<dt><strong><a name="item_bind">$p->bind($local_addr);</a></strong>
<dd>
<p>Sets the source address from which pings will be sent. This must be
the address of one of the interfaces on the local host. $local_addr
may be specified as a hostname or as a text IP address such as
"192.168.1.1".</p>
</dd>
<dd>
<p>If the protocol is set to "tcp", this method may be called any
number of times, and each call to the <a href="#item_ping"><code>ping()</code></a> method (below) will use
the most recent $local_addr. If the protocol is "icmp" or "udp",
then <a href="#item_bind"><code>bind()</code></a> must be called at most once per object, and (if it is
called at all) must be called before the first call to <a href="#item_ping"><code>ping()</code></a> for that
object.</p>
</dd>
</li>
<dt><strong><a name="item_open">$p->open($host);</a></strong>
<dd>
<p>When you are using the "stream" protocol, this call pre-opens the
tcp socket. It's only necessary to do this if you want to
provide a different timeout when creating the connection, or
remove the overhead of establishing the connection from the
first ping. If you don't call <a href="#item_open"><code>open()</code></a>, the connection is
automatically opened the first time <a href="#item_ping"><code>ping()</code></a> is called.
This call simply does nothing if you are using any protocol other
than stream.</p>
</dd>
</li>
<dt><strong><a name="item_ack">$p->ack( [ $host ] );</a></strong>
<dd>
<p>When using the "syn" protocol, use this method to determine
the reachability of the remote host. This method is meant
to be called up to as many times as <a href="#item_ping"><code>ping()</code></a> was called. Each
call returns the host (as passed to <a href="#item_ping"><code>ping())</code></a> that came back
with the TCP ACK. The order in which the hosts are returned
may not necessarily be the same order in which they were
SYN queued using the <a href="#item_ping"><code>ping()</code></a> method. If the timeout is
reached before the TCP ACK is received, or if the remote
host is not listening on the port attempted, then the TCP
connection will not be established and <a href="#item_ack"><code>ack()</code></a> will return
undef. In list context, the host, the ack time, and the
dotted ip string will be returned instead of just the host.
If the optional $host argument is specified, the return
value will be partaining to that host only.
This call simply does nothing if you are using any protocol
other than syn.</p>
</dd>
</li>
<dt><strong><a name="item_nack">$p->nack( $failed_ack_host );</a></strong>
<dd>
<p>The reason that host $failed_ack_host did not receive a
valid ACK. Useful to find out why when ack( $fail_ack_host )
returns a false value.</p>
</dd>
</li>
<dt><strong><a name="item_close">$p->close();</a></strong>
<dd>
<p>Close the network connection for this ping object. The network
connection is also closed by "undef $p". The network connection is
automatically closed if the ping object goes out of scope (e.g. $p is
local to a subroutine and you leave the subroutine).</p>
</dd>
</li>
<dt><strong><a name="item_pingecho">pingecho($host [, $timeout]);</a></strong>
<dd>
<p>To provide backward compatibility with the previous version of
Net::Ping, a <a href="#item_pingecho"><code>pingecho()</code></a> subroutine is available with the same
functionality as before. <a href="#item_pingecho"><code>pingecho()</code></a> uses the tcp protocol. The
return values and parameters are the same as described for the <a href="#item_ping"><code>ping()</code></a>
method. This subroutine is obsolete and may be removed in a future
version of Net::Ping.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="notes">NOTES</a></h1>
<p>There will be less network overhead (and some efficiency in your
program) if you specify either the udp or the icmp protocol. The tcp
protocol will generate 2.5 times or more traffic for each ping than
either udp or icmp. If many hosts are pinged frequently, you may wish
to implement a small wait (e.g. 25ms or more) between each ping to
avoid flooding your network with packets.</p>
<p>The icmp protocol requires that the program be run as root or that it
be setuid to root. The other protocols do not require special
privileges, but not all network devices implement tcp or udp echo.</p>
<p>Local hosts should normally respond to pings within milliseconds.
However, on a very congested network it may take up to 3 seconds or
longer to receive an echo packet from the remote host. If the timeout
is set too low under these conditions, it will appear that the remote
host is not reachable (which is almost the truth).</p>
<p>Reachability doesn't necessarily mean that the remote host is actually
functioning beyond its ability to echo packets. tcp is slightly better
at indicating the health of a system than icmp because it uses more
of the networking stack to respond.</p>
<p>Because of a lack of anything better, this module uses its own
routines to pack and unpack ICMP packets. It would be better for a
separate module to be written which understands all of the different
kinds of ICMP packets.</p>
<p>
</p>
<hr />
<h1><a name="install">INSTALL</a></h1>
<p>The latest source tree is available via cvs:</p>
<pre>
cvs -z3 -q -d :pserver:anonymous@cvs.roobik.com.:/usr/local/cvsroot/freeware checkout Net-Ping
cd Net-Ping</pre>
<p>The tarball can be created as follows:</p>
<pre>
<span class="variable">perl</span> <span class="variable">Makefile</span><span class="operator">.</span><span class="variable">PL</span> <span class="operator">;</span> <span class="variable">make</span> <span class="operator">;</span> <span class="variable">make</span> <span class="variable">dist</span>
</pre>
<p>The latest Net::Ping release can be found at CPAN:</p>
<pre>
$CPAN/modules/by-module/Net/</pre>
<p>1) Extract the tarball</p>
<pre>
gtar -zxvf Net-Ping-xxxx.tar.gz
cd Net-Ping-xxxx</pre>
<p>2) Build:</p>
<pre>
make realclean
perl Makefile.PL
make
make test</pre>
<p>3) Install</p>
<pre>
make install</pre>
<p>Or install it RPM Style:</p>
<pre>
rpm -ta SOURCES/Net-Ping-xxxx.tar.gz</pre>
<pre>
rpm -ih RPMS/noarch/perl-Net-Ping-xxxx.rpm</pre>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>For a list of known issues, visit:</p>
<p><a href="https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Ping">https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Ping</a></p>
<p>To report a new bug, visit:</p>
<p><a href="https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Ping">https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Ping</a></p>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<pre>
Current maintainer:
bbb@cpan.org (Rob Brown)</pre>
<pre>
External protocol:
colinm@cpan.org (Colin McMillen)</pre>
<pre>
Stream protocol:
bronson@trestle.com (Scott Bronson)</pre>
<pre>
Original pingecho():
karrer@bernina.ethz.ch (Andreas Karrer)
pmarquess@bfsec.bt.co.uk (Paul Marquess)</pre>
<pre>
Original Net::Ping author:
mose@ns.ccsn.edu (Russell Mosemann)</pre>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright (c) 2002-2003, Rob Brown. All rights reserved.</p>
<p>Copyright (c) 2001, Colin McMillen. All rights reserved.</p>
<p>This program is free software; you may redistribute it and/or
modify it under the same terms as Perl itself.</p>
<p>$Id: Ping.pm,v 1.86 2003/06/27 21:31:07 rob Exp $</p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?