使用php运行ipconfig命令
我使用此代码来理解访客(客户)的一些信息。它一直在我的Xampp虚拟服务器上运行,但我无法在我的主服务器(主机)上运行。我只看到一页空白使用php运行ipconfig命令,php,windows,cmd,mac-address,ipconfig,Php,Windows,Cmd,Mac Address,Ipconfig,我使用此代码来理解访客(客户)的一些信息。它一直在我的Xampp虚拟服务器上运行,但我无法在我的主服务器(主机)上运行。我只看到一页空白 $info = system('ipconfig /all'); echo $info; 这可能对你有帮助 服务器IP 您可以从$\u server['server\u ADDR']获取服务器IP地址 客户端IP地址 您可以从$\u服务器['REMOTE\u ADDR'] 编辑:在注释中询问如何获取外部命令的输出-一种方法是使用反勾号,例如 $ipAddre
$info = system('ipconfig /all');
echo $info;
这可能对你有帮助 服务器IP 您可以从
$\u server['server\u ADDR']
获取服务器IP地址
客户端IP地址
您可以从$\u服务器['REMOTE\u ADDR']
编辑:在注释中询问如何获取外部命令的输出-一种方法是使用反勾号,例如
$ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;
#run the external command, break output into lines
$arp=`arp -a $ipAddress`;
$lines=explode("\n", $arp);
#look for the output line describing our IP address
foreach($lines as $line)
{
$cols=preg_split('/\s+/', trim($line));
if ($cols[0]==$ipAddress)
{
$macAddr=$cols[1];
}
}
但是如果客户端不在局域网上怎么办?
好吧,除非你能让客户自愿提供这些信息并通过其他方式传递,否则你就不走运了。请参阅Peter G Mac关于使用Javascript的建议
您还可以尝试执行以下命令
<?php
// http://www.php.net/manual/en/function.exec.php#85930
$_ = null;
// If you care about the return value, use this:
passthru("C:\\WINDOWS\\system32\\cmd.exe /c custom.bat",$_);
header('Content-Type: text/plain');
echo $_;
// if you don't care, just use this:
$_ = exec("C:\\WINDOWS\\system32\\cmd.exe /c custom.bat");
?>
这将只获取服务器IP信息,而不是客户端。因为您正在本地PC上运行代码,所以您将看到您的本地信息(与服务器信息相同)
另外,如果您的主机服务器运行的是linux,那么该命令将是ifconfig
,但这仍然只能获取服务器信息。好吧,既然您澄清了服务器是基于linux的,那么linux上正确的命令是
/sbin/ifconfig -a
返回的数据看起来略有不同
eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: 0000::000:0000:0000:0000/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14141910 errors:0 dropped:0 overruns:0 frame:0
TX packets:6532919 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4462743134 (4.4 GB) TX bytes:1340503018 (1.3 GB)
Interrupt:22 Memory:f6ae0000-f6b00000
主服务器是基于windows的服务器吗?不,服务器有Linux操作系统(Apache)。ipconfig不在Linux上运行。使用ifconfig for theipconfig
返回服务器的网络信息,而不是连接的客户端的网络信息。此服务器是apache。那么,为什么它要在xampp上运行呢?xampp将apache作为服务器运行。xampp只是lamp安装(php、mysql、apache)的包装器ipconfig
/ifconfig
依赖于操作系统的命令,而不是apache
/php
命令