How can I get the MAC and the IP address of a connected client in PHP?

前端 未结 16 2374
长发绾君心
长发绾君心 2020-11-22 02:29

I need to know the MAC and the IP address of the connect clients, how can I do this in PHP?

相关标签:
16条回答
  • 2020-11-22 02:50

    I don't think you can get MAC address in PHP, but you can get IP from $_SERVER['REMOTE_ADDR'] variable.

    0 讨论(0)
  • 2020-11-22 02:52

    In windows, If the user is using your script locally, it will be very simple :

    <?php
    // get all the informations about the client's network
     $ipconfig =   shell_exec ("ipconfig/all"));  
     // display those informations   
     echo $ipconfig;
    /*  
      look for the value of "physical adress"  and use substr() function to 
      retrieve the adress from this long string.
      here in my case i'm using a french cmd.
      you can change the numbers according adress mac position in the string.
    */
     echo   substr(shell_exec ("ipconfig/all"),1821,18); 
    ?>
    
    0 讨论(0)
  • 2020-11-22 02:53

    Perhaps getting the Mac address is not the best approach for verifying a client's machine over the internet. Consider using a token instead which is stored in the client's browser by an administrator's login.

    Therefore the client can only have this token if the administrator grants it to them through their browser. If the token is not present or valid then the client's machine is invalid.

    0 讨论(0)
  • 2020-11-22 02:53

    under linux using iptables you can log to a file each request to web server with mac address and ip. from php lookup last item with ip address and get mac address.

    As stated remember that the mac address is from last router on the trace.

    0 讨论(0)
  • 2020-11-22 02:55

    Use this class (https://github.com/BlakeGardner/php-mac-address)

    This is a PHP class for MAC address manipulation on top of Unix, Linux and Mac OS X operating systems. it was primarily written to help with spoofing for wireless security audits.

    0 讨论(0)
  • 2020-11-22 03:00

    For windows server I think u can use this:

    <?php
    echo exec('getmac');
    ?>
    
    0 讨论(0)
提交回复
热议问题