首頁 > php教程 > PHP源码 > 主體

php ping端口

PHP中文网
發布: 2016-05-23 16:37:15
原創
1893 人瀏覽過

跳至

    error_reporting(0);
    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],&#39;Server&#39;)){$k = $i; break;}
            }
            if(!stristr($array[$k],&#39;Server&#39;)) return &#39;unknown&#39;;
            else return str_replace(&#39;Server&#39;,&#39;服务器软件&#39;,$array[$k]);
    }
    function ping($host,$port)
    {
            $time_start = microtime_float();
            $ip = gethostbyname($host);
            $fp = @fsockopen($host,$port,&$errno,&$errstr,1);
            if(!$fp) return &#39;Request timed out.
    &#39;."\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 &#39;Reply from &#39;.$ip.&#39;: time=&#39;.$time.&#39;ms
    &#39;;
    }
    if(isset($_POST[&#39;url&#39;]) && isset($_POST[&#39;duankou&#39;]))
    {
            echo &#39;&#39;.getsoft($host,$port).&#39;  
    &#39;;
            echo &#39;Pinging &#39;.$host.&#39; [&#39;.gethostbyname($host).&#39;] with Port:&#39;.$port.&#39; of data:
      
    &#39;."\r\n";
            ob_flush();
            flush();
            for($i = 0;$i < $num;$i++)
            {
                    echo ping($host,$port);
                    ob_flush();
                    flush();
                    sleep(1);
            }
    }
?>域名/IP: 
端口:
登入後複製

                   

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!