Run ipconfig command with php

前端 未结 3 1449
醉梦人生
醉梦人生 2021-01-22 05:34

I use this code to understand some information of visitors (clients). It has been running on my virtual server on Xampp, but I can`t run on my main server (host). I see just a b

3条回答
  •  忘掉有多难
    2021-01-22 06:04

    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

     
    

提交回复
热议问题