PHP get IP, MAC address function

黄舟
Release: 2023-03-03 19:10:01
Original
1867 people have browsed it

参数$AiType取值:1:IP,2:MAC,3:IP+MAC
返回 return string:地址串

function GetClientAddr($AiType=0) 

  $sMac = ""; 
  $ip= getenv("REMOTE_ADDR");  
  $ip1 = getenv("HTTP_X_FORWARDED_FOR");  
  $ip2 = getenv("HTTP_CLIENT_IP");  
  ($ip1) ? $ip = $ip1 : null;  
  ($ip2) ? $ip = $ip2 : null;  
  if ($AiType > 1) 
  { 
     $sCmd = "nbtstat -a " . $ip; 
     $sString = shell_exec($sCmd); 
     $aTemp = split("=",$sString); 
     $sMac = trim($aTemp[count($aTemp)-1]); 
  } 
  switch($AiType) 
  { 
    case 0: 
      $sResult = ""; 
      break; 
    case 1: 
      $sResult = $ip; 
      break; 
    case 2: 
      $sResult = $sMac; 
      break; 
    case 3: 
      $sResult = $ip . " " . $sMac; 
      break; 
    default: 
      $sResult = ""; 
      break; 
   } 
    return $sResult; 

?>    

参数$AiType取值:1:IP,2:MAC,3:IP+MAC
返回 return string:地址串

function GetClientAddr($AiType=0) 

  $sMac = ""; 
  $ip= getenv("REMOTE_ADDR");  
  $ip1 = getenv("HTTP_X_FORWARDED_FOR");  
  $ip2 = getenv("HTTP_CLIENT_IP");  
  ($ip1) ? $ip = $ip1 : null;  
  ($ip2) ? $ip = $ip2 : null;  
  if ($AiType > 1) 
  { 
     $sCmd = "nbtstat -a " . $ip; 
     $sString = shell_exec($sCmd); 
     $aTemp = split("=",$sString); 
     $sMac = trim($aTemp[count($aTemp)-1]); 
  } 
  switch($AiType) 
  { 
    case 0: 
      $sResult = ""; 
      break; 
    case 1: 
      $sResult = $ip; 
      break; 
    case 2: 
      $sResult = $sMac; 
      break; 
    case 3: 
      $sResult = $ip . " " . $sMac; 
      break; 
    default: 
      $sResult = ""; 
      break; 
   } 
    return $sResult; 

?>    


 以上就是php获取IP、MAC地址函数的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)! 


Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!