废话不多讲,直接上代码吧!
复制代码 代码如下:
<?php
class MacAddr
{
public $returnArray = array();
public $macAddr;
function __contruct($os_type=null){
if(is_null($os_type)) $os_type = PHP_OS;
switch (strtolower($os_type)){
case "linux":
$this->forLinux();
break;
case "solaris":
break;
case "unix":
break;
case "aix":
break;
default:
$this->forWindows();
break;
}
$temp_array = array();
foreach($this->returnArray as $value ){
if(preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i", $value, $temp_array)){
$this->macAddr = $temp_array[0];
break;
}
}
unset($temp_array);
return $this->macAddr;
}
function forWindows(){
@exec("ipconfig /all", $this->returnArray);
if($this->returnArray)
return $this->returnArray;
else{
$ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";
if (is_file($ipconfig))
@exec($ipconfig." /all", $this->returnArray);
else
@exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->returnArray);
return $this->returnArray;
}
}
function forLinux(){
@exec("ifconfig -a", $this->returnArray);
return $this->returnArray;
}
}
$mac = new MacAddr(PHP_OS);
echo $mac->macAddr;
echo "<br />";
// 获取客户端
// linux
$command = "arp -a {$_SERVER['REMOTE_ADDR']}";
echo $command;
echo "<br />";
$result=`{$command}`;
// windows
$command = "nbtstat -a {$_SERVER['REMOTE_ADDR']}";
echo $command;
echo "<br />";
$result=`{$command}`;
print_r($result);
?>
获取服务端的逻辑没什么大问题,可能会存在权限问题。
获取客户端的时候,可能会比较慢,arp/nbstat命令执行会比较慢。
复制代码 代码如下:
<script language="JScript" event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for="foo">
document.forms[0].lbMacAddr.value=unescape(MACAddr);
</script>
<script language="JScript" event="OnObjectReady(objObject,objAsyncContext)" for="foo">
if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true && objObject.MACAddress != null && objObject.MACAddress != "undefined") MACAddr = objObject.MACAddress;
</script>
<object id="locator" classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6"></object>
<object id="foo" classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>
<script language="JScript">
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
</script>
<form><input type="text" id='lbMacAddr' name='lbMacAddr' /></form>
只适用于IE浏览器,而且会有告警提示,挺遗憾的。
客户端,mac
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 群星《环球国语元素》香港首版[WAV+CUE][1G]
- 周慧敏《玉女天后》原音母版1:1直刻[WAV+CUE][1G]
- 谭咏麟《20世纪中华歌坛名人百集珍藏版》[WAV+CUE][1G]
- 炉石传说40轮盘术最新卡组代码在哪找 标准40轮盘术卡组代码分享
- 炉石传说亲王贼怎么玩 2024亲王贼最新卡组代码分享
- 炉石传说30.6.2补丁后有什么卡组 30.6.2最强卡组最新推荐
- 模拟之声慢刻CD《蔡琴名曲回顾遇听》[原抓WAV+CUE]
- BruceLiu-WAVES(MusicbySatie)(2024)2CD[24Bit-96kHz]FLAC
- KonstantinKrimmel-MythosSchubertLoewe(2024)[24Bit-96kHz]FLAC
- 2024雷蛇高校挑战赛 嘤式分解助力收官之战
- 海信发布110吋世俱杯官方定制AI电视 引领智能观赛
- 海信发布27英寸显示器大圣G5 Pro:采用自研超解析芯片、友达原厂模组
- 蔡琴《机遇》1:1母盘直刻日本头版[WAV分轨][1.1G]
- 陈百强《与你几分钟的约会》XRCD+SHMCD限量编号版[低速原抓WAV+CUE][994M]
- 陈洁丽《监听王NO.1 》示范级发烧天碟[WAV+分轨][1.1G]