& Lt ;? Php & nbsp; // obtain detailed information about the ip address with the highest number of connections & nbsp; $ top10; & nbsp; // obtain detailed information about the ip address & nbsp; $ get_locationtrue; & nbsp; // reverse ip address, used to obtain the spider. it is slow to enable & nbsp; $ reverseFALSE; & nbsp; // $ reverseTRUE; & nbsp; I
// Obtain detailed information about the ip address with the highest number of connections
$ Top = 10;
// Obtain the ip address details
$ Get_location = true;
// Reverse ip address, used to obtain the spider. it is slow to enable
$ 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) s (d. d): d s/sm ";
$ Table = array ();
// 1. number of connections/2. local ip address/3. peer ip address
/**
* The port/ip address is unique.
*/
If (preg_match_all ($ regex, $ content, $ result )){
Foreach ($ result [1] as $ I => $ port ){
If (isset ($ table [$ port.:. $ result [2] [$ I])
$ Table [$ port.:. $ result [2] [$ I];
Else
$ Table [$ port.:. $ 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 "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;
}
?>