我正在从事 laravel 项目。我需要访问访问该网站的客户的IP地址和MAC地址。
他们有什么方法可以获取这两个地址。
我用过:
Request::ip();
我得到了客户端的IP地址。但是如何获取MAC地址。
提前致谢。
最佳答案
是的,你可以做到
BY DEFAULT PHP HAS A BUILT IN FUNCTION THAT EXECUTES THE COMMAND LINE COMMANDS
shell_exec
http://php.net/manual/en/function.shell-exec.php
执行
http://php.net/manual/en/function.exec.php
所以为了获取mac地址写了函数
function getMAcAddressExec()
{
return substr(exec('getmac'), 0, 17);
}
echo getMAcAddressExec();
function getMAcAddressShellExec()
{
return substr(shell_exec('getmac'), 159,20);
}
echo getMAcAddressShellExec();
已编辑
在 routes
文件夹下的 web.php
文件中添加以下行
Route::get('/getmacshellexec',function()
{
$shellexec = shell_exec('getmac');
dd($shellexec);
}
);
Route::get('/getmacexec',function()
{
$shellexec = exec('getmac');
dd($shellexec);
}
);
然后尝试 url
yourproject/getmacshellexec
和
yourproject/getmacexec
请在下面评论你得到的任何输出
关于php - 如何在 laravel 中获取客户端 IP 地址和 MAC 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54758803/