Heim > Backend-Entwicklung > PHP-Tutorial > PHP获取IP、IP所在地址与连接数实例代码_PHP教程

PHP获取IP、IP所在地址与连接数实例代码_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-07-13 17:43:18
Original
1366 Leute haben es durchsucht

//获取连接数最高的ip的详细信息 
$top = 10; 
//获取ip的详细信息 
$get_location = true; 
//反解ip,用于获取蜘蛛,开启后速度较慢 
$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、连接数/2、本机ip/3、对方ip 
/** 
* 端口/ip是唯一的 
*/
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 " 连接数:",$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; 
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478839.htmlTechArticle?php //获取连接数最高的ip的详细信息 $top = 10; //获取ip的详细信息 $get_location = true; //反解ip,用于获取蜘蛛,开启后速度较慢 $reverse = FALSE; //...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage