PHP to get the LAN IP function, is not very useful, which God help to optimize a bit

Source: Internet
Author: User
I wrote the original code as follows:

function The_lan_ip () {//

if (!is_windows_os ()) {//If it is not the Windows operating system, perform ifconfig to catch the corresponding IPV4 IP
EXEC (' ifconfig ', $output);
for ($i = 0; $i <= count ($output); $i + +) {
error_reporting (0);
Preg_match ('/\inet.*:(. *) \040/', $output [$i], $the _ip_str); Through the regular to find inet corresponding IP address is the LAN IP
if (count ($the _ip_str) > 0) {
$the _lan_ip[$i] = $the _ip_str[1];
}
}
} else {exec (' ipconfig ', $output);//If it is a Windows operating system, execute ipconfig to catch the corresponding IPV4 IP
for ($i = 0; $i <= count ($output); $i + +) {
error_reporting (0);
Preg_match ('/\ipv4.*:(. *)/', $output [$i], $the _ip_str); Through the regular to find IPv4 corresponding IP address is the LAN IP
if (count ($the _ip_str) > 0) {
$the _lan_ip[$i] = $the _ip_str[1];
}
}
}
Return ($the _lan_ip);
}

The above describes the PHP to get the LAN IP function, is not very useful, which God help to optimize a bit, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.