Ping is a command under Windows, UNIX, and Linux systems. Ping also belongs to a communication protocol and is part of the TCP/IP protocol. The ping command allows you to check if the network is connected and helps us to analyze and determine network failures. Application format: Ping space IP address. The command can also be used with many parameters, in particular, type ping to press ENTER to see detailed instructions.
PING (Packet Internet Groper), Internet Packet Explorer, a program for testing network connection volumes. Ping sends an ICMP (Internet control Messages Protocol) that is an Internet datagram control protocol, an ECHO request message to the destination and reports whether the desired Icmpecho (ICMP echo response) is received. It is a command to check whether the network is unobstructed or the speed of the network connection. As an administrator or hacker living on the network, the ping command is the first DOS command that must be mastered, and the principle is that it uses the uniqueness of the IP address of the machine on the network, sending a packet to the destination IP address, Ask the other party to return a packet of the same size to determine whether two network machines are connected, how much delay.
Ping refers to end-to-end connectivity, which is often used as a check for usability, but some virus Trojans force a large number of remote ping commands to preempt your network resources, causing the system to slow down and slow down. Ping intrusion is strictly forbidden as a basic function of most firewalls to provide users with a choice. In general, if you do not use as a server or network testing, you can safely select it to protect your computer.
This article mainly introduces the PHP implementation of the ping port function, in the form of an example of a more detailed analysis of PHP using socket programming skills, the need for friends can refer to the following, the implementation of the code as follows:
<?php/* * @function PHP functions that can ping ports * */error_reporting (E_ERROR); Header ("content-type:text/html; Charset=utf-8 "); Set_time_limit (120); $host = isset ($_post[' url ')? Chop (Str_replace (' http://', ' ', $_post[' url ')), ' www.baidu.com '; $port = isset ($_post[' Duankou ')? Chop ($_post[' Duankou '): ' 80 '; $num = 10; function microtime_float () {list ($usec, $sec) = Explode ("", Microtime ()); return (float) $usec + (float) $sec); } function Getsoft ($host, $port) {$fp = @fsockopen ($host, $port,& $errno,& $errstr, 3); if (! $fp) return ' unknown '; $get = "Get/http/1.1\r\nhost:". $host. " \r\nconnection:close\r\n\r\n "; @fputs ($fp, $get); $data = "; while ($fp &&!feof ($fp)) $data. = Fread ($fp, 1024); @fclose ($FP); $array = explode ("\ n", $data); $k = 2; for ($i = 0; $i < $i + +) {if (Stristr ($array [$i], ' Server ') {$k = $i; break;} } if (!stristr ($array [$k], ' Server ')) return ' unknown '; else return str_replace (' server ', ' Server Software ', $array [$k]); } function Ping ($host, $port) {$time _start = Microtime_float (); $ip = gethostbyname ($host); $fp = @fsockopen ($host, $port,& $errno,& $errstr, 1); if (! $fp) return ' Request timed out. ' \ r \ n "; $get = "Get/http/1.1\r\nhost:". $host. " \r\nconnection:close\r\n\r\n "; @fputs ($fp, $get); @fclose ($FP); $time _end = Microtime_float (); $time = $time _end-$time _start; $time = Ceil ($time * 1000); Return ' Reply from ' $ip. ': Time= '. $time. ' MS '; } if (Isset ($_post[' url ')) && isset ($_post[' Duankou ']) {echo ' <font color= ' #FF0000 > '. Gets OFT ($host, $port). ' </font> '; Echo ' Pinging '. $host. ' ['. gethostbyname ($host). '] With Port: '. $port. 'of data: '. ' \ r \ n "; Ob_flush (); Flush (); for ($i = 0; $i < $num; $i + +) {echo ping ($host, $port); Ob_flush (); Flush (); Sleep (1); }}?><form method= "POST" > Domain/ip:<input type= "text" name= "url" value= "<?php echo $host;? > "size=" > Port: <input type= "text" name= "Duankou" value= "<?php echo $port;? > "size=" > <input type= "Submit" value= "ping" ></form>