获取网络客户端MAC地址,使用PhP的语法问题 [英] Getting Network Client MAC address, Syntax issue using PhP
本文介绍了获取网络客户端MAC地址,使用PhP的语法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上,如果我直接在shell_exec()
Actually the below coding is working fine, if I provide the ip address directly inside the shell_exec()
$mac = shell_exec('arp -a 192.168.0.107');
如果,我从其系统获取客户端的ip并将其存储在变量中,然后调用该变量,如下所示,
If, I get the ip of the client from his system and stored in a variable and call the same, as given below,
$mac = shell_exec('arp -a' . escapeshellarg($ip));
输出未生成.
这是完整的代码:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$mac = shell_exec('arp -a'. escapeshellarg($ip));
//Working fine when sample client IP is provided...
//$mac = shell_exec('arp -a 192.168.0.107');
$findme = "Physical";
$pos = strpos($mac, $findme);
$macp = substr($mac,($pos+42),26);
if(empty($mac))
{
die("No mac address for $ip not found");
}
// having it
echo "mac address for $ip: $macp";
?>
请告知,为什么escapeshellarg($ip)
在shell_exec()
中不起作用.
Please advise, why escapeshellarg($ip)
does not work in the shell_exec()
.
推荐答案
shell_exec('arp '.$ip.' | awk \'{print $4}\'');
终端的结果
└──arp 10.1.10.26 | awk'{print $ 4}'
└── arp 10.1.10.26 | awk '{print $4}'
a4:5e:60:ee:29:19
这篇关于获取网络客户端MAC地址,使用PhP的语法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文