


How to obtain the computer IP, host name, and mac address of all users in php LAN
Introduces in detail the implementation of php to obtain the computer IP, host name, and mac address of all users on the LAN. It is very practical. Friends in need can refer to it
The code is as follows:
<?php $bIp = gethostbyname($_ENV['COMPUTERNAME']); //获取本机的局域网IP echo "本机IP:",$bIp,"\n"; echo "本机主机名:",gethostbyaddr($bIp),"\n\n\n"; //gethostbyaddr 函数可以根据局域网IP获取主机名 //默认网关IP list($ipd1,$ipd2,$ipd3) = explode('.',$bIp); $mask = $ipd1 . "." . $ipd2 . "." . $ipd3 ; exec('arp -a',$aIp); //获取局域网中的其他IP foreach( $aIp as $ipv) { if(strpos($ipv,'接口') !== false) {//一下显示的IP是否是当前局域网中的 而不是其他的类型 可以在cmd下试一下命令 $bool = false; 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; } //去除默认网关 if(strcmp($mask . ".1", $sArr[1]) == 0) { continue; } //去除同网关下255的IP if(strcmp($mask . ".255", $sArr[1]) == 0) { continue; } //去除组播IP list($cIp) = explode('.', $sArr[1]); if($cIp >= 224 && $cIp <= 239) { continue; } echo "IP地址:|",$sArr[1],"|\n"; echo "MAC地址:",$sArr[2],"\n"; echo "主机名:",gethostbyaddr($sArr[1]),"\n"; echo "\n\n"; } } }
php implements a complete example of obtaining the computer IP, host name, and mac address of all users on the LAN
This program is run in cli mode, on the browser It should also be possible
php has completed the function of getting the user IP in the LAN. The main ones used are the exec function of php and the arp -a command of window
Get the local IP: gethostbyname ($_ENV['COMPUTERNAME']) is different from the previous writing method. Interested friends can continue to study it in depth.
Get the host name function: gethostbyaddr(IPd) This function is also very powerful.
Recommended learning: php video tutorial
The above is the detailed content of How to obtain the computer IP, host name, and mac address of all users in php LAN. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8's JIT compilation enhances performance by compiling frequently executed code into machine code, benefiting applications with heavy computations and reducing execution times.

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses symmetric and asymmetric encryption in PHP, comparing their suitability, performance, and security differences. Symmetric encryption is faster and suited for bulk data, while asymmetric is used for secure key exchange.

The article discusses implementing robust authentication and authorization in PHP to prevent unauthorized access, detailing best practices and recommending security-enhancing tools.

Prepared statements in PHP enhance database security and efficiency by preventing SQL injection and improving query performance through compilation and reuse.Character count: 159

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the mysqli_query() and mysqli_fetch_assoc() functions in PHP for MySQL database interactions. It explains their roles, differences, and provides a practical example of their use. The main argument focuses on the benefits of usin
