This article describes how to use php to obtain the IP address, host name, and mac address of all users in the LAN, if you need a php instance, you can refer to the php instance described in this article to obtain the computer IP address, host name, and mac address of all users in the LAN. It provides some reference for php programmers. The complete code is as follows:
<? Php $ bIp = gethostbyname ($ _ ENV ['computername']); // Obtain the local LAN IPecho "local IP:", $ bIp, "\ n "; echo "local host name:", gethostbyaddr ($ bIp), "\ n "; // The gethostbyaddr function can obtain the host name based on the lan ip address // Default Gateway IPlist ($ ipd1, $ ipd2, $ ipd3) = explode ('. ', $ bIp); $ mask = $ ipd1. ". ". $ ipd2. ". ". $ ipd3; exec ('arp-A', $ aIp); // obtain other IPforeach ($ aIp as $ ipv) {if (strpos ($ ipv, 'interface ')! = False) {// check whether the displayed IP address is in the current LAN rather than other types. you can try the command $ bool = false in cmd; preg_match ('/(? :(?: 25 [0-5] | 2 [0-4] \ d | (1 \ d {2}) | ([1-9]? \ D) \.) {3 }(?: 25 [0-5] | 2 [0-4] \ d | (1 \ d {2}) | ([1-9]? \ D)/', $ ipv, $ arr); if (strcmp ($ arr [0], $ bIp) = 0) {$ bool = true ;}} else {if ($ bool) {$ str = preg_replace ('/\ s +/', '|', $ ipv); $ sArr = explode ('| ', $ str); if ($ sArr [1] = 'Internet' | empty ($ sArr [1]) {continue ;} // remove the default gateway if (strcmp ($ mask. ". 1 ", $ sArr [1]) = 0) {continue;} // remove the 255 IP address if (strcmp ($ mask. ". 255 ", $ sArr [1]) = 0) {continue;} // remove multicast IP list ($ cIp) = explode ('. ', $ sArr [1]); if ($ cIp >=224 & $ cIp <= 239) {continue;} echo "IP address: | ", $ sArr [1], "| \ n"; echo "MAC address:", $ sArr [2], "\ n"; echo "host name :", gethostbyaddr ($ sArr [1]), "\ n"; echo "\ n ";}}}
This program runs in cli mode and can be used in a browser.
Php obtains the user ip address in the LAN. it mainly uses the exec function of php and the arp-a command of the window.
Get the local IP address: gethostbyname ($ _ ENV ['computername']) is different from the previous method. if you are interested, you can continue to study it in depth.
The gethostbyaddr (IPd) function is also powerful.