No DT, only DT [NET class sharing]

Source: Internet
Author: User

A problem has plagued us for a long time. How can we handle the identity of website visitors? IP address? What if the user changes the IP address? Later I thought that the MAC address of the user's computer is unique, and OK solved the problem by trying to get the user's MAC address. But how can we solve this problem? I checked it all over the Internet and found a method to use my MAC, but it wasn't the result we wanted. Is it swollen? DT asked the teacher. He said that PHP could not get the MAC address. It was so sad. Later I thought about it. Maybe you really don't know. However, Guan Rong met Jack Li, a strong brother V5! In the strong brother's class, I accidentally learned a function about MAC operations. It was so happy and inspired! Arp-a (use arp directly on linux). As long as a user logs on to your website, communication will be established, and his MAC will be saved to your arp list. Execute the doscommand using the exec () function in php, and assign the result of exec () to an array, which is the result of DOS.
----------------------------------------------------------------------------------
C: \ Documents ents and Settings \ Administrator> arp-

Interface: 192.168.100.254 --- 0x2
Internet Address Physical Address Type
192.168.100.000000-00-00-00-00-00-00 invalid

Interface: 192.168.60.29 --- 0x3
Internet Address Physical Address Type
192.168.60.1 3c-e5-a6-0c-60-bb dynamic
192.168.60.4 00-1f-c6-e9-4c-a3 dynamic
192.168.60.13 00-16-d3-2f-83-55 dynamic
192.168.60.28 00-15-58-7b-72-92 dynamic
192.168.60.100 dc-0e-a1-5f-57-a6 dynamic
192.168.60.179 00-15-58-81-07-4e dynamic
192.168.60.214 00-16-41-17-f0-d1 dynamic
----------------------------------------------------------------------------------
After getting this array, we can get the user's mac. Here we will use some string processing functions. We recommend that you use explode () to quickly get the desired data, is it very happy.
I also found some problems during the test. I need to continue to improve the command. This command runs well in windows, but it is too slow in linux, however, the general idea here is complete. When a user accesses a website, he must first determine the user's operating system and then select the method in the NET class to solve the problem, in other words, using awk in linux is more convenient than using php Strings To operate functions. We look forward to your mutual improvement and new questions and common progress!
The source code is attached below.
<! -- Net. class. php -->
<? Php
/**
* Collect visitors' Network Information
*
*/
Class Net {
/**
* Parameter list
* Www.2cto.com
* @ Param string $ MAC information line of the IP address configuration file of the hostMac Server
* @ Param string $ Vip client IP Address
* @ Param string $ MAC address of the Vmac Client
*
*/

Private $ hostMac = array ();
Static $ Vip = NULL;
Private $ pos;
Static $ Vmac = NULL;
Private $ Maclist = array ();

/**
* Obtain the MAC address of the server.
* @ Param int $ temporary parameters that Tmpa supports for Loops
* @ Param array $ temporary array for Tmarr to store list information
* @ Return value: the MAC address of the server.
*/
Public function getHostMac (){
@ Exec ("ipconfig/all", $ Tmarr );
For ($ Tmpa; $ Tmpa <count ($ Tmarr); $ Tmpa ++ ){
If (eregi ("Physical", $ Tmarr [$ Tmpa]) {
$ This-> hostMac = explode (":", $ Tmarr [$ Tmpa]);
}
}
Return $ this-> hostMac [1];
}

/**
* Obtain the IP address of the client.
* @ Param int $ temporary parameters that Tmpa supports for Loops
* @ Param array $ temporary array for Tmarr to store list information
* @ Return value: Client IP Address
*/
Public function getVisitIp (){
If (self: $ Vip! = NULL ){
Return self: $ Vip;
}
If (isset ($ _ SERVER ['HTTP _ X_FORWARDED_FOR ']) {
$ Tmarr = explode (',', $ _ SERVER ['HTTP _ X_FORWARDED_FOR ']);
$ Pos = array_search ('unknown ', $ Tmarr );
If (false! ==$ Pos ){
Unset ($ Tmarr [$ pos]);
}
Echo self: $ Vip;
Die ();
} Elseif (isset ($ _ SERVER ['HTTP _ CLIENT_IP ']) {
Self: $ Vip = $ _ SERVER ['HTTP _ CLIENT_IP '];
} Elseif (isset ($ _ SERVER ['remote _ ADDR ']) {
Self: $ Vip = $ _ SERVER ['remote _ ADDR '];
}
// Valid IP address verification
Self: $ Vip = (false! = Ip2long (self: $ Vip ))? Self: $ Vip: '0. 0.0.0 ';
Return self: $ Vip;
}

/**
* Obtain the MAC address of the client.
*
* @ Param int $ temporary parameters that Tmpa supports for Loops
* @ Param array $ temporary array for Tmarr to store list information
* @ Return value: client MAC
*/
Public function getVisitMac (){
@ Exec ("arp-a", $ Tmarr );
$ Ip = $ this-> getVisitIp ();
For ($ Tmpa; $ Tmpa <count ($ Tmarr); $ Tmpa ++ ){
If (eregi ($ ip, $ Tmarr [$ Tmpa]) {
Self: $ Vmac = explode ("", $ Tmarr [$ Tmpa]);
}
}
Return self: $ Vmac [11];
}
Public function filter ($ mac, $ ip) {// defines a function for filtering MAC @ return string $ clinetMac

$ Ecar = array_shift ($ mac );
While (count ($ mac) <> 0 ){
$ Ecar = array_pop ($ mac );
If (substr_count ($ Ecar, $ ip) = 1 ){
$ ClientMac = trim ($ Ecar );
$ ClientMac = str_replace ($ ip, "", $ clientMac );
$ ClientMac = str_split (trim ($ clientMac), 17 );
Return $ clientMac = $ clientMac [0];
}
}
}
}

?>
Author: zdrjlamp

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.