mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
Cleaned up Utils::getIP(), resolved strict-type issues, close #1062
This commit is contained in:
parent
61b857a81c
commit
75cc2d6914
@ -126,39 +126,51 @@ class Utils{
|
||||
*
|
||||
* @param bool $force default false, force IP check even when cached
|
||||
*
|
||||
* @return string
|
||||
* @return string|bool
|
||||
*/
|
||||
|
||||
public static function getIP($force = false){
|
||||
if(Utils::$online === false){
|
||||
return false;
|
||||
}elseif(Utils::$ip !== false and $force !== true){
|
||||
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){
|
||||
Utils::$ip = $matches[1];
|
||||
}else{
|
||||
$ip = Utils::getURL("http://www.checkip.org/");
|
||||
if(preg_match('#">([0-9a-fA-F\:\.]*)</span>#', $ip, $matches) > 0){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
do{
|
||||
$ip = Utils::getURL("http://api.ipify.org/");
|
||||
if($ip !== false){
|
||||
Utils::$ip = $ip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user