Home > Backend Development > PHP Tutorial > PHP obtains IP, IP address and connection number example code_PHP tutorial

PHP obtains IP, IP address and connection number example code_PHP tutorial

WBOY
Release: 2016-07-13 17:43:18
Original
1347 people have browsed it

//Get the detailed information of the IP with the highest number of connections
$top = 10;
//Get the detailed information of the IP
$get_location = true;
//Reverse IP, used to obtain spiders, the speed is slower after opening
$reverse = FALSE;
//$reverse = TRUE;

ini_set(extension_dir,dirname(__FILE__));
ini_set(enable_dl,TRUE);
if(!dl("php_curl.dll")){
exit(Can load curl .);
}
$content = `netstat -an -p TCP`;
$regex = "/s TCPs d .d .d .d :(d )s (d .d .d .d ):d s /sm";
$table = array();
//1, number of connections/2, local ip/3, other party ip
/**
* Port/ip is unique
*/
if(preg_match_all($regex,$content,$result)){
foreach($result[1] as $i=>$port){
if(isset($table[$port .:.$result[2][$i]]))
                                                                                                                    :.$result[2][$i]] = 1;
}
$curl = curl_init();
curl_setopt($curl,CURLOPT_TIMEOUT,5);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$i = 0;
$count = 0;
if(asort($table))
foreach( $table as $key=>$times){
$ip = substr(strstr($key,:),1);
$port = substr($key,0,strpos($key,: ));
$i ;
echo " Number of connections: ",$times, - ,$key;
if(!$get_location || $i continue;
}
if( $port==80) $count = $times;
if($ip!==127.0.0.1 || $ip!==0.0.0.0){
$host = $reverse ? gethostbyaddr($ip ) : $ip;
if($host==$ip){
curl_setopt($curl,CURLOPT_URL, "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format =txt&ip=".$ip);
$location = curl_exec($curl);
echo "(".preg_replace(/(s|d|.)/,,$location).")";
} else {
echo "(".$host.")";
}
}
}
echo " ",All(80):,$count;
}
?>

http://www.bkjia.com/PHPjc/478839.html

truehttp: //www.bkjia.com/PHPjc/478839.htmlTechArticle?php //Get the details of the IP with the highest number of connections $top = 10; //Get the details of the IP Information $get_location = true; //Reverse IP, used to obtain spiders, the speed is slower after opening $reverse = FALSE; //...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template