我使用这段代码来理解访问者(客户)的一些信息。它已经在我的Xampp虚拟服务器上运行了,但我不能在我的主服务器(主机)上运行。我看到的只是一张白纸。
$info = system('ipconfig /all');
echo $info;发布于 2012-05-22 22:37:48
这可能会对你有帮助
服务器IP
您可以从$_SERVER['SERVER_ADDR']获取服务器IP地址。
客户端IP地址
您可以从$_SERVER['REMOTE_ADDR']获取客户端IP
编辑:你在注释中询问如何获得外部命令的输出-一种方法是使用反号,例如
$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");
?>发布于 2012-05-22 22:39:25
这将仅获得服务器的 IP信息,而不是客户端。因为您是在本地PC上运行代码,所以您将看到本地信息(与服务器信息相同)。
另外,如果您的主机服务器运行的是linux,则该命令将为ifconfig,但这仍然只能获取服务器信息。
发布于 2012-05-22 22:44:54
既然您已经说明了服务器是基于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 https://stackoverflow.com/questions/10704239
复制相似问题