Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "Net::Ping 3" | |
132 | .TH Net::Ping 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | Net::Ping \- check a remote host for reachability | |
135 | .PP | |
136 | $Id: Ping.pm,v 1.6 2002/06/19 15:23:48 rob Exp $ | |
137 | .SH "SYNOPSIS" | |
138 | .IX Header "SYNOPSIS" | |
139 | .Vb 1 | |
140 | \& use Net::Ping; | |
141 | .Ve | |
142 | .PP | |
143 | .Vb 3 | |
144 | \& $p = Net::Ping->new(); | |
145 | \& print "$host is alive.\en" if $p->ping($host); | |
146 | \& $p->close(); | |
147 | .Ve | |
148 | .PP | |
149 | .Vb 10 | |
150 | \& $p = Net::Ping->new("icmp"); | |
151 | \& $p->bind($my_addr); # Specify source interface of pings | |
152 | \& foreach $host (@host_array) | |
153 | \& { | |
154 | \& print "$host is "; | |
155 | \& print "NOT " unless $p->ping($host, 2); | |
156 | \& print "reachable.\en"; | |
157 | \& sleep(1); | |
158 | \& } | |
159 | \& $p->close(); | |
160 | .Ve | |
161 | .PP | |
162 | .Vb 10 | |
163 | \& $p = Net::Ping->new("tcp", 2); | |
164 | \& # Try connecting to the www port instead of the echo port | |
165 | \& $p->{port_num} = getservbyname("http", "tcp"); | |
166 | \& while ($stop_time > time()) | |
167 | \& { | |
168 | \& print "$host not reachable ", scalar(localtime()), "\en" | |
169 | \& unless $p->ping($host); | |
170 | \& sleep(300); | |
171 | \& } | |
172 | \& undef($p); | |
173 | .Ve | |
174 | .PP | |
175 | .Vb 7 | |
176 | \& # High precision syntax (requires Time::HiRes) | |
177 | \& $p = Net::Ping->new(); | |
178 | \& $p->hires(); | |
179 | \& ($ret, $duration, $ip) = $p->ping($host, 5.5); | |
180 | \& printf("$host [ip: $ip] is alive (packet return time: %.2f ms)\en", 1000 * $duration) | |
181 | \& if $ret; | |
182 | \& $p->close(); | |
183 | .Ve | |
184 | .PP | |
185 | .Vb 2 | |
186 | \& # For backward compatibility | |
187 | \& print "$host is alive.\en" if pingecho($host); | |
188 | .Ve | |
189 | .SH "DESCRIPTION" | |
190 | .IX Header "DESCRIPTION" | |
191 | This module contains methods to test the reachability of remote | |
192 | hosts on a network. A ping object is first created with optional | |
193 | parameters, a variable number of hosts may be pinged multiple | |
194 | times and then the connection is closed. | |
195 | .PP | |
196 | You may choose one of four different protocols to use for the | |
197 | ping. The \*(L"udp\*(R" protocol is the default. Note that a live remote host | |
198 | may still fail to be pingable by one or more of these protocols. For | |
199 | example, www.microsoft.com is generally alive but not pingable. | |
200 | .PP | |
201 | With the \*(L"tcp\*(R" protocol the \fIping()\fR method attempts to establish a | |
202 | connection to the remote host's echo port. If the connection is | |
203 | successfully established, the remote host is considered reachable. No | |
204 | data is actually echoed. This protocol does not require any special | |
205 | privileges but has higher overhead than the other two protocols. | |
206 | .PP | |
207 | Specifying the \*(L"udp\*(R" protocol causes the \fIping()\fR method to send a udp | |
208 | packet to the remote host's echo port. If the echoed packet is | |
209 | received from the remote host and the received packet contains the | |
210 | same data as the packet that was sent, the remote host is considered | |
211 | reachable. This protocol does not require any special privileges. | |
212 | It should be borne in mind that, for a udp ping, a host | |
213 | will be reported as unreachable if it is not running the | |
214 | appropriate echo service. For Unix-like systems see \fIinetd\fR\|(8) | |
215 | for more information. | |
216 | .PP | |
217 | If the \*(L"icmp\*(R" protocol is specified, the \fIping()\fR method sends an icmp | |
218 | echo message to the remote host, which is what the \s-1UNIX\s0 ping program | |
219 | does. If the echoed message is received from the remote host and | |
220 | the echoed information is correct, the remote host is considered | |
221 | reachable. Specifying the \*(L"icmp\*(R" protocol requires that the program | |
222 | be run as root or that the program be setuid to root. | |
223 | .PP | |
224 | If the \*(L"external\*(R" protocol is specified, the \fIping()\fR method attempts to | |
225 | use the \f(CW\*(C`Net::Ping::External\*(C'\fR module to ping the remote host. | |
226 | \&\f(CW\*(C`Net::Ping::External\*(C'\fR interfaces with your system's default \f(CW\*(C`ping\*(C'\fR | |
227 | utility to perform the ping, and generally produces relatively | |
228 | accurate results. If \f(CW\*(C`Net::Ping::External\*(C'\fR if not installed on your | |
229 | system, specifying the \*(L"external\*(R" protocol will result in an error. | |
230 | .Sh "Functions" | |
231 | .IX Subsection "Functions" | |
232 | .ie n .IP "Net::Ping\->new([$proto [, $def_timeout\fR [, \f(CW$bytes]]]);" 4 | |
233 | .el .IP "Net::Ping\->new([$proto [, \f(CW$def_timeout\fR [, \f(CW$bytes\fR]]]);" 4 | |
234 | .IX Item "Net::Ping->new([$proto [, $def_timeout [, $bytes]]]);" | |
235 | Create a new ping object. All of the parameters are optional. \f(CW$proto\fR | |
236 | specifies the protocol to use when doing a ping. The current choices | |
237 | are \*(L"tcp\*(R", \*(L"udp\*(R" or \*(L"icmp\*(R". The default is \*(L"udp\*(R". | |
238 | .Sp | |
239 | If a default timeout ($def_timeout) in seconds is provided, it is used | |
240 | when a timeout is not given to the \fIping()\fR method (below). The timeout | |
241 | must be greater than 0 and the default, if not specified, is 5 seconds. | |
242 | .Sp | |
243 | If the number of data bytes ($bytes) is given, that many data bytes | |
244 | are included in the ping packet sent to the remote host. The number of | |
245 | data bytes is ignored if the protocol is \*(L"tcp\*(R". The minimum (and | |
246 | default) number of data bytes is 1 if the protocol is \*(L"udp\*(R" and 0 | |
247 | otherwise. The maximum number of data bytes that can be specified is | |
248 | 1024. | |
249 | .ie n .IP "$p\->ping($host [, $timeout]);" 4 | |
250 | .el .IP "$p\->ping($host [, \f(CW$timeout\fR]);" 4 | |
251 | .IX Item "$p->ping($host [, $timeout]);" | |
252 | Ping the remote host and wait for a response. \f(CW$host\fR can be either the | |
253 | hostname or the \s-1IP\s0 number of the remote host. The optional timeout | |
254 | must be greater than 0 seconds and defaults to whatever was specified | |
255 | when the ping object was created. Returns a success flag. If the | |
256 | hostname cannot be found or there is a problem with the \s-1IP\s0 number, the | |
257 | success flag returned will be undef. Otherwise, the success flag will | |
258 | be 1 if the host is reachable and 0 if it is not. For most practical | |
259 | purposes, undef and 0 and can be treated as the same case. In array | |
260 | context, the elapsed time is also returned. The elapsed time value will | |
261 | be a float, as retuned by the \fITime::HiRes::time()\fR function, if \fIhires()\fR | |
262 | has been previously called, otherwise it is returned as an integer. | |
263 | .IP "$p\->source_verify( { 0 | 1 } );" 4 | |
264 | .IX Item "$p->source_verify( { 0 | 1 } );" | |
265 | Allows source endpoint verification to be enabled or disabled. | |
266 | This is useful for those remote destinations with multiples | |
267 | interfaces where the response may not originate from the same | |
268 | endpoint that the original destination endpoint was sent to. | |
269 | This only affects udp and icmp protocol pings. | |
270 | .Sp | |
271 | This is enabled by default. | |
272 | .IP "$p\->hires( { 0 | 1 } );" 4 | |
273 | .IX Item "$p->hires( { 0 | 1 } );" | |
274 | Causes this module to use Time::HiRes module, allowing milliseconds | |
275 | to be returned by subsequent calls to \fIping()\fR. | |
276 | .Sp | |
277 | This is disabled by default. | |
278 | .IP "$p\->bind($local_addr);" 4 | |
279 | .IX Item "$p->bind($local_addr);" | |
280 | Sets the source address from which pings will be sent. This must be | |
281 | the address of one of the interfaces on the local host. \f(CW$local_addr\fR | |
282 | may be specified as a hostname or as a text \s-1IP\s0 address such as | |
283 | \&\*(L"192.168.1.1\*(R". | |
284 | .Sp | |
285 | If the protocol is set to \*(L"tcp\*(R", this method may be called any | |
286 | number of times, and each call to the \fIping()\fR method (below) will use | |
287 | the most recent \f(CW$local_addr\fR. If the protocol is \*(L"icmp\*(R" or \*(L"udp\*(R", | |
288 | then \fIbind()\fR must be called at most once per object, and (if it is | |
289 | called at all) must be called before the first call to \fIping()\fR for that | |
290 | object. | |
291 | .IP "$p\->open($host);" 4 | |
292 | .IX Item "$p->open($host);" | |
293 | When you are using the stream protocol, this call pre-opens the | |
294 | tcp socket. It's only necessary to do this if you want to | |
295 | provide a different timeout when creating the connection, or | |
296 | remove the overhead of establishing the connection from the | |
297 | first ping. If you don't call \f(CW\*(C`open()\*(C'\fR, the connection is | |
298 | automatically opened the first time \f(CW\*(C`ping()\*(C'\fR is called. | |
299 | This call simply does nothing if you are using any protocol other | |
300 | than stream. | |
301 | .IP "$p\->\fIclose()\fR;" 4 | |
302 | .IX Item "$p->close();" | |
303 | Close the network connection for this ping object. The network | |
304 | connection is also closed by \*(L"undef \f(CW$p\fR\*(R". The network connection is | |
305 | automatically closed if the ping object goes out of scope (e.g. \f(CW$p\fR is | |
306 | local to a subroutine and you leave the subroutine). | |
307 | .ie n .IP "pingecho($host [, $timeout]);" 4 | |
308 | .el .IP "pingecho($host [, \f(CW$timeout\fR]);" 4 | |
309 | .IX Item "pingecho($host [, $timeout]);" | |
310 | To provide backward compatibility with the previous version of | |
311 | Net::Ping, a \fIpingecho()\fR subroutine is available with the same | |
312 | functionality as before. \fIpingecho()\fR uses the tcp protocol. The | |
313 | return values and parameters are the same as described for the \fIping()\fR | |
314 | method. This subroutine is obsolete and may be removed in a future | |
315 | version of Net::Ping. | |
316 | .SH "WARNING" | |
317 | .IX Header "WARNING" | |
318 | \&\fIpingecho()\fR or a ping object with the tcp protocol use \fIalarm()\fR to | |
319 | implement the timeout. So, don't use \fIalarm()\fR in your program while | |
320 | you are using \fIpingecho()\fR or a ping object with the tcp protocol. The | |
321 | udp and icmp protocols do not use \fIalarm()\fR to implement the timeout. | |
322 | .SH "NOTES" | |
323 | .IX Header "NOTES" | |
324 | There will be less network overhead (and some efficiency in your | |
325 | program) if you specify either the udp or the icmp protocol. The tcp | |
326 | protocol will generate 2.5 times or more traffic for each ping than | |
327 | either udp or icmp. If many hosts are pinged frequently, you may wish | |
328 | to implement a small wait (e.g. 25ms or more) between each ping to | |
329 | avoid flooding your network with packets. | |
330 | .PP | |
331 | The icmp protocol requires that the program be run as root or that it | |
332 | be setuid to root. The other protocols do not require special | |
333 | privileges, but not all network devices implement tcp or udp echo. | |
334 | .PP | |
335 | Local hosts should normally respond to pings within milliseconds. | |
336 | However, on a very congested network it may take up to 3 seconds or | |
337 | longer to receive an echo packet from the remote host. If the timeout | |
338 | is set too low under these conditions, it will appear that the remote | |
339 | host is not reachable (which is almost the truth). | |
340 | .PP | |
341 | Reachability doesn't necessarily mean that the remote host is actually | |
342 | functioning beyond its ability to echo packets. tcp is slightly better | |
343 | at indicating the health of a system than icmp because it uses more | |
344 | of the networking stack to respond. | |
345 | .PP | |
346 | Because of a lack of anything better, this module uses its own | |
347 | routines to pack and unpack \s-1ICMP\s0 packets. It would be better for a | |
348 | separate module to be written which understands all of the different | |
349 | kinds of \s-1ICMP\s0 packets. | |
350 | .SH "INSTALL" | |
351 | .IX Header "INSTALL" | |
352 | The latest source tree is available via cvs: | |
353 | .PP | |
354 | .Vb 2 | |
355 | \& cvs -z3 -q -d :pserver:anonymous@cvs.roobik.com.:/usr/local/cvsroot/freeware co Net-Ping | |
356 | \& cd Net-Ping | |
357 | .Ve | |
358 | .PP | |
359 | The tarball can be created as follows: | |
360 | .PP | |
361 | .Vb 1 | |
362 | \& perl Makefile.PL ; make ; make dist | |
363 | .Ve | |
364 | .PP | |
365 | The latest Net::Ping release can be found at \s-1CPAN:\s0 | |
366 | .PP | |
367 | .Vb 1 | |
368 | \& $CPAN/modules/by-module/Net/ | |
369 | .Ve | |
370 | .PP | |
371 | 1) Extract the tarball | |
372 | .PP | |
373 | .Vb 2 | |
374 | \& gtar -zxvf Net-Ping-xxxx.tar.gz | |
375 | \& cd Net-Ping-xxxx | |
376 | .Ve | |
377 | .PP | |
378 | 2) Build: | |
379 | .PP | |
380 | .Vb 4 | |
381 | \& make realclean | |
382 | \& perl Makefile.PL | |
383 | \& make | |
384 | \& make test | |
385 | .Ve | |
386 | .PP | |
387 | 3) Install | |
388 | .PP | |
389 | .Vb 1 | |
390 | \& make install | |
391 | .Ve | |
392 | .PP | |
393 | Or install it \s-1RPM\s0 Style: | |
394 | .PP | |
395 | .Vb 1 | |
396 | \& rpm -ta SOURCES/Net-Ping-xxxx.tar.gz | |
397 | .Ve | |
398 | .PP | |
399 | .Vb 1 | |
400 | \& rpm -ih RPMS/noarch/perl-Net-Ping-xxxx.rpm | |
401 | .Ve | |
402 | .SH "AUTHORS" | |
403 | .IX Header "AUTHORS" | |
404 | .Vb 2 | |
405 | \& Current maintainer: | |
406 | \& bbb@cpan.org (Rob Brown) | |
407 | .Ve | |
408 | .PP | |
409 | .Vb 2 | |
410 | \& External protocol: | |
411 | \& colinm@cpan.org (Colin McMillen) | |
412 | .Ve | |
413 | .PP | |
414 | .Vb 2 | |
415 | \& Stream protocol: | |
416 | \& bronson@trestle.com (Scott Bronson) | |
417 | .Ve | |
418 | .PP | |
419 | .Vb 3 | |
420 | \& Original pingecho(): | |
421 | \& karrer@bernina.ethz.ch (Andreas Karrer) | |
422 | \& pmarquess@bfsec.bt.co.uk (Paul Marquess) | |
423 | .Ve | |
424 | .PP | |
425 | .Vb 2 | |
426 | \& Original Net::Ping author: | |
427 | \& mose@ns.ccsn.edu (Russell Mosemann) | |
428 | .Ve | |
429 | .SH "COPYRIGHT" | |
430 | .IX Header "COPYRIGHT" | |
431 | Copyright (c) 2002, Rob Brown. All rights reserved. | |
432 | .PP | |
433 | Copyright (c) 2001, Colin McMillen. All rights reserved. | |
434 | .PP | |
435 | This program is free software; you may redistribute it and/or | |
436 | modify it under the same terms as Perl itself. |