可以用系统命令exec(); 假设你是win系统。远程用户的ip为$_SERVER['REMOTE_ADDR']; 先执行ping命令;再执行arp命令 <?php $ip = $_SERVER['REMOTE_ADDR']; if (exec("ping $ip")) { exec("arp -a $ip",$result); } ?> $result 为执行 "arp -a $ip"的返回结果;用正则表达式将形如52-54-ab-52-12-d6的字符取出即可; 这是我在win下cmd里的执行示例: C:\>ping 192.168.49.130Pinging 192.168.49.130 with 32 bytes of data:Reply from 192.168.49.130: bytes=32 time<10ms TTL=128 Reply from 192.168.49.130: bytes=32 time<10ms TTL=128 Reply from 192.168.49.130: bytes=32 time<10ms TTL=128 Reply from 192.168.49.130: bytes=32 time<10ms TTL=128Ping statistics for 192.168.49.130: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0msC:\>arp -a 192.168.49.130Interface: 192.168.50.62 on Interface 0x1000003 Internet Address Physical Address Type 192.168.49.130 52-54-ab-52-12-d6 dynamicC:\>
假设你是win系统。远程用户的ip为$_SERVER['REMOTE_ADDR'];
先执行ping命令;再执行arp命令
<?php
$ip = $_SERVER['REMOTE_ADDR'];
if (exec("ping $ip"))
{
exec("arp -a $ip",$result);
}
?>
$result 为执行 "arp -a $ip"的返回结果;用正则表达式将形如52-54-ab-52-12-d6的字符取出即可;
这是我在win下cmd里的执行示例:
C:\>ping 192.168.49.130Pinging 192.168.49.130 with 32 bytes of data:Reply from 192.168.49.130: bytes=32 time<10ms TTL=128
Reply from 192.168.49.130: bytes=32 time<10ms TTL=128
Reply from 192.168.49.130: bytes=32 time<10ms TTL=128
Reply from 192.168.49.130: bytes=32 time<10ms TTL=128Ping statistics for 192.168.49.130:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0msC:\>arp -a 192.168.49.130Interface: 192.168.50.62 on Interface 0x1000003
Internet Address Physical Address Type
192.168.49.130 52-54-ab-52-12-d6 dynamicC:\>
收藏的,没测试过..CODE /*------------------------------------------------------------
*GetClientAddr 取访问者地址
* Parameters:$AiType -- 类型1:IP,2:MAC,3:IP+MAC
* Return: 地址串
*------------------------------------------------------------*/
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;
}
上面所谓的arp -a 和nbtstat 只能在局域网内使用,一旦server和client跨过了某个路由器、防火墙甚至是一个三层交换机(更不要说是代理服务器),此种命令即告失效。
@exec(" ipconfig -all > c:\file/physicAddress.txt");
?>
*GetClientAddr 取访问者地址
* Parameters:$AiType -- 类型1:IP,2:MAC,3:IP+MAC
* Return: 地址串
*------------------------------------------------------------*/
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;
}
____________________________________________
这是win下面的程序,
linux下面的是
________________________________________
/*****************************
*function : get ip and mac of client
*parameter : mode,msgString
*returnvalue:
*discribe : shell_exec arp IP in linux sys
*foundtime :
*****************************/
function getClientIp($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 = "arp $ip";
$sString = shell_exec($sCmd);
for($iCount=0;$iCount<10;$iCount++)
$sString=str_replace(" "," ",$sString);
$aTemp = split(" ",$sString);
$sMac = trim($aTemp[count($aTemp)-3]);
}
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;
}
再linux下面执行arp 就可以得到本网络的MAC值!
远程读用户不是读本地只能通过activex来做
————————————————————
以上的是得到访问用户的mac,而且是在远程执行!
hover_online(ξ芎メ)
的方法
是通过分析命令行结果得出mac地址但是有的情况下得不出来结果