Run ipconfig command with php

余生颓废 提交于 2019-12-02 02:15:01

this might help you

Server IP

You can get the server IP address from $_SERVER['SERVER_ADDR'].

Client IP address

You can get the client IP from $_SERVER['REMOTE_ADDR']

Edit: you ask in comments how to get the output of an external command - one way is to use backticks, e.g.

$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];
   }
}

But what if the client isn't on a LAN?

Well, you're out of luck unless you can have the client volunteer that information and transmit via other means. See Peter G Mac's suggestion for using Javascript.

you can also try following command

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

This would only get the servers IP information not the client. Because you are running the code on your local PC you will see your local information (which will be the same as the server information).

Also if your hosts server is running linux, the command would be ifconfig, but that would still only get the server information.

Well, since you clarified that the server is linux based, the correct command on linux is

/sbin/ifconfig -a

The data returned will look slightly different

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 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!