search
Homephp教程PHP源码可以ping端口的php函数


<?php
/*
 * @author     xujiajay
 * @date       2010-10-7
 * @email      xujiaphp@gmail.com
 * @function   可以ping端口的php函数
 *
 */
	error_reporting(E_ERROR);
	header("content-Type: text/html; charset=utf-8");
	set_time_limit(120);
	$host = isset($_POST[&#39;url&#39;]) ? chop(str_replace(&#39;http://&#39;,&#39;&#39;,$_POST[&#39;url&#39;])) : &#39;www.baidu.com&#39;;
	$port = isset($_POST[&#39;duankou&#39;]) ? chop($_POST[&#39;duankou&#39;]) : &#39;80&#39;;
	$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 &#39;unknown&#39;;
	        $get = "GET / HTTP/1.1\r\nHost:".$host."\r\nConnection: Close\r\n\r\n";
	        @fputs($fp,$get);
	        $data = &#39;&#39;;
	        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: 
端口:

                   

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools