This example for you to share the PHP to obtain the real IP address instance code, for your reference.
The main is to obtain the operating system for WIN2000/XP, Win7 native IP real address, and get the operating system for Linux type of the native IP real address, the specific contents are 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/";
Get operating system for WIN2000/XP, Win7 native IP real address
exec ("ipconfig", $out, $stats);
if (!empty ($out)) {
foreach ($out as $row) {
if strstr ($row, "IP") && strstr ($row, ":") &&!strst R ($row, "IPv6")) {
$tmpIp = explode (":", $row);
if (Preg_match ($preg, Trim ($tmpIp [1])) {return
trim ($tmpIp [1]);
}}} Get the operating system for Linux type native IP real 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 ' 127.0.0.1 ';
}
The above is the entire content of this article, I hope to help you learn.