English 中文(简体)
使用 Pphp 运行 ipp 配置命令
原标题:Run ipconfig command with php

我用这个代码来理解一些访问者( 客户) 的信息。 它一直在 Xampp 上的虚拟服务器上运行, 但我无法运行主服务器( 主机) 。 我看到的是空白页面 。

$info = system( ipconfig /all );
echo $info;
问题回答

这可能帮助你

<强 > 服务器 IP

您可以从$_SERVER[SERVER_ADR]获得服务器IP地址。

<强度> 密钥 IP 地址

您可以从 $_SERVER[REMOTE_ADD] 获得客户端 IP

< 加强 > 编辑 : 您在评论中询问如何获取外部命令的输出 - 一种方法是使用回icks, 例如 。

$ipAddress=$_SERVER[ REMOTE_ADDR ];
$macAddr=false;

#run the external command, break output into lines
$arp=`arp -a $ipAddress`;
$lines=explode("
", $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 Macs关于使用Javashamp的建议。

也可以尝试跟随命令

 <?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");
?>

这将只获取 < engen@ em> serverers 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 




相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签