Cleaned up Utils::getIP(), resolved strict-type issues, close #1062

This commit is contained in:
Dylan K. Taylor 2017-06-11 10:25:48 +01:00
parent 61b857a81c
commit 75cc2d6914

View File

@ -126,39 +126,51 @@ class Utils{
* *
* @param bool $force default false, force IP check even when cached * @param bool $force default false, force IP check even when cached
* *
* @return string * @return string|bool
*/ */
public static function getIP($force = false){ public static function getIP($force = false){
if(Utils::$online === false){ if(Utils::$online === false){
return false; return false;
}elseif(Utils::$ip !== false and $force !== true){ }elseif(Utils::$ip !== false and $force !== true){
return Utils::$ip; return Utils::$ip;
} }
$ip = trim(strip_tags(Utils::getURL("http://checkip.dyndns.org/")));
if(preg_match('#Current IP Address\: ([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){ do{
Utils::$ip = $matches[1]; $ip = Utils::getURL("http://api.ipify.org/");
}else{ if($ip !== false){
$ip = Utils::getURL("http://www.checkip.org/"); Utils::$ip = $ip;
if(preg_match('#">([0-9a-fA-F\:\.]*)</span>#', $ip, $matches) > 0){ break;
Utils::$ip = $matches[1];
}else{
$ip = Utils::getURL("http://checkmyip.org/");
if(preg_match('#Your IP address is ([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){
Utils::$ip = $matches[1];
}else{
$ip = trim(Utils::getURL("http://ifconfig.me/ip"));
if($ip != ""){
Utils::$ip = $ip;
}else{
return false;
}
}
} }
}
$ip = Utils::getURL("http://checkip.dyndns.org/");
if($ip !== false and preg_match('#Current IP Address\: ([0-9a-fA-F\:\.]*)#', trim(strip_tags($ip)), $matches) > 0){
Utils::$ip = $matches[1];
break;
}
$ip = Utils::getURL("http://www.checkip.org/");
if($ip !== false and preg_match('#">([0-9a-fA-F\:\.]*)</span>#', $ip, $matches) > 0){
Utils::$ip = $matches[1];
break;
}
$ip = Utils::getURL("http://checkmyip.org/");
if($ip !== false and preg_match('#Your IP address is ([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){
Utils::$ip = $matches[1];
break;
}
$ip = Utils::getURL("http://ifconfig.me/ip");
if($ip !== false and trim($ip) != ""){
Utils::$ip = trim($ip);
break;
}
return false;
}while(false);
return Utils::$ip; return Utils::$ip;
} }
/** /**