PHP to obtain the intranet user's MAC address (WINDOWS/linux) implementation code

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

The function has been modified. in LINUX, it is found that the EXEC function cannot be used, that is, the MAC address cannot be obtained. After communication, the project must be deployed on the LINUX server. After thinking for a long time, I finally found a solution. I can get the MAC address of the Intranet user without executing EXEC.
On an intranet server, there is a server with 192.168.1.151. When an API on the server accesses this API, it obtains the user's MAC and JOSN to output the user account information, because the server can obtain MAC, you can use it a little.
Use CURL to forge the source IP address (the IP address is not the IP address of the LINUX server, it is the IP address accessed by the client), CURL to the 151 server, the server gets the corresponding, you can obtain the MAC address of the client based on the user IP address and the regular expression of ARP-A parameter. The program runs on 151, while 151 is a windows 2008 server. However, you must use HTTP_CLIENT_IP instead of REMOTE_ADDR. The reason is that HTTP_CLIENT_IP can be forged using CURL, so that you can use LINUX to obtain the user IP address and then send it to 151 for processing.
Q: What should I do if I get a MAC address from the user's IP address? Using ARP-A analysis under CMD, even if the user changes the IP address, the MAC address of the computer that should be the user will not be changed by default.

The following is an excerpt from a netizen's article on obtaining an IP Address:
It is a headache for the dz code to judge the IP address. The three things, namely, REMOTE_ADDR, HTTP_CLIENT_IP, and HTTP_X_FORWARDED_FOR, are too detailed in the manual and basically do not have them.
Gg found out one thing on the Internet. In addition, there was a clever idea. I used JS to get the IP address and POST it to the server. Why did Y use proxy to lie to the server? There is a kind of Internet connection. I shut down Js first !! Oh, haha. I have the chance to try ajax in the future, and I don't have to use these three variables if they are dead.

$ _ SERVER ['...']; // for php
I. No proxy server is used:
REMOTE_ADDR = your IP address
HTTP_VIA = no value or no display
HTTP_X_FORWARDED_FOR = no value or no display
Ii. Transparent proxy server: Transparent Proxies
REMOTE_ADDR = IP address of the last Proxy Server
HTTP_VIA = Proxy Server IP Address
HTTP_X_FORWARDED_FOR = your real IP address. When multiple proxy servers are used, this value is similar to the following: 203.98.1820.3, 203.98.1820.3, 203.129.72.215.
This type of proxy server still forwards your information to your access object, which cannot hide your real identity.
Iii. Normal Anonymous proxy server: Anonymous Proxies
REMOTE_ADDR = IP address of the last Proxy Server
HTTP_VIA = Proxy Server IP Address
HTTP_X_FORWARDED_FOR = Proxy Server IP address. When multiple proxy servers are used, this value is similar to the following: 203.98.1820.3, 203.98.1820.3, 203.129.72.215.
Your real IP address is hidden, but you are disclosed to the access object that you use the proxy server to access them.
Iv. destorting Proxies
REMOTE_ADDR = Proxy Server IP Address
HTTP_VIA = Proxy Server IP Address
HTTP_X_FORWARDED_FOR = random IP address. When multiple proxy servers are used, the value is as follows: 203.98.182.163, 203.98.182.163, 203.129.72.215.
It tells the access object that you used the proxy server, but fabricated a false random IP address instead of your real IP address to cheat it.
5. High Anonymity Proxies (Elite proxies)
REMOTE_ADDR = Proxy Server IP Address
HTTP_VIA = no value or no display
HTTP_X_FORWARDED_FOR = no value or no value is displayed. When multiple proxy servers are used, the value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
The proxy server information replaces all your information, just as you directly access the object using the proxy server.

REMOTE_ADDR is the IP address when your client "shakes hands" with your server. If "anonymous proxy" is used, REMOTE_ADDR displays the IP address of the proxy server.
HTTP_CLIENT_IP is the HTTP header sent by the proxy server. If it is a "Super anonymous proxy", the return value is none. Similarly, REMOTE_ADDR will be replaced with the IP address of the proxy server.
$ _ SERVER ['remote _ ADDR ']; // IP address of the access end (which may be a user or a proxy)
$ _ SERVER ['HTTP _ CLIENT_IP ']; // proxy end (it may exist and can be forged)
$ _ SERVER ['HTTP _ X_FORWARDED_FOR ']; // the proxy of the user's IP address (which may exist or can be forged)

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.