PHP Get IP, IP address and number of Connections instance Code _php tutorial

Source: Internet
Author: User
Tags get ip
Get more information about the IP with the highest number of connections
$top = 10;
Get details of IP
$get _location = true;
Reverse IP, used to get spiders, slow 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) s (d. D. D):d s/sm";
$table = Array ();
1, the number of connections/2, the machine IP/3, the other 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]])
$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 "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:, $count;
}
?>

http://www.bkjia.com/PHPjc/478839.html www.bkjia.com true http://www.bkjia.com/PHPjc/478839.html techarticle ? PHP//Get the details of the highest number of connections $top = 10;//Get the details of the IP $get _location = true;//reverse IP, used to get the spider, the speed is slower after opening $reverse = FALSE;

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.