diff --git a/src/Util.php b/src/Util.php index 3556c8a..809a485 100644 --- a/src/Util.php +++ b/src/Util.php @@ -15,50 +15,7 @@ class Util */ public static function getLocalIp() { - try { // if exec can be used - $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/"; - - if (PATH_SEPARATOR == ':') { // linux - 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]); - } - } - } - } else { // windows PATH_SEPARATOR==';' - 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]); - } - } - } - } - } - } catch (Exception $ex) { - } - - if (isset( $_ENV["HOSTNAME"] )) { - $MachineName = $_ENV["HOSTNAME"]; - } else { - if (isset( $_ENV["COMPUTERNAME"] )) { - $MachineName = $_ENV["COMPUTERNAME"]; - } else { - $MachineName = ""; - } - } - if ($MachineName != "") { - return $MachineName; - } - - return '127.0.0.1'; + return getHostByName(getHostName()); }