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. You can use the "ping" command to check whether the network is connected, which can help us analyze and determine network faults. Application format: Ping space IP address. This command can also be used with many parameters. Specifically, type Ping and press Enter to see detailed instructions.
PING (Packet Internet Groper), Internet packet explorer, a program used to test the amount of network connections. Ping sends an ICMP (Internet Control Messages Protocol), which is the Internet Message Control Protocol; an echo request message is sent to the destination and reports whether the desired ICM Echo (ICMP echo response) is received. It is a command used to check whether the network is smooth or the network connection speed. As an administrator or hacker living on the network, the ping command is the first DOS command that must be mastered. The principle it uses is this: using the uniqueness of the IP address of the machine on the network, send a message to the target IP address. A data packet, and then ask the other party to return a data packet of the same size to determine whether the two network machines are connected and what the delay is.
Ping refers to end-to-end connectivity, which is usually used as an availability check. However, some viruses and Trojans will force a large number of remote execution ping commands to seize your network resources, causing the system to slow down and the network speed to slow down. . Strictly prohibit ping intrusion as a basic function of most firewalls for users to choose. Under normal circumstances, if you are not using it as a server or conducting network testing, you can safely select it to protect your computer.
This article mainly introduces the ping port function implemented by PHP, and analyzes in detail the skills of PHP using socket programming in the form of examples. Friends in need can refer to it. The specific implementation code is as follows:
<?php /* * @function 可以ping端口的php函数 * */ 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 < 20;$i++) { if(stristr($array[$i],'Server')){$k = $i; break;} } if(!stristr($array[$k],'Server')) return 'unknown'; else return str_replace('Server','服务器软件',$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">'.getsoft($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"> 域名/IP:<input type="text" name="url" value="<?php echo $host;?>" size="50"> 端口:<input type="text" name="duankou" value="<?php echo $port;?>" size="10"> <input type="submit" value="ping"> </form>
The above is the detailed content of Example code of ping port function implemented in PHP. For more information, please follow other related articles on the PHP Chinese website!

多年来,Xbox控制台得到了突飞猛进的改进。多年来,游戏不断发展,具有栩栩如生的功能,而游戏玩家似乎无法获得足够的体验。在Xbox上玩您最喜欢的游戏可能是一种完全引人入胜的体验。但是,有时使用这些高级功能,如果互联网速度不是那么好,我们最终会遇到延迟或ping问题。有时我们希望游戏下载速度更快。如今,像ForzaHorizon5和MortalKombat这样的游戏需要超过100GB的内存。如果我们没有正确的互联网设置来帮助我们,下载此类游戏可能需要很长时间。方法1:通过

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

ping请求超时的原因有目标主机不可达、网络拥堵、防火墙或安全设置和DNS解析问题等。详细介绍:1、目标主机不可达,Ping请求超时可能意味着目标主机无法通过网络访问,可能是由于目标主机关闭了网络连接、目标主机所在的网络出现故障、目标主机IP地址设置错误等原因导致;2、网络拥堵,Ping请求超时也可能是由于网络拥堵导致的,网络拥堵可能是由于大量的数据传输、网络设备故障等等。

网络ping不通,是什么回事?其实这是个非常常见的问题了,主要分为两种情况,同网段ping不通和不同网段ping不通,下面就来看看详细内容吧。 同网段ping不通的原因ping命令无法连接的情况通常有两种:一是在同一网段内无法ping通的IP地址,另一种是在不同网段内无法ping通的IP地址。这两种情况具有不同的解决方法。首先,我们来讨论在同一网段内ping不通的情况。 一、同网段ping不通,结果是“无法访问目标主机” 目的ip和源ip是同一网段的,ping的结果是&l

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment
