PHP取得MAC地址
<?php // 在linux下面取得MAC地址// 在windows下面需要外部mac.exe,// mac . exe为返回MAC地址的可执行程序,这个你们可以自己用DELPHi或者VC写 /// 作者 hisun <[email protected]>// 任何疑问,请到 <a href="http://www.hisunweb.com" target="_blank">www.hisunweb.com</a> 留言,谢谢!// 请尊重作者劳动成果if ($_ENV["OS"] == "Windows_NT") { function getMAC($nic = "lo") { $mac_exe_file = "e:\mac.exe"; if ($nic == 'lo') return "000000000000"; if ($nic != 'eth0') { return false; } $s1 = trim(shell_exec($mac_exe_file)); return strtolower($s1); } } else { function getMAC($nic = "lo") { if ($nic == 'lo') return "000000000000"; $s1 = shell_exec("/sbin/ifconfig " . escapeshellarg($nic) . " | head -1"); if (strpos($s1, 'HWaddr') <= 1) { return false; } else { $a = explode('HWaddr', $s1); $s2 = str_replace(":", "", trim($a[1])); return strtolower($s2); } } } // echo "lo=>".getMAC()."<br>";echo "eth0=>" . getMAC('eth0') . "<br>";echo "eth1=>" . getMAC('eth1') . "<br>";?>
<?php // 在linux下面取得MAC地址// 在windows下面需要外部mac.exe,// mac . exe为返回MAC地址的可执行程序,这个你们可以自己用DELPHi或者VC写 /// 作者 hisun <[email protected]>// 任何疑问,请到 <a href="http://www.hisunweb.com" target="_blank">www.hisunweb.com</a> 留言,谢谢!// 请尊重作者劳动成果if ($_ENV["OS"] == "Windows_NT") { function getMAC($nic = "lo") { $mac_exe_file = "e:\mac.exe"; if ($nic == 'lo') return "000000000000"; if ($nic != 'eth0') { return false; } $s1 = trim(shell_exec($mac_exe_file)); return strtolower($s1); } } else { function getMAC($nic = "lo") { if ($nic == 'lo') return "000000000000"; $s1 = shell_exec("/sbin/ifconfig " . escapeshellarg($nic) . " | head -1"); if (strpos($s1, 'HWaddr') <= 1) { return false; } else { $a = explode('HWaddr', $s1); $s2 = str_replace(":", "", trim($a[1])); return strtolower($s2); } } } // echo "lo=>".getMAC()."<br>";echo "eth0=>" . getMAC('eth0') . "<br>";echo "eth1=>" . getMAC('eth1') . "<br>";?>
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=true")
For Each IPConfig In IPConfigSet
s = ""
ss = ""
For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
ss = ss & IPConfig.IPAddress(i) & " "
Next
s = s & "IPAddress: " & ss & vbCrLf
s = s & "MACAddress: " & IPConfig.MACAddress & vbCrLf
MsgBox s
Next
LINUX/BSD下,就用最老土的方法(当初我初学啊,嘻)
用exec()去调用ifconfig命令,把结果集保存,再进行正则分析,取得ETHER后面的值就可以,这个在服务端比较容易,呵呵,下次问问题时,说清楚一下,好回答
for($Tmpa;$Tmpa<count($array);$Tmpa++){
if(eregi($REMOTE_ADDR,$array[$Tmpa])){
$mac=explode($REMOTE_ADDR,$array[$Tmpa]);
echo $mac[1];
}
}
echo $REMOTE_ADDR;
?>