This article mainly introduces php to obtain the real IP address instance code of the local machine, which has some reference value, interested friends can refer to the examples in this article to share with you the php code for getting the real IP address of the local machine for your reference.
It is mainly used to obtain the real IP address of the local machine whose OS is win2000/xp and win7, and the real IP address of the local machine whose OS is linux. the specific content is as follows:
Function getLocalIP () {$ preg = "/\ A ([0-9]? [0-9]) | (1 [0-9] {2}) | (2 [0-4] [0-9]) | (25 [0-5]) \.) {3} ([0-9]? [0-9]) | (1 [0-9] {2}) | (2 [0-4] [0-9]) | (25 [0-5]) \ Z/"; // Obtain the real IP address exec (" ipconfig ", $ out, $ stats); if (! Empty ($ out) {foreach ($ out AS $ row) {if (strstr ($ row, "IP") & strstr ($ row ,":") &&! Strstr ($ row, "IPv6") {$ tmpIp = explode (":", $ row); if (preg_match ($ preg, trim ($ tmpIp [1]) {return trim ($ tmpIp [1]) ;}}} // Obtain the real IP address exec ("ifconfig", $ out, $ stats); if (! Empty ($ out) {if (isset ($ out [1]) & strstr ($ out [1], 'addr :')) {$ tmpArray = explode (":", $ out [1]); $ tmpIp = explode ("", $ tmpArray [1]); if (preg_match ($ preg, trim ($ tmpIp [0]) {return trim ($ tmpIp [0]) ;}} return '2017. 0.0.1 ';}
The above is all the content of this article, hoping to help you learn.