欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php获取IP、MAC地址函数

程序员文章站 2022-04-10 21:24:51
...
参数$AiType取值:1:IP,2:MAC,3:IP+MAC
返回 return string:地址串

<?php
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:地址串

<?php
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中文网(www.php.cn)!