复制代码 代码如下:
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. I found that the EXEC function cannot be used on LINUX, which means that the MAC address cannot be obtained. After communication, the project must be deployed under a LINUX server. After thinking hard for a long time, the author finally found a solution. The MAC address of the intranet user can be obtained without executing EXEC.
In the intranet server, there is a server at 192.168.1.151. There is an API on the server. When accessing this API, the user's MAC is obtained and the user account information is output in JOSN mode. Because the server can obtain the MAC, you can add a little bit. Take advantage of.
Use CURL to forge the source IP (the IP is not the IP of the LINUX server, but the IP address accessed by the client), CURL to the 151 server, and the server gets the response. It can be obtained according to the regular method of the user IP address and ARP -A parameters. The MAC address of the client, the program is running on 151, and 151 is the WINDOWS 2008 server. But it should be noted that REMOTE_ADDR cannot be used, HTTP_CLIENT_IP must be used. The reason is that HTTP_CLIENT_IP can be forged using CURL, so that LINUX can be used to obtain the user IP and then sent to 151 for processing.
Question: Obtain the MAC address based on the user’s IP. What should I do if the user changes his IP? Using ARP -A analysis under CMD, even if the user changes IP, the MAC address of the computer corresponding to the user will not be changed by default.
The following is an excerpt from a netizen’s article about obtaining IP:
The dz code to determine the IP is too troublesome. The three things of REMOTE_ADDR, HTTP_CLIENT_IP, and HTTP_X_FORWARDED_FOR are not detailed in the manual. , basically means nothing.
I searched online and found something. In addition, there is an idea that is too clever. Use JS to get the IP and then POST to the server. How about using a proxy to deceive the server? If you have the guts to go online, turn off JS first! ! Oh haha, I will try it with ajax if I have a chance in the future, and I won’t have to worry about using these three variables if.
$_SERVER['...']; // for php
1. When no proxy server is used:
REMOTE_ADDR = Your IP
HTTP_VIA = No value or not displayed
HTTP_X_FORWARDED_FOR = No value or not displayed
2. When using transparent proxy servers: Transparent Proxies
REMOTE_ADDR = Last proxy server IP
HTTP_VIA = Proxy server IP
HTTP_X_FORWARDED_FOR = Your real IP, when passing through multiple proxy servers, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
This type of proxy server still forwards your information to the person you are visiting, and cannot achieve the purpose of hiding your true identity.
3. The situation of using ordinary anonymous proxy servers: Anonymous Proxies
REMOTE_ADDR = Last proxy server IP
HTTP_VIA = Proxy server IP
HTTP_X_FORWARDED_FOR = Proxy server IP, when passing through multiple proxy servers, this The values are similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
Hide your real IP, but reveal to your visitors that you are using a proxy server to access them.
4. The use of deceptive proxy servers: Distorting Proxies
REMOTE_ADDR = proxy server IP
HTTP_VIA = proxy server IP
HTTP_X_FORWARDED_FOR = random IP, when passing through multiple proxy servers, this value is similar As follows: 203.98.182.163, 203.98.182.163, 203.129.72.215.
Tell the visitor that you are using a proxy server, but make up a fake random IP instead of your real IP to trick it.
5. The use of high-anonymity proxy servers: High Anonymity Proxies (Elite proxies)
REMOTE_ADDR = Proxy server IP
HTTP_VIA = No value or not displayed
HTTP_X_FORWARDED_FOR = No value or not displayed, after When there are multiple proxy servers, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
Completely replaces all your information with the proxy server's information, just like you are using that proxy server to directly access the object.
REMOTE_ADDR is the IP when your client "handshakes" with your server. If an "anonymous proxy" is used, REMOTE_ADDR will display the IP of the proxy server.
HTTP_CLIENT_IP is the HTTP header sent by the proxy server. If it is a "super anonymous proxy", a value of none is returned. Likewise, REMOTE_ADDR will be replaced with the IP of this proxy server.
$_SERVER['REMOTE_ADDR']; //Accessing end (may be user, may be proxy) IP
$_SERVER['HTTP_CLIENT_IP']; //Proxy end (may exist, can be forged) )
$_SERVER['HTTP_X_FORWARDED_FOR']; //Which IP the user is using as a proxy (may exist or can be forged)
http://www.bkjia.com/PHPjc/324164.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324164.htmlTechArticleCopy 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...