Implementation code _php Tutorial for obtaining MAC Address (Windows/linux) for intranet users in PHP

Source: Internet
Author: User
Copy CodeThe code is as follows:
function Ce_getmac ()
{
if (Php_os = = ' WINNT ')
{
$return _array = Array ();
$temp _array = Array ();
$mac _addr = "";
@exec ("Arp-a", $return _array);
foreach ($return _array as $value)
{
if (Strpos ($value, $_server["Http_client_ip")!== false &&
Preg_match ("/(:?? [ 0-9a-f]{2}[:-]) {5}[0-9a-f]{2}/i ", $value, $temp _array))
{
$mac _addr = $temp _array[0];
Break
}
}
Return $mac _addr? Strtoupper ($mac _addr): ";
}
else if (Php_os = = ' Linux ')
{
return true;
}
}

function has been modified, to Linux found not to use the EXEC function, that is, to obtain a MAC address. After communication, the project must be deployed under the Linux server, the author after a long time to find a solution, without exec can also get to the intranet user's MAC address.
In the intranet server, there is a 192.168.1.151 server, the server on the API, access to the API, to obtain the user Mac,josn way to output user account information, because the server can obtain a Mac, you can use a little bit.
Using curl to forge the source IP (IP is not the IP of the Linux server, is the IP address of the client access), curl to 151 server, the server gets corresponding, according to the User IP address and arp-a parameters of the regular way can get the client's MAC address, the program runs in 151, And 151 is a Windows 2008 server. However, it is important to note that you cannot use REMOTE_ADDR and you must use HTTP_CLIENT_IP. The reason is that HTTP_CLIENT_IP can be forged using curl so that you can use Linux to get the user's IP and then send it to 151 processing.
Question: According to the user IP to get the MAC address, then the user to change an IP what to do? With CMD under ARP-A analysis, the MAC address of the computer that should be the user is not replaced by default, even if the user is changing the IP.

The following is a excerpt of the Netizen's article about acquiring IP:
DZ Code Judge IP that block is too annoying, day, remote_addr,http_client_ip,http_x_forwarded_for three things in manual too not detailed, basically equals No.
Online GG A bit, find a little, in addition, there is a train of thought too coincidence, with JS take IP post to the server, Y with proxy cheat server? A kind of internet first to turn JS off Ah!! Oh haha, later have the opportunity to use Ajax to try, also save to use these three variables if to die.

$_server[' ... '; for PHP
One, not using the proxy server situation:
REMOTE_ADDR = Your IP
Http_via = no value or no display
Http_x_forwarded_for = no value or no display
Second, the use of transparent proxy server situation: Transparent Proxies
REMOTE_ADDR = Last Proxy server IP
Http_via = Proxy Server IP
Http_x_forwarded_for = Your real IP, after multiple proxy servers, this value resembles the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
This type of proxy server also forwards your information to your Access object, and does not achieve the purpose of hiding the true identity.
Third, the use of ordinary anonymous proxy server situation: Anonymous Proxies
REMOTE_ADDR = Last Proxy server IP
Http_via = Proxy Server IP
Http_x_forwarded_for = Proxy IP, after multiple proxies, this value resembles the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
Hides your real IP, but reveals to the Access object that you are using a proxy server to access them.
Iv. use of deceptive proxy servers: distorting Proxies
REMOTE_ADDR = Proxy Server IP
Http_via = Proxy Server IP
Http_x_forwarded_for = Random IP, after multiple proxy servers, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
Tells the Access object that you used a proxy server, but fabricated a bogus random IP to spoof it instead of your real IP.
V. Use of highly anonymous proxy servers: High anonymity Proxies (Elite Proxies)
REMOTE_ADDR = Proxy Server IP
Http_via = no value or no display
Http_x_forwarded_for = no value or not displayed, after multiple proxy servers, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
Full use of Proxy server information replaces all of your information, as if you were using the proxy server directly to access the object.

REMOTE_ADDR is the IP of your client when it "shakes hands" with your server. If you use anonymous proxy, REMOTE_ADDR displays the IP of the proxy server.
HTTP_CLIENT_IP is the HTTP header sent by the proxy server. If "Super Anonymous proxy", the value of none is returned. Similarly, REMOTE_ADDR will be replaced with the IP of this proxy server.
$_server[' REMOTE_ADDR ']; The IP of the access side (possibly the user, possibly the proxy)
$_server[' Http_client_ip ']; Agent-side (may exist, can be forged)
$_server[' http_x_forwarded_for ']; The user is the agent in which IP is used (may exist or can be forged)

http://www.bkjia.com/PHPjc/324164.html www.bkjia.com true http://www.bkjia.com/PHPjc/324164.html techarticle Copy the code as follows: function Ce_getmac () {if (Php_os = = ' WINNT ') {$return _array = array (), $temp _array = Array (); $mac _addr = ""; @exec ("Arp-a", $return _array); foreach ($re ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.