{
    "content": [
        {
            "type": "text",
            "text": "# Net::Ping (perldoc)\n\n**Summary:** Net::Ping - check a remote host for reachability\n\n**Synopsis:** use Net::Ping;\n$p = Net::Ping->new();\nprint \"$host is alive.\\n\" if $p->ping($host);\n$p->close();\n$p = Net::Ping->new(\"icmp\");\n$p->bind($myaddr); # Specify source interface of pings\nforeach $host (@hostarray)\n{\nprint \"$host is \";\nprint \"NOT \" unless $p->ping($host, 2);\nprint \"reachable.\\n\";\nsleep(1);\n}\n$p->close();\n$p = Net::Ping->new(\"icmpv6\");\n$ip = \"[fd00:dead:beef::4e]\";\nprint \"$ip is alive.\\n\" if $p->ping($ip);\n$p = Net::Ping->new(\"tcp\", 2);\n# Try connecting to the www port instead of the echo port\n$p->portnumber(scalar(getservbyname(\"http\", \"tcp\")));\nwhile ($stoptime > time())\n{\nprint \"$host not reachable \", scalar(localtime()), \"\\n\"\nunless $p->ping($host);\nsleep(300);\n}\nundef($p);\n# Like tcp protocol, but with many hosts\n$p = Net::Ping->new(\"syn\");\n$p->portnumber(getservbyname(\"http\", \"tcp\"));\nforeach $host (@hostarray) {\n$p->ping($host);\n}\nwhile (($host,$rtt,$ip) = $p->ack) {\nprint \"HOST: $host [$ip] ACKed in $rtt seconds.\\n\";\n}\n# High precision syntax (requires Time::HiRes)\n$p = Net::Ping->new();\n$p->hires();\n($ret, $duration, $ip) = $p->ping($host, 5.5);\nprintf(\"$host [ip: $ip] is alive (packet return time: %.2f ms)\\n\",\n1000 * $duration)\nif $ret;\n$p->close();\n# For backward compatibility\nprint \"$host is alive.\\n\" if pingecho($host);\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (54 lines)\n- **DESCRIPTION** (42 lines) — 3 subsections\n  - Functions (236 lines)\n  - pingecho (5 lines)\n  - wakeonlan (8 lines)\n- **NOTES** (22 lines)\n- **INSTALL** (11 lines)\n- **BUGS** (9 lines)\n- **AUTHORS** (24 lines)\n- **COPYRIGHT** (13 lines)\n\n## Full Content\n\n### NAME\n\nNet::Ping - check a remote host for reachability\n\n### SYNOPSIS\n\nuse Net::Ping;\n\n$p = Net::Ping->new();\nprint \"$host is alive.\\n\" if $p->ping($host);\n$p->close();\n\n$p = Net::Ping->new(\"icmp\");\n$p->bind($myaddr); # Specify source interface of pings\nforeach $host (@hostarray)\n{\nprint \"$host is \";\nprint \"NOT \" unless $p->ping($host, 2);\nprint \"reachable.\\n\";\nsleep(1);\n}\n$p->close();\n\n$p = Net::Ping->new(\"icmpv6\");\n$ip = \"[fd00:dead:beef::4e]\";\nprint \"$ip is alive.\\n\" if $p->ping($ip);\n\n$p = Net::Ping->new(\"tcp\", 2);\n# Try connecting to the www port instead of the echo port\n$p->portnumber(scalar(getservbyname(\"http\", \"tcp\")));\nwhile ($stoptime > time())\n{\nprint \"$host not reachable \", scalar(localtime()), \"\\n\"\nunless $p->ping($host);\nsleep(300);\n}\nundef($p);\n\n# Like tcp protocol, but with many hosts\n$p = Net::Ping->new(\"syn\");\n$p->portnumber(getservbyname(\"http\", \"tcp\"));\nforeach $host (@hostarray) {\n$p->ping($host);\n}\nwhile (($host,$rtt,$ip) = $p->ack) {\nprint \"HOST: $host [$ip] ACKed in $rtt seconds.\\n\";\n}\n\n# High precision syntax (requires Time::HiRes)\n$p = Net::Ping->new();\n$p->hires();\n($ret, $duration, $ip) = $p->ping($host, 5.5);\nprintf(\"$host [ip: $ip] is alive (packet return time: %.2f ms)\\n\",\n1000 * $duration)\nif $ret;\n$p->close();\n\n# For backward compatibility\nprint \"$host is alive.\\n\" if pingecho($host);\n\n### DESCRIPTION\n\nThis module contains methods to test the reachability of remote hosts on a network. A ping\nobject is first created with optional parameters, a variable number of hosts may be pinged\nmultiple times and then the connection is closed.\n\nYou may choose one of six different protocols to use for the ping. The \"tcp\" protocol is the\ndefault. Note that a live remote host may still fail to be pingable by one or more of these\nprotocols. For example, www.microsoft.com is generally alive but not \"icmp\" pingable.\n\nWith the \"tcp\" protocol the ping() method attempts to establish a connection to the remote\nhost's echo port. If the connection is successfully established, the remote host is considered\nreachable. No data is actually echoed. This protocol does not require any special privileges but\nhas higher overhead than the \"udp\" and \"icmp\" protocols.\n\nSpecifying the \"udp\" protocol causes the ping() method to send a udp packet to the remote host's\necho port. If the echoed packet is received from the remote host and the received packet\ncontains the same data as the packet that was sent, the remote host is considered reachable.\nThis protocol does not require any special privileges. It should be borne in mind that, for a\nudp ping, a host will be reported as unreachable if it is not running the appropriate echo\nservice. For Unix-like systems see inetd(8) for more information.\n\nIf the \"icmp\" protocol is specified, the ping() method sends an icmp echo message to the remote\nhost, which is what the UNIX ping program does. If the echoed message is received from the\nremote host and the echoed information is correct, the remote host is considered reachable.\nSpecifying the \"icmp\" protocol requires that the program be run as root or that the program be\nsetuid to root.\n\nIf the \"external\" protocol is specified, the ping() method attempts to use the\n\"Net::Ping::External\" module to ping the remote host. \"Net::Ping::External\" interfaces with your\nsystem's default \"ping\" utility to perform the ping, and generally produces relatively accurate\nresults. If \"Net::Ping::External\" if not installed on your system, specifying the \"external\"\nprotocol will result in an error.\n\nIf the \"syn\" protocol is specified, the \"ping\" method will only send a TCP SYN packet to the\nremote host then immediately return. If the syn packet was sent successfully, it will return a\ntrue value, otherwise it will return false. NOTE: Unlike the other protocols, the return value\ndoes NOT determine if the remote host is alive or not since the full TCP three-way handshake may\nnot have completed yet. The remote host is only considered reachable if it receives a TCP ACK\nwithin the timeout specified. To begin waiting for the ACK packets, use the \"ack\" method as\nexplained below. Use the \"syn\" protocol instead the \"tcp\" protocol to determine reachability of\nmultiple destinations simultaneously by sending parallel TCP SYN packets. It will not block\nwhile testing each remote host. This protocol does not require any special privileges.\n\n#### Functions\n\nNet::Ping->new([proto, timeout, bytes, device, tos, ttl, family, host, port, bind, gateway,\nretrans, pingstring, sourceverify econnrefused dontfrag IPV6USEMINMTU IPV6RECVPATHMTU])\nCreate a new ping object. All of the parameters are optional and can be passed as hash ref.\nAll options besides the first 7 must be passed as hash ref.\n\n\"proto\" specifies the protocol to use when doing a ping. The current choices are \"tcp\",\n\"udp\", \"icmp\", \"icmpv6\", \"stream\", \"syn\", or \"external\". The default is \"tcp\".\n\nIf a \"timeout\" in seconds is provided, it is used when a timeout is not given to the ping()\nmethod (below). The timeout must be greater than 0 and the default, if not specified, is 5\nseconds.\n\nIf the number of data bytes (\"bytes\") is given, that many data bytes are included in the\nping packet sent to the remote host. The number of data bytes is ignored if the protocol is\n\"tcp\". The minimum (and default) number of data bytes is 1 if the protocol is \"udp\" and 0\notherwise. The maximum number of data bytes that can be specified is 65535, but staying\nbelow the MTU (1472 bytes for ICMP) is recommended. Many small devices cannot deal with\nfragmented ICMP packets.\n\nIf \"device\" is given, this device is used to bind the source endpoint before sending the\nping packet. I believe this only works with superuser privileges and with udp and icmp\nprotocols at this time.\n\nIf <tos> is given, this ToS is configured into the socket.\n\nFor icmp, \"ttl\" can be specified to set the TTL of the outgoing packet.\n\nValid \"family\" values for IPv4:\n\n4, v4, ip4, ipv4, AFINET (constant)\n\nValid \"family\" values for IPv6:\n\n6, v6, ip6, ipv6, AFINET6 (constant)\n\nThe \"host\" argument implicitly specifies the family if the family argument is not given.\n\nThe \"port\" argument is only valid for a udp, tcp or stream ping, and will not do what you\nthink it does. ping returns true when we get a \"Connection refused\"! The default is the echo\nport.\n\nThe \"bind\" argument specifies the localaddr to bind to. By specifying a bind argument you\ndon't need the bind method.\n\nThe \"gateway\" argument is only valid for IPv6, and requires a IPv6 address.\n\nThe \"retrans\" argument the exponential backoff rate, default 1.2. It matches the $deffactor\nglobal.\n\nThe \"dontfrag\" argument sets the IPDONTFRAG bit, but note that IPDONTFRAG is not yet\ndefined by Socket, and not available on many systems. Then it is ignored. On linux it also\nsets IPMTUDISCOVER to IPPMTUDISCDO but need we don't chunk oversized packets. You need\nto set $datasize manually.\n\n$p->ping($host [, $timeout [, $family]]);\nPing the remote host and wait for a response. $host can be either the hostname or the IP\nnumber of the remote host. The optional timeout must be greater than 0 seconds and defaults\nto whatever was specified when the ping object was created. Returns a success flag. If the\nhostname cannot be found or there is a problem with the IP number, the success flag returned\nwill be undef. Otherwise, the success flag will be 1 if the host is reachable and 0 if it is\nnot. For most practical purposes, undef and 0 and can be treated as the same case. In array\ncontext, the elapsed time as well as the string form of the ip the host resolved to are also\nreturned. The elapsed time value will be a float, as returned by the Time::HiRes::time()\nfunction, if hires() has been previously called, otherwise it is returned as an integer.\n\n$p->sourceverify( { 0 | 1 } );\nAllows source endpoint verification to be enabled or disabled. This is useful for those\nremote destinations with multiples interfaces where the response may not originate from the\nsame endpoint that the original destination endpoint was sent to. This only affects udp and\nicmp protocol pings.\n\nThis is enabled by default.\n\n$p->servicecheck( { 0 | 1 } );\nSet whether or not the connect behavior should enforce remote service availability as well\nas reachability. Normally, if the remote server reported ECONNREFUSED, it must have been\nreachable because of the status packet that it reported. With this option enabled, the full\nthree-way tcp handshake must have been established successfully before it will claim it is\nreachable. NOTE: It still does nothing more than connect and disconnect. It does not speak\nany protocol (i.e., HTTP or FTP) to ensure the remote server is sane in any way. The remote\nserver CPU could be grinding to a halt and unresponsive to any clients connecting, but if\nthe kernel throws the ACK packet, it is considered alive anyway. To really determine if the\nserver is responding well would be application specific and is beyond the scope of\nNet::Ping. For udp protocol, enabling this option demands that the remote server replies\nwith the same udp data that it was sent as defined by the udp echo service.\n\nThis affects the \"udp\", \"tcp\", and \"syn\" protocols.\n\nThis is disabled by default.\n\n$p->tcpservicecheck( { 0 | 1 } );\nDeprecated method, but does the same as servicecheck() method.\n\n$p->hires( { 0 | 1 } );\nWith 1 causes this module to use Time::HiRes module, allowing milliseconds to be returned by\nsubsequent calls to ping().\n\n$p->time\nThe current time, hires or not.\n\n$p->socketblockingmode( $fh, $mode );\nSets or clears the ONONBLOCK flag on a file handle.\n\n$p->IPV6USEMINMTU\nWith argument sets the option. Without returns the option value.\n\n$p->IPV6RECVPATHMTU\nNotify an according IPv6 MTU.\n\nWith argument sets the option. Without returns the option value.\n\n$p->IPV6HOPLIMIT\nWith argument sets the option. Without returns the option value.\n\n$p->IPV6REACHCONF *NYI*\nSets ipv6 reachability IPV6REACHCONF was removed in RFC3542. ping6 -R supports it.\nIPV6REACHCONF requires root/admin permissions.\n\nWith argument sets the option. Without returns the option value.\n\nNot yet implemented.\n\n$p->bind($localaddr);\nSets the source address from which pings will be sent. This must be the address of one of\nthe interfaces on the local host. $localaddr may be specified as a hostname or as a text IP\naddress such as \"192.168.1.1\".\n\nIf the protocol is set to \"tcp\", this method may be called any number of times, and each\ncall to the ping() method (below) will use the most recent $localaddr. If the protocol is\n\"icmp\" or \"udp\", then bind() must be called at most once per object, and (if it is called at\nall) must be called before the first call to ping() for that object.\n\nThe bind() call can be omitted when specifying the \"bind\" option to new().\n\n$p->messagetype([$pingtype]);\nWhen you are using the \"icmp\" protocol, this call permit to change the message type to\n'echo' or 'timestamp' (only for IPv4, see RFC 792).\n\nWithout argument, it returns the currently used icmp protocol message type. By default, it\nreturns 'echo'.\n\n$p->open($host);\nWhen you are using the \"stream\" protocol, this call pre-opens the tcp socket. It's only\nnecessary to do this if you want to provide a different timeout when creating the\nconnection, or remove the overhead of establishing the connection from the first ping. If\nyou don't call \"open()\", the connection is automatically opened the first time \"ping()\" is\ncalled. This call simply does nothing if you are using any protocol other than stream.\n\nThe $host argument can be omitted when specifying the \"host\" option to new().\n\n$p->ack( [ $host ] );\nWhen using the \"syn\" protocol, use this method to determine the reachability of the remote\nhost. This method is meant to be called up to as many times as ping() was called. Each call\nreturns the host (as passed to ping()) that came back with the TCP ACK. The order in which\nthe hosts are returned may not necessarily be the same order in which they were SYN queued\nusing the ping() method. If the timeout is reached before the TCP ACK is received, or if the\nremote host is not listening on the port attempted, then the TCP connection will not be\nestablished and ack() will return undef. In list context, the host, the ack time, the dotted\nip string, and the port number will be returned instead of just the host. If the optional\n$host argument is specified, the return value will be pertaining to that host only. This\ncall simply does nothing if you are using any protocol other than \"syn\".\n\nWhen \"new\" had a host option, this host will be used. Without $host argument, all hosts are\nscanned.\n\n$p->nack( $failedackhost );\nThe reason that \"host $failedackhost\" did not receive a valid ACK. Useful to find out why\nwhen \"ack($failackhost)\" returns a false value.\n\n$p->ackunfork($host)\nThe variant called by \"ack\" with the \"syn\" protocol and $synforking enabled.\n\n$p->pingicmp([$host, $timeout, $family])\nThe \"ping\" method used with the icmp protocol.\n\n$p->pingicmpv6([$host, $timeout, $family])\nThe \"ping\" method used with the icmpv6 protocol.\n\n$p->pingstream([$host, $timeout, $family])\nThe \"ping\" method used with the stream protocol.\n\nPerform a stream ping. If the tcp connection isn't already open, it opens it. It then sends\nsome data and waits for a reply. It leaves the stream open on exit.\n\n$p->pingsyn([$host, $ip, $starttime, $stoptime])\nThe \"ping\" method used with the syn protocol. Sends a TCP SYN packet to host specified.\n\n$p->pingsynfork([$host, $timeout, $family])\nThe \"ping\" method used with the forking syn protocol.\n\n$p->pingtcp([$host, $timeout, $family])\nThe \"ping\" method used with the tcp protocol.\n\n$p->pingudp([$host, $timeout, $family])\nThe \"ping\" method used with the udp protocol.\n\nPerform a udp echo ping. Construct a message of at least the one-byte sequence number and\nany additional data bytes. Send the message out and wait for a message to come back. If we\nget a message, make sure all of its parts match. If they do, we are done. Otherwise go back\nand wait for the message until we run out of time. Return the result of our efforts.\n\n$p->pingexternal([$host, $timeout, $family])\nThe \"ping\" method used with the external protocol. Uses Net::Ping::External to do an\nexternal ping.\n\n$p->tcpconnect([$ip, $timeout])\nInitiates a TCP connection, for a tcp ping.\n\n$p->tcpecho([$ip, $timeout, $pingstring])\nPerforms a TCP echo. It writes the given string to the socket and then reads it back. It\nreturns 1 on success, 0 on failure.\n\n$p->close();\nClose the network connection for this ping object. The network connection is also closed by\n\"undef $p\". The network connection is automatically closed if the ping object goes out of\nscope (e.g. $p is local to a subroutine and you leave the subroutine).\n\n$p->portnumber([$portnumber])\nWhen called with a port number, the port number used to ping is set to $portnumber rather\nthan using the echo port. It also has the effect of calling \"$p->servicecheck(1)\" causing a\nping to return a successful response only if that specific port is accessible. This function\nreturns the value of the port that \"ping\" will connect to.\n\n$p->mselect\nA \"select()\" wrapper that compensates for platform peculiarities.\n\n$p->ntop\nPlatform abstraction over \"inetntop()\"\n\n$p->checksum($msg)\nDo a checksum on the message. Basically sum all of the short words and fold the high order\nbits into the low order bits.\n\n$p->icmpresult\nReturns a list of addr, type, subcode.\n\n#### pingecho\n\nTo provide backward compatibility with the previous version of Net::Ping, a \"pingecho()\"\nsubroutine is available with the same functionality as before. \"pingecho()\" uses the tcp\nprotocol. The return values and parameters are the same as described for the \"ping\" method.\nThis subroutine is obsolete and may be removed in a future version of Net::Ping.\n\n#### wakeonlan\n\nEmit the popular wake-on-lan magic udp packet to wake up a local device. See also Net::Wake,\nbut this has the mac address as 1st arg. $host should be the local gateway. Without it will\nbroadcast.\n\nDefault host: '255.255.255.255' Default port: 9\n\nperl -MNet::Ping=wakeonlan -e'wakeonlan \"e0:69:95:35:68:d2\"'\n\n### NOTES\n\nThere will be less network overhead (and some efficiency in your program) if you specify either\nthe udp or the icmp protocol. The tcp protocol will generate 2.5 times or more traffic for each\nping than either udp or icmp. If many hosts are pinged frequently, you may wish to implement a\nsmall wait (e.g. 25ms or more) between each ping to avoid flooding your network with packets.\n\nThe icmp and icmpv6 protocols requires that the program be run as root or that it be setuid to\nroot. The other protocols do not require special privileges, but not all network devices\nimplement tcp or udp echo.\n\nLocal hosts should normally respond to pings within milliseconds. However, on a very congested\nnetwork it may take up to 3 seconds or longer to receive an echo packet from the remote host. If\nthe timeout is set too low under these conditions, it will appear that the remote host is not\nreachable (which is almost the truth).\n\nReachability doesn't necessarily mean that the remote host is actually functioning beyond its\nability to echo packets. tcp is slightly better at indicating the health of a system than icmp\nbecause it uses more of the networking stack to respond.\n\nBecause of a lack of anything better, this module uses its own routines to pack and unpack ICMP\npackets. It would be better for a separate module to be written which understands all of the\ndifferent kinds of ICMP packets.\n\n### INSTALL\n\nThe latest source tree is available via git:\n\ngit clone https://github.com/rurban/Net-Ping.git\ncd Net-Ping\n\nThe tarball can be created as follows:\n\nperl Makefile.PL ; make ; make dist\n\nThe latest Net::Ping releases are included in cperl and perl5.\n\n### BUGS\n\nFor a list of known issues, visit:\n\n<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Ping> and\n<https://github.com/rurban/Net-Ping/issues>\n\nTo report a new bug, visit:\n\n<https://github.com/rurban/Net-Ping/issues>\n\n### AUTHORS\n\nCurrent maintainers:\nperl11 (for cperl, with IPv6 support and more)\np5p    (for perl5)\n\nPrevious maintainers:\nbbb@cpan.org (Rob Brown)\nSteve Peters\n\nExternal protocol:\ncolinm@cpan.org (Colin McMillen)\n\nStream protocol:\nbronson@trestle.com (Scott Bronson)\n\nWake-on-lan:\n1999-2003 Clinton Wong\n\nOriginal pingecho():\nkarrer@bernina.ethz.ch (Andreas Karrer)\npmarquess@bfsec.bt.co.uk (Paul Marquess)\n\nOriginal Net::Ping author:\nmose@ns.ccsn.edu (Russell Mosemann)\n\n### COPYRIGHT\n\nCopyright (c) 2017-2020, Reini Urban. All rights reserved.\n\nCopyright (c) 2016, cPanel Inc. All rights reserved.\n\nCopyright (c) 2012, Steve Peters. All rights reserved.\n\nCopyright (c) 2002-2003, Rob Brown. All rights reserved.\n\nCopyright (c) 2001, Colin McMillen. All rights reserved.\n\nThis program is free software; you may redistribute it and/or modify it under the same terms as\nPerl itself.\n\n"
        }
    ],
    "structuredContent": {
        "command": "Net::Ping",
        "section": "",
        "mode": "perldoc",
        "summary": "Net::Ping - check a remote host for reachability",
        "synopsis": "use Net::Ping;\n$p = Net::Ping->new();\nprint \"$host is alive.\\n\" if $p->ping($host);\n$p->close();\n$p = Net::Ping->new(\"icmp\");\n$p->bind($myaddr); # Specify source interface of pings\nforeach $host (@hostarray)\n{\nprint \"$host is \";\nprint \"NOT \" unless $p->ping($host, 2);\nprint \"reachable.\\n\";\nsleep(1);\n}\n$p->close();\n$p = Net::Ping->new(\"icmpv6\");\n$ip = \"[fd00:dead:beef::4e]\";\nprint \"$ip is alive.\\n\" if $p->ping($ip);\n$p = Net::Ping->new(\"tcp\", 2);\n# Try connecting to the www port instead of the echo port\n$p->portnumber(scalar(getservbyname(\"http\", \"tcp\")));\nwhile ($stoptime > time())\n{\nprint \"$host not reachable \", scalar(localtime()), \"\\n\"\nunless $p->ping($host);\nsleep(300);\n}\nundef($p);\n# Like tcp protocol, but with many hosts\n$p = Net::Ping->new(\"syn\");\n$p->portnumber(getservbyname(\"http\", \"tcp\"));\nforeach $host (@hostarray) {\n$p->ping($host);\n}\nwhile (($host,$rtt,$ip) = $p->ack) {\nprint \"HOST: $host [$ip] ACKed in $rtt seconds.\\n\";\n}\n# High precision syntax (requires Time::HiRes)\n$p = Net::Ping->new();\n$p->hires();\n($ret, $duration, $ip) = $p->ping($host, 5.5);\nprintf(\"$host [ip: $ip] is alive (packet return time: %.2f ms)\\n\",\n1000 * $duration)\nif $ret;\n$p->close();\n# For backward compatibility\nprint \"$host is alive.\\n\" if pingecho($host);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 54,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 42,
                "subsections": [
                    {
                        "name": "Functions",
                        "lines": 236
                    },
                    {
                        "name": "pingecho",
                        "lines": 5
                    },
                    {
                        "name": "wakeonlan",
                        "lines": 8
                    }
                ]
            },
            {
                "name": "NOTES",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "INSTALL",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 13,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Net::Ping - check a remote host for reachability\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Net::Ping;\n\n$p = Net::Ping->new();\nprint \"$host is alive.\\n\" if $p->ping($host);\n$p->close();\n\n$p = Net::Ping->new(\"icmp\");\n$p->bind($myaddr); # Specify source interface of pings\nforeach $host (@hostarray)\n{\nprint \"$host is \";\nprint \"NOT \" unless $p->ping($host, 2);\nprint \"reachable.\\n\";\nsleep(1);\n}\n$p->close();\n\n$p = Net::Ping->new(\"icmpv6\");\n$ip = \"[fd00:dead:beef::4e]\";\nprint \"$ip is alive.\\n\" if $p->ping($ip);\n\n$p = Net::Ping->new(\"tcp\", 2);\n# Try connecting to the www port instead of the echo port\n$p->portnumber(scalar(getservbyname(\"http\", \"tcp\")));\nwhile ($stoptime > time())\n{\nprint \"$host not reachable \", scalar(localtime()), \"\\n\"\nunless $p->ping($host);\nsleep(300);\n}\nundef($p);\n\n# Like tcp protocol, but with many hosts\n$p = Net::Ping->new(\"syn\");\n$p->portnumber(getservbyname(\"http\", \"tcp\"));\nforeach $host (@hostarray) {\n$p->ping($host);\n}\nwhile (($host,$rtt,$ip) = $p->ack) {\nprint \"HOST: $host [$ip] ACKed in $rtt seconds.\\n\";\n}\n\n# High precision syntax (requires Time::HiRes)\n$p = Net::Ping->new();\n$p->hires();\n($ret, $duration, $ip) = $p->ping($host, 5.5);\nprintf(\"$host [ip: $ip] is alive (packet return time: %.2f ms)\\n\",\n1000 * $duration)\nif $ret;\n$p->close();\n\n# For backward compatibility\nprint \"$host is alive.\\n\" if pingecho($host);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module contains methods to test the reachability of remote hosts on a network. A ping\nobject is first created with optional parameters, a variable number of hosts may be pinged\nmultiple times and then the connection is closed.\n\nYou may choose one of six different protocols to use for the ping. The \"tcp\" protocol is the\ndefault. Note that a live remote host may still fail to be pingable by one or more of these\nprotocols. For example, www.microsoft.com is generally alive but not \"icmp\" pingable.\n\nWith the \"tcp\" protocol the ping() method attempts to establish a connection to the remote\nhost's echo port. If the connection is successfully established, the remote host is considered\nreachable. No data is actually echoed. This protocol does not require any special privileges but\nhas higher overhead than the \"udp\" and \"icmp\" protocols.\n\nSpecifying the \"udp\" protocol causes the ping() method to send a udp packet to the remote host's\necho port. If the echoed packet is received from the remote host and the received packet\ncontains the same data as the packet that was sent, the remote host is considered reachable.\nThis protocol does not require any special privileges. It should be borne in mind that, for a\nudp ping, a host will be reported as unreachable if it is not running the appropriate echo\nservice. For Unix-like systems see inetd(8) for more information.\n\nIf the \"icmp\" protocol is specified, the ping() method sends an icmp echo message to the remote\nhost, which is what the UNIX ping program does. If the echoed message is received from the\nremote host and the echoed information is correct, the remote host is considered reachable.\nSpecifying the \"icmp\" protocol requires that the program be run as root or that the program be\nsetuid to root.\n\nIf the \"external\" protocol is specified, the ping() method attempts to use the\n\"Net::Ping::External\" module to ping the remote host. \"Net::Ping::External\" interfaces with your\nsystem's default \"ping\" utility to perform the ping, and generally produces relatively accurate\nresults. If \"Net::Ping::External\" if not installed on your system, specifying the \"external\"\nprotocol will result in an error.\n\nIf the \"syn\" protocol is specified, the \"ping\" method will only send a TCP SYN packet to the\nremote host then immediately return. If the syn packet was sent successfully, it will return a\ntrue value, otherwise it will return false. NOTE: Unlike the other protocols, the return value\ndoes NOT determine if the remote host is alive or not since the full TCP three-way handshake may\nnot have completed yet. The remote host is only considered reachable if it receives a TCP ACK\nwithin the timeout specified. To begin waiting for the ACK packets, use the \"ack\" method as\nexplained below. Use the \"syn\" protocol instead the \"tcp\" protocol to determine reachability of\nmultiple destinations simultaneously by sending parallel TCP SYN packets. It will not block\nwhile testing each remote host. This protocol does not require any special privileges.\n",
                "subsections": [
                    {
                        "name": "Functions",
                        "content": "Net::Ping->new([proto, timeout, bytes, device, tos, ttl, family, host, port, bind, gateway,\nretrans, pingstring, sourceverify econnrefused dontfrag IPV6USEMINMTU IPV6RECVPATHMTU])\nCreate a new ping object. All of the parameters are optional and can be passed as hash ref.\nAll options besides the first 7 must be passed as hash ref.\n\n\"proto\" specifies the protocol to use when doing a ping. The current choices are \"tcp\",\n\"udp\", \"icmp\", \"icmpv6\", \"stream\", \"syn\", or \"external\". The default is \"tcp\".\n\nIf a \"timeout\" in seconds is provided, it is used when a timeout is not given to the ping()\nmethod (below). The timeout must be greater than 0 and the default, if not specified, is 5\nseconds.\n\nIf the number of data bytes (\"bytes\") is given, that many data bytes are included in the\nping packet sent to the remote host. The number of data bytes is ignored if the protocol is\n\"tcp\". The minimum (and default) number of data bytes is 1 if the protocol is \"udp\" and 0\notherwise. The maximum number of data bytes that can be specified is 65535, but staying\nbelow the MTU (1472 bytes for ICMP) is recommended. Many small devices cannot deal with\nfragmented ICMP packets.\n\nIf \"device\" is given, this device is used to bind the source endpoint before sending the\nping packet. I believe this only works with superuser privileges and with udp and icmp\nprotocols at this time.\n\nIf <tos> is given, this ToS is configured into the socket.\n\nFor icmp, \"ttl\" can be specified to set the TTL of the outgoing packet.\n\nValid \"family\" values for IPv4:\n\n4, v4, ip4, ipv4, AFINET (constant)\n\nValid \"family\" values for IPv6:\n\n6, v6, ip6, ipv6, AFINET6 (constant)\n\nThe \"host\" argument implicitly specifies the family if the family argument is not given.\n\nThe \"port\" argument is only valid for a udp, tcp or stream ping, and will not do what you\nthink it does. ping returns true when we get a \"Connection refused\"! The default is the echo\nport.\n\nThe \"bind\" argument specifies the localaddr to bind to. By specifying a bind argument you\ndon't need the bind method.\n\nThe \"gateway\" argument is only valid for IPv6, and requires a IPv6 address.\n\nThe \"retrans\" argument the exponential backoff rate, default 1.2. It matches the $deffactor\nglobal.\n\nThe \"dontfrag\" argument sets the IPDONTFRAG bit, but note that IPDONTFRAG is not yet\ndefined by Socket, and not available on many systems. Then it is ignored. On linux it also\nsets IPMTUDISCOVER to IPPMTUDISCDO but need we don't chunk oversized packets. You need\nto set $datasize manually.\n\n$p->ping($host [, $timeout [, $family]]);\nPing the remote host and wait for a response. $host can be either the hostname or the IP\nnumber of the remote host. The optional timeout must be greater than 0 seconds and defaults\nto whatever was specified when the ping object was created. Returns a success flag. If the\nhostname cannot be found or there is a problem with the IP number, the success flag returned\nwill be undef. Otherwise, the success flag will be 1 if the host is reachable and 0 if it is\nnot. For most practical purposes, undef and 0 and can be treated as the same case. In array\ncontext, the elapsed time as well as the string form of the ip the host resolved to are also\nreturned. The elapsed time value will be a float, as returned by the Time::HiRes::time()\nfunction, if hires() has been previously called, otherwise it is returned as an integer.\n\n$p->sourceverify( { 0 | 1 } );\nAllows source endpoint verification to be enabled or disabled. This is useful for those\nremote destinations with multiples interfaces where the response may not originate from the\nsame endpoint that the original destination endpoint was sent to. This only affects udp and\nicmp protocol pings.\n\nThis is enabled by default.\n\n$p->servicecheck( { 0 | 1 } );\nSet whether or not the connect behavior should enforce remote service availability as well\nas reachability. Normally, if the remote server reported ECONNREFUSED, it must have been\nreachable because of the status packet that it reported. With this option enabled, the full\nthree-way tcp handshake must have been established successfully before it will claim it is\nreachable. NOTE: It still does nothing more than connect and disconnect. It does not speak\nany protocol (i.e., HTTP or FTP) to ensure the remote server is sane in any way. The remote\nserver CPU could be grinding to a halt and unresponsive to any clients connecting, but if\nthe kernel throws the ACK packet, it is considered alive anyway. To really determine if the\nserver is responding well would be application specific and is beyond the scope of\nNet::Ping. For udp protocol, enabling this option demands that the remote server replies\nwith the same udp data that it was sent as defined by the udp echo service.\n\nThis affects the \"udp\", \"tcp\", and \"syn\" protocols.\n\nThis is disabled by default.\n\n$p->tcpservicecheck( { 0 | 1 } );\nDeprecated method, but does the same as servicecheck() method.\n\n$p->hires( { 0 | 1 } );\nWith 1 causes this module to use Time::HiRes module, allowing milliseconds to be returned by\nsubsequent calls to ping().\n\n$p->time\nThe current time, hires or not.\n\n$p->socketblockingmode( $fh, $mode );\nSets or clears the ONONBLOCK flag on a file handle.\n\n$p->IPV6USEMINMTU\nWith argument sets the option. Without returns the option value.\n\n$p->IPV6RECVPATHMTU\nNotify an according IPv6 MTU.\n\nWith argument sets the option. Without returns the option value.\n\n$p->IPV6HOPLIMIT\nWith argument sets the option. Without returns the option value.\n\n$p->IPV6REACHCONF *NYI*\nSets ipv6 reachability IPV6REACHCONF was removed in RFC3542. ping6 -R supports it.\nIPV6REACHCONF requires root/admin permissions.\n\nWith argument sets the option. Without returns the option value.\n\nNot yet implemented.\n\n$p->bind($localaddr);\nSets the source address from which pings will be sent. This must be the address of one of\nthe interfaces on the local host. $localaddr may be specified as a hostname or as a text IP\naddress such as \"192.168.1.1\".\n\nIf the protocol is set to \"tcp\", this method may be called any number of times, and each\ncall to the ping() method (below) will use the most recent $localaddr. If the protocol is\n\"icmp\" or \"udp\", then bind() must be called at most once per object, and (if it is called at\nall) must be called before the first call to ping() for that object.\n\nThe bind() call can be omitted when specifying the \"bind\" option to new().\n\n$p->messagetype([$pingtype]);\nWhen you are using the \"icmp\" protocol, this call permit to change the message type to\n'echo' or 'timestamp' (only for IPv4, see RFC 792).\n\nWithout argument, it returns the currently used icmp protocol message type. By default, it\nreturns 'echo'.\n\n$p->open($host);\nWhen you are using the \"stream\" protocol, this call pre-opens the tcp socket. It's only\nnecessary to do this if you want to provide a different timeout when creating the\nconnection, or remove the overhead of establishing the connection from the first ping. If\nyou don't call \"open()\", the connection is automatically opened the first time \"ping()\" is\ncalled. This call simply does nothing if you are using any protocol other than stream.\n\nThe $host argument can be omitted when specifying the \"host\" option to new().\n\n$p->ack( [ $host ] );\nWhen using the \"syn\" protocol, use this method to determine the reachability of the remote\nhost. This method is meant to be called up to as many times as ping() was called. Each call\nreturns the host (as passed to ping()) that came back with the TCP ACK. The order in which\nthe hosts are returned may not necessarily be the same order in which they were SYN queued\nusing the ping() method. If the timeout is reached before the TCP ACK is received, or if the\nremote host is not listening on the port attempted, then the TCP connection will not be\nestablished and ack() will return undef. In list context, the host, the ack time, the dotted\nip string, and the port number will be returned instead of just the host. If the optional\n$host argument is specified, the return value will be pertaining to that host only. This\ncall simply does nothing if you are using any protocol other than \"syn\".\n\nWhen \"new\" had a host option, this host will be used. Without $host argument, all hosts are\nscanned.\n\n$p->nack( $failedackhost );\nThe reason that \"host $failedackhost\" did not receive a valid ACK. Useful to find out why\nwhen \"ack($failackhost)\" returns a false value.\n\n$p->ackunfork($host)\nThe variant called by \"ack\" with the \"syn\" protocol and $synforking enabled.\n\n$p->pingicmp([$host, $timeout, $family])\nThe \"ping\" method used with the icmp protocol.\n\n$p->pingicmpv6([$host, $timeout, $family])\nThe \"ping\" method used with the icmpv6 protocol.\n\n$p->pingstream([$host, $timeout, $family])\nThe \"ping\" method used with the stream protocol.\n\nPerform a stream ping. If the tcp connection isn't already open, it opens it. It then sends\nsome data and waits for a reply. It leaves the stream open on exit.\n\n$p->pingsyn([$host, $ip, $starttime, $stoptime])\nThe \"ping\" method used with the syn protocol. Sends a TCP SYN packet to host specified.\n\n$p->pingsynfork([$host, $timeout, $family])\nThe \"ping\" method used with the forking syn protocol.\n\n$p->pingtcp([$host, $timeout, $family])\nThe \"ping\" method used with the tcp protocol.\n\n$p->pingudp([$host, $timeout, $family])\nThe \"ping\" method used with the udp protocol.\n\nPerform a udp echo ping. Construct a message of at least the one-byte sequence number and\nany additional data bytes. Send the message out and wait for a message to come back. If we\nget a message, make sure all of its parts match. If they do, we are done. Otherwise go back\nand wait for the message until we run out of time. Return the result of our efforts.\n\n$p->pingexternal([$host, $timeout, $family])\nThe \"ping\" method used with the external protocol. Uses Net::Ping::External to do an\nexternal ping.\n\n$p->tcpconnect([$ip, $timeout])\nInitiates a TCP connection, for a tcp ping.\n\n$p->tcpecho([$ip, $timeout, $pingstring])\nPerforms a TCP echo. It writes the given string to the socket and then reads it back. It\nreturns 1 on success, 0 on failure.\n\n$p->close();\nClose the network connection for this ping object. The network connection is also closed by\n\"undef $p\". The network connection is automatically closed if the ping object goes out of\nscope (e.g. $p is local to a subroutine and you leave the subroutine).\n\n$p->portnumber([$portnumber])\nWhen called with a port number, the port number used to ping is set to $portnumber rather\nthan using the echo port. It also has the effect of calling \"$p->servicecheck(1)\" causing a\nping to return a successful response only if that specific port is accessible. This function\nreturns the value of the port that \"ping\" will connect to.\n\n$p->mselect\nA \"select()\" wrapper that compensates for platform peculiarities.\n\n$p->ntop\nPlatform abstraction over \"inetntop()\"\n\n$p->checksum($msg)\nDo a checksum on the message. Basically sum all of the short words and fold the high order\nbits into the low order bits.\n\n$p->icmpresult\nReturns a list of addr, type, subcode.\n"
                    },
                    {
                        "name": "pingecho",
                        "content": "To provide backward compatibility with the previous version of Net::Ping, a \"pingecho()\"\nsubroutine is available with the same functionality as before. \"pingecho()\" uses the tcp\nprotocol. The return values and parameters are the same as described for the \"ping\" method.\nThis subroutine is obsolete and may be removed in a future version of Net::Ping.\n"
                    },
                    {
                        "name": "wakeonlan",
                        "content": "Emit the popular wake-on-lan magic udp packet to wake up a local device. See also Net::Wake,\nbut this has the mac address as 1st arg. $host should be the local gateway. Without it will\nbroadcast.\n\nDefault host: '255.255.255.255' Default port: 9\n\nperl -MNet::Ping=wakeonlan -e'wakeonlan \"e0:69:95:35:68:d2\"'\n"
                    }
                ]
            },
            "NOTES": {
                "content": "There will be less network overhead (and some efficiency in your program) if you specify either\nthe udp or the icmp protocol. The tcp protocol will generate 2.5 times or more traffic for each\nping than either udp or icmp. If many hosts are pinged frequently, you may wish to implement a\nsmall wait (e.g. 25ms or more) between each ping to avoid flooding your network with packets.\n\nThe icmp and icmpv6 protocols requires that the program be run as root or that it be setuid to\nroot. The other protocols do not require special privileges, but not all network devices\nimplement tcp or udp echo.\n\nLocal hosts should normally respond to pings within milliseconds. However, on a very congested\nnetwork it may take up to 3 seconds or longer to receive an echo packet from the remote host. If\nthe timeout is set too low under these conditions, it will appear that the remote host is not\nreachable (which is almost the truth).\n\nReachability doesn't necessarily mean that the remote host is actually functioning beyond its\nability to echo packets. tcp is slightly better at indicating the health of a system than icmp\nbecause it uses more of the networking stack to respond.\n\nBecause of a lack of anything better, this module uses its own routines to pack and unpack ICMP\npackets. It would be better for a separate module to be written which understands all of the\ndifferent kinds of ICMP packets.\n",
                "subsections": []
            },
            "INSTALL": {
                "content": "The latest source tree is available via git:\n\ngit clone https://github.com/rurban/Net-Ping.git\ncd Net-Ping\n\nThe tarball can be created as follows:\n\nperl Makefile.PL ; make ; make dist\n\nThe latest Net::Ping releases are included in cperl and perl5.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "For a list of known issues, visit:\n\n<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Ping> and\n<https://github.com/rurban/Net-Ping/issues>\n\nTo report a new bug, visit:\n\n<https://github.com/rurban/Net-Ping/issues>\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Current maintainers:\nperl11 (for cperl, with IPv6 support and more)\np5p    (for perl5)\n\nPrevious maintainers:\nbbb@cpan.org (Rob Brown)\nSteve Peters\n\nExternal protocol:\ncolinm@cpan.org (Colin McMillen)\n\nStream protocol:\nbronson@trestle.com (Scott Bronson)\n\nWake-on-lan:\n1999-2003 Clinton Wong\n\nOriginal pingecho():\nkarrer@bernina.ethz.ch (Andreas Karrer)\npmarquess@bfsec.bt.co.uk (Paul Marquess)\n\nOriginal Net::Ping author:\nmose@ns.ccsn.edu (Russell Mosemann)\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (c) 2017-2020, Reini Urban. All rights reserved.\n\nCopyright (c) 2016, cPanel Inc. All rights reserved.\n\nCopyright (c) 2012, Steve Peters. All rights reserved.\n\nCopyright (c) 2002-2003, Rob Brown. All rights reserved.\n\nCopyright (c) 2001, Colin McMillen. All rights reserved.\n\nThis program is free software; you may redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}