php实现的ping端口函数实例,phpping端口实例
本文实例讲述了php实现的ping端口函数。分享给大家供大家参考。
具体实现代码如下:
复制代码 代码如下:
/*
* @author xujiajay
* @date 2010-10-7
* @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
{
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 ''.getsoft($host,$port).'';
echo 'Pinging '.$host.' ['.gethostbyname($host).'] with Port:'.$port.' of data:'."\r\n";
ob_flush();
flush();
for($i = 0;$i
{
echo ping($host,$port);
ob_flush();
flush();
sleep(1);
}
}
?>
希望本文所述对大家的PHP程序设计有所帮助。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Dreamweaver CS6
視覺化網頁開發工具