pocketmine\utils\Utils::getIP PHP Method

getIP() public static method

Gets the External IP using an external service, it is cached
public static getIP ( boolean $force = false ) : string
$force boolean default false, force IP check even when cached
return string
    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("https://api.ipify.org")));
        if ($ip) {
            Utils::$ip = $ip;
        } 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;
                    }
                }
            }
        }
        return Utils::$ip;
    }

Usage Example

Example #1
0
 private function networkFunctions()
 {
     $config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
     echo "[!] " . $this->lang->query_warning1 . "\n";
     echo "[!] " . $this->lang->query_warning2 . "\n";
     echo "[?] " . $this->lang->query_disable . " (y/N): ";
     if (strtolower($this->getInput("n")) === "y") {
         $config->set("enable-query", false);
     } else {
         $config->set("enable-query", true);
     }
     echo "[*] " . $this->lang->rcon_info . "\n";
     echo "[?] " . $this->lang->rcon_enable . " (y/N): ";
     if (strtolower($this->getInput("n")) === "y") {
         $config->set("enable-rcon", true);
         $password = substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10);
         $config->set("rcon.password", $password);
         echo "[*] " . $this->lang->rcon_password . ": " . $password . "\n";
     } else {
         $config->set("enable-rcon", false);
     }
     /*echo "[*] " . $this->lang->usage_info . "\n";
     		echo "[?] " . $this->lang->usage_disable . " (y/N): ";
     		if(strtolower($this->getInput("n")) === "y"){
     			$config->set("send-usage", false);
     		}else{
     			$config->set("send-usage", true);
     		}*/
     $config->save();
     echo "[*] " . $this->lang->ip_get . "\n";
     $externalIP = Utils::getIP();
     $internalIP = gethostbyname(trim(`hostname`));
     echo "[!] " . $this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP]) . "\n";
     echo "[!] " . $this->lang->ip_confirm;
     $this->getInput();
 }
All Usage Examples Of pocketmine\utils\Utils::getIP