Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Net / Ping.html
blob2c9984120493624f905cdf50daeb8170d4aa39b7
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>Net::Ping - check a remote host for reachability</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;Net::Ping - check a remote host for reachability</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <ul>
27 <li><a href="#functions">Functions</a></li>
28 </ul>
30 <li><a href="#notes">NOTES</a></li>
31 <li><a href="#install">INSTALL</a></li>
32 <li><a href="#bugs">BUGS</a></li>
33 <li><a href="#authors">AUTHORS</a></li>
34 <li><a href="#copyright">COPYRIGHT</a></li>
35 </ul>
36 <!-- INDEX END -->
38 <hr />
39 <p>
40 </p>
41 <h1><a name="name">NAME</a></h1>
42 <p>Net::Ping - check a remote host for reachability</p>
43 <p>
44 </p>
45 <hr />
46 <h1><a name="synopsis">SYNOPSIS</a></h1>
47 <pre>
48 use Net::Ping;</pre>
49 <pre>
50 $p = Net::Ping-&gt;new();
51 print &quot;$host is alive.\n&quot; if $p-&gt;ping($host);
52 $p-&gt;close();</pre>
53 <pre>
54 $p = Net::Ping-&gt;new(&quot;icmp&quot;);
55 $p-&gt;bind($my_addr); # Specify source interface of pings
56 foreach $host (@host_array)
58 print &quot;$host is &quot;;
59 print &quot;NOT &quot; unless $p-&gt;ping($host, 2);
60 print &quot;reachable.\n&quot;;
61 sleep(1);
63 $p-&gt;close();</pre>
64 <pre>
65 $p = Net::Ping-&gt;new(&quot;tcp&quot;, 2);
66 # Try connecting to the www port instead of the echo port
67 $p-&gt;{port_num} = getservbyname(&quot;http&quot;, &quot;tcp&quot;);
68 while ($stop_time &gt; time())
70 print &quot;$host not reachable &quot;, scalar(localtime()), &quot;\n&quot;
71 unless $p-&gt;ping($host);
72 sleep(300);
74 undef($p);</pre>
75 <pre>
76 # Like tcp protocol, but with many hosts
77 $p = Net::Ping-&gt;new(&quot;syn&quot;);
78 $p-&gt;{port_num} = getservbyname(&quot;http&quot;, &quot;tcp&quot;);
79 foreach $host (@host_array) {
80 $p-&gt;ping($host);
82 while (($host,$rtt,$ip) = $p-&gt;ack) {
83 print &quot;HOST: $host [$ip] ACKed in $rtt seconds.\n&quot;;
84 }</pre>
85 <pre>
86 # High precision syntax (requires Time::HiRes)
87 $p = Net::Ping-&gt;new();
88 $p-&gt;hires();
89 ($ret, $duration, $ip) = $p-&gt;ping($host, 5.5);
90 printf(&quot;$host [ip: $ip] is alive (packet return time: %.2f ms)\n&quot;, 1000 * $duration)
91 if $ret;
92 $p-&gt;close();</pre>
93 <pre>
94 # For backward compatibility
95 print &quot;$host is alive.\n&quot; if pingecho($host);</pre>
96 <p>
97 </p>
98 <hr />
99 <h1><a name="description">DESCRIPTION</a></h1>
100 <p>This module contains methods to test the reachability of remote
101 hosts on a network. A ping object is first created with optional
102 parameters, a variable number of hosts may be pinged multiple
103 times and then the connection is closed.</p>
104 <p>You may choose one of six different protocols to use for the
105 ping. The ``tcp'' protocol is the default. Note that a live remote host
106 may still fail to be pingable by one or more of these protocols. For
107 example, www.microsoft.com is generally alive but not ``icmp'' pingable.</p>
108 <p>With the ``tcp'' protocol the <a href="#item_ping"><code>ping()</code></a> method attempts to establish a
109 connection to the remote host's echo port. If the connection is
110 successfully established, the remote host is considered reachable. No
111 data is actually echoed. This protocol does not require any special
112 privileges but has higher overhead than the ``udp'' and ``icmp'' protocols.</p>
113 <p>Specifying the ``udp'' protocol causes the <a href="#item_ping"><code>ping()</code></a> method to send a udp
114 packet to the remote host's echo port. If the echoed packet is
115 received from the remote host and the received packet contains the
116 same data as the packet that was sent, the remote host is considered
117 reachable. This protocol does not require any special privileges.
118 It should be borne in mind that, for a udp ping, a host
119 will be reported as unreachable if it is not running the
120 appropriate echo service. For Unix-like systems see <em>inetd(8)</em>
121 for more information.</p>
122 <p>If the ``icmp'' protocol is specified, the <a href="#item_ping"><code>ping()</code></a> method sends an icmp
123 echo message to the remote host, which is what the UNIX ping program
124 does. If the echoed message is received from the remote host and
125 the echoed information is correct, the remote host is considered
126 reachable. Specifying the ``icmp'' protocol requires that the program
127 be run as root or that the program be setuid to root.</p>
128 <p>If the ``external'' protocol is specified, the <a href="#item_ping"><code>ping()</code></a> method attempts to
129 use the <code>Net::Ping::External</code> module to ping the remote host.
130 <code>Net::Ping::External</code> interfaces with your system's default <a href="#item_ping"><code>ping</code></a>
131 utility to perform the ping, and generally produces relatively
132 accurate results. If <code>Net::Ping::External</code> if not installed on your
133 system, specifying the ``external'' protocol will result in an error.</p>
134 <p>If the ``syn'' protocol is specified, the <a href="#item_ping"><code>ping()</code></a> method will only
135 send a TCP SYN packet to the remote host then immediately return.
136 If the syn packet was sent successfully, it will return a true value,
137 otherwise it will return false. NOTE: Unlike the other protocols,
138 the return value does NOT determine if the remote host is alive or
139 not since the full TCP three-way handshake may not have completed
140 yet. The remote host is only considered reachable if it receives
141 a TCP ACK within the timeout specifed. To begin waiting for the
142 ACK packets, use the <a href="#item_ack"><code>ack()</code></a> method as explained below. Use the
143 ``syn'' protocol instead the ``tcp'' protocol to determine reachability
144 of multiple destinations simultaneously by sending parallel TCP
145 SYN packets. It will not block while testing each remote host.
146 demo/fping is provided in this distribution to demonstrate the
147 ``syn'' protocol as an example.
148 This protocol does not require any special privileges.</p>
150 </p>
151 <h2><a name="functions">Functions</a></h2>
152 <dl>
153 <dt><strong><a name="item_new">Net::Ping-&gt;new([$proto [, $def_timeout [, $bytes [, $device [, $tos ]]]]]);</a></strong>
155 <dd>
156 <p>Create a new ping object. All of the parameters are optional. $proto
157 specifies the protocol to use when doing a ping. The current choices
158 are ``tcp'', ``udp'', ``icmp'', ``stream'', ``syn'', or ``external''.
159 The default is ``tcp''.</p>
160 </dd>
161 <dd>
162 <p>If a default timeout ($def_timeout) in seconds is provided, it is used
163 when a timeout is not given to the <a href="#item_ping"><code>ping()</code></a> method (below). The timeout
164 must be greater than 0 and the default, if not specified, is 5 seconds.</p>
165 </dd>
166 <dd>
167 <p>If the number of data bytes ($bytes) is given, that many data bytes
168 are included in the ping packet sent to the remote host. The number of
169 data bytes is ignored if the protocol is ``tcp''. The minimum (and
170 default) number of data bytes is 1 if the protocol is ``udp'' and 0
171 otherwise. The maximum number of data bytes that can be specified is
172 1024.</p>
173 </dd>
174 <dd>
175 <p>If $device is given, this device is used to bind the source endpoint
176 before sending the ping packet. I beleive this only works with
177 superuser privileges and with udp and icmp protocols at this time.</p>
178 </dd>
179 <dd>
180 <p>If $tos is given, this ToS is configured into the soscket.</p>
181 </dd>
182 </li>
183 <dt><strong><a name="item_ping">$p-&gt;ping($host [, $timeout]);</a></strong>
185 <dd>
186 <p>Ping the remote host and wait for a response. $host can be either the
187 hostname or the IP number of the remote host. The optional timeout
188 must be greater than 0 seconds and defaults to whatever was specified
189 when the ping object was created. Returns a success flag. If the
190 hostname cannot be found or there is a problem with the IP number, the
191 success flag returned will be undef. Otherwise, the success flag will
192 be 1 if the host is reachable and 0 if it is not. For most practical
193 purposes, undef and 0 and can be treated as the same case. In array
194 context, the elapsed time as well as the string form of the ip the
195 host resolved to are also returned. The elapsed time value will
196 be a float, as retuned by the Time::HiRes::time() function, if <a href="#item_hires"><code>hires()</code></a>
197 has been previously called, otherwise it is returned as an integer.</p>
198 </dd>
199 </li>
200 <dt><strong><a name="item_source_verify">$p-&gt;source_verify( { 0 | 1 } );</a></strong>
202 <dd>
203 <p>Allows source endpoint verification to be enabled or disabled.
204 This is useful for those remote destinations with multiples
205 interfaces where the response may not originate from the same
206 endpoint that the original destination endpoint was sent to.
207 This only affects udp and icmp protocol pings.</p>
208 </dd>
209 <dd>
210 <p>This is enabled by default.</p>
211 </dd>
212 </li>
213 <dt><strong><a name="item_service_check">$p-&gt;service_check( { 0 | 1 } );</a></strong>
215 <dd>
216 <p>Set whether or not the connect behavior should enforce
217 remote service availability as well as reachability. Normally,
218 if the remote server reported ECONNREFUSED, it must have been
219 reachable because of the status packet that it reported.
220 With this option enabled, the full three-way tcp handshake
221 must have been established successfully before it will
222 claim it is reachable. NOTE: It still does nothing more
223 than connect and disconnect. It does not speak any protocol
224 (i.e., HTTP or FTP) to ensure the remote server is sane in
225 any way. The remote server CPU could be grinding to a halt
226 and unresponsive to any clients connecting, but if the kernel
227 throws the ACK packet, it is considered alive anyway. To
228 really determine if the server is responding well would be
229 application specific and is beyond the scope of Net::Ping.
230 For udp protocol, enabling this option demands that the
231 remote server replies with the same udp data that it was sent
232 as defined by the udp echo service.</p>
233 </dd>
234 <dd>
235 <p>This affects the ``udp'', ``tcp'', and ``syn'' protocols.</p>
236 </dd>
237 <dd>
238 <p>This is disabled by default.</p>
239 </dd>
240 </li>
241 <dt><strong><a name="item_tcp_service_check">$p-&gt;tcp_service_check( { 0 | 1 } );</a></strong>
243 <dd>
244 <p>Depricated method, but does the same as <a href="#item_service_check"><code>service_check()</code></a> method.</p>
245 </dd>
246 </li>
247 <dt><strong><a name="item_hires">$p-&gt;hires( { 0 | 1 } );</a></strong>
249 <dd>
250 <p>Causes this module to use Time::HiRes module, allowing milliseconds
251 to be returned by subsequent calls to ping().</p>
252 </dd>
253 <dd>
254 <p>This is disabled by default.</p>
255 </dd>
256 </li>
257 <dt><strong><a name="item_bind">$p-&gt;bind($local_addr);</a></strong>
259 <dd>
260 <p>Sets the source address from which pings will be sent. This must be
261 the address of one of the interfaces on the local host. $local_addr
262 may be specified as a hostname or as a text IP address such as
263 ``192.168.1.1''.</p>
264 </dd>
265 <dd>
266 <p>If the protocol is set to ``tcp'', this method may be called any
267 number of times, and each call to the <a href="#item_ping"><code>ping()</code></a> method (below) will use
268 the most recent $local_addr. If the protocol is ``icmp'' or ``udp'',
269 then <a href="#item_bind"><code>bind()</code></a> must be called at most once per object, and (if it is
270 called at all) must be called before the first call to <a href="#item_ping"><code>ping()</code></a> for that
271 object.</p>
272 </dd>
273 </li>
274 <dt><strong><a name="item_open">$p-&gt;open($host);</a></strong>
276 <dd>
277 <p>When you are using the ``stream'' protocol, this call pre-opens the
278 tcp socket. It's only necessary to do this if you want to
279 provide a different timeout when creating the connection, or
280 remove the overhead of establishing the connection from the
281 first ping. If you don't call <a href="#item_open"><code>open()</code></a>, the connection is
282 automatically opened the first time <a href="#item_ping"><code>ping()</code></a> is called.
283 This call simply does nothing if you are using any protocol other
284 than stream.</p>
285 </dd>
286 </li>
287 <dt><strong><a name="item_ack">$p-&gt;ack( [ $host ] );</a></strong>
289 <dd>
290 <p>When using the ``syn'' protocol, use this method to determine
291 the reachability of the remote host. This method is meant
292 to be called up to as many times as <a href="#item_ping"><code>ping()</code></a> was called. Each
293 call returns the host (as passed to <a href="#item_ping"><code>ping())</code></a> that came back
294 with the TCP ACK. The order in which the hosts are returned
295 may not necessarily be the same order in which they were
296 SYN queued using the <a href="#item_ping"><code>ping()</code></a> method. If the timeout is
297 reached before the TCP ACK is received, or if the remote
298 host is not listening on the port attempted, then the TCP
299 connection will not be established and <a href="#item_ack"><code>ack()</code></a> will return
300 undef. In list context, the host, the ack time, and the
301 dotted ip string will be returned instead of just the host.
302 If the optional $host argument is specified, the return
303 value will be partaining to that host only.
304 This call simply does nothing if you are using any protocol
305 other than syn.</p>
306 </dd>
307 </li>
308 <dt><strong><a name="item_nack">$p-&gt;nack( $failed_ack_host );</a></strong>
310 <dd>
311 <p>The reason that host $failed_ack_host did not receive a
312 valid ACK. Useful to find out why when ack( $fail_ack_host )
313 returns a false value.</p>
314 </dd>
315 </li>
316 <dt><strong><a name="item_close">$p-&gt;close();</a></strong>
318 <dd>
319 <p>Close the network connection for this ping object. The network
320 connection is also closed by ``undef $p''. The network connection is
321 automatically closed if the ping object goes out of scope (e.g. $p is
322 local to a subroutine and you leave the subroutine).</p>
323 </dd>
324 </li>
325 <dt><strong><a name="item_pingecho">pingecho($host [, $timeout]);</a></strong>
327 <dd>
328 <p>To provide backward compatibility with the previous version of
329 Net::Ping, a <a href="#item_pingecho"><code>pingecho()</code></a> subroutine is available with the same
330 functionality as before. <a href="#item_pingecho"><code>pingecho()</code></a> uses the tcp protocol. The
331 return values and parameters are the same as described for the <a href="#item_ping"><code>ping()</code></a>
332 method. This subroutine is obsolete and may be removed in a future
333 version of Net::Ping.</p>
334 </dd>
335 </li>
336 </dl>
338 </p>
339 <hr />
340 <h1><a name="notes">NOTES</a></h1>
341 <p>There will be less network overhead (and some efficiency in your
342 program) if you specify either the udp or the icmp protocol. The tcp
343 protocol will generate 2.5 times or more traffic for each ping than
344 either udp or icmp. If many hosts are pinged frequently, you may wish
345 to implement a small wait (e.g. 25ms or more) between each ping to
346 avoid flooding your network with packets.</p>
347 <p>The icmp protocol requires that the program be run as root or that it
348 be setuid to root. The other protocols do not require special
349 privileges, but not all network devices implement tcp or udp echo.</p>
350 <p>Local hosts should normally respond to pings within milliseconds.
351 However, on a very congested network it may take up to 3 seconds or
352 longer to receive an echo packet from the remote host. If the timeout
353 is set too low under these conditions, it will appear that the remote
354 host is not reachable (which is almost the truth).</p>
355 <p>Reachability doesn't necessarily mean that the remote host is actually
356 functioning beyond its ability to echo packets. tcp is slightly better
357 at indicating the health of a system than icmp because it uses more
358 of the networking stack to respond.</p>
359 <p>Because of a lack of anything better, this module uses its own
360 routines to pack and unpack ICMP packets. It would be better for a
361 separate module to be written which understands all of the different
362 kinds of ICMP packets.</p>
364 </p>
365 <hr />
366 <h1><a name="install">INSTALL</a></h1>
367 <p>The latest source tree is available via cvs:</p>
368 <pre>
369 cvs -z3 -q -d :pserver:anonymous@cvs.roobik.com.:/usr/local/cvsroot/freeware checkout Net-Ping
370 cd Net-Ping</pre>
371 <p>The tarball can be created as follows:</p>
372 <pre>
373 perl Makefile.PL ; make ; make dist</pre>
374 <p>The latest Net::Ping release can be found at CPAN:</p>
375 <pre>
376 $CPAN/modules/by-module/Net/</pre>
377 <p>1) Extract the tarball</p>
378 <pre>
379 gtar -zxvf Net-Ping-xxxx.tar.gz
380 cd Net-Ping-xxxx</pre>
381 <p>2) Build:</p>
382 <pre>
383 make realclean
384 perl Makefile.PL
385 make
386 make test</pre>
387 <p>3) Install</p>
388 <pre>
389 make install</pre>
390 <p>Or install it RPM Style:</p>
391 <pre>
392 rpm -ta SOURCES/Net-Ping-xxxx.tar.gz</pre>
393 <pre>
394 rpm -ih RPMS/noarch/perl-Net-Ping-xxxx.rpm</pre>
396 </p>
397 <hr />
398 <h1><a name="bugs">BUGS</a></h1>
399 <p>For a list of known issues, visit:</p>
400 <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>
401 <p>To report a new bug, visit:</p>
402 <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>
404 </p>
405 <hr />
406 <h1><a name="authors">AUTHORS</a></h1>
407 <pre>
408 Current maintainer:
409 bbb@cpan.org (Rob Brown)</pre>
410 <pre>
411 External protocol:
412 colinm@cpan.org (Colin McMillen)</pre>
413 <pre>
414 Stream protocol:
415 bronson@trestle.com (Scott Bronson)</pre>
416 <pre>
417 Original pingecho():
418 karrer@bernina.ethz.ch (Andreas Karrer)
419 pmarquess@bfsec.bt.co.uk (Paul Marquess)</pre>
420 <pre>
421 Original Net::Ping author:
422 mose@ns.ccsn.edu (Russell Mosemann)</pre>
424 </p>
425 <hr />
426 <h1><a name="copyright">COPYRIGHT</a></h1>
427 <p>Copyright (c) 2002-2003, Rob Brown. All rights reserved.</p>
428 <p>Copyright (c) 2001, Colin McMillen. All rights reserved.</p>
429 <p>This program is free software; you may redistribute it and/or
430 modify it under the same terms as Perl itself.</p>
431 <p>$Id: Ping.pm,v 1.86 2003/06/27 21:31:07 rob Exp $</p>
432 <table border="0" width="100%" cellspacing="0" cellpadding="3">
433 <tr><td class="block" style="background-color: #cccccc" valign="middle">
434 <big><strong><span class="block">&nbsp;Net::Ping - check a remote host for reachability</span></strong></big>
435 </td></tr>
436 </table>
438 </body>
440 </html>