From 2665dffdd8a8318cae82dbe12080a3a336944b92 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 11 Jan 2013 15:08:02 +0100 Subject: [PATCH] Show External IP --- src/API/ServerAPI.php | 3 +++ src/classes/Utils.class.php | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 5200bfcee..edd506900 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -102,6 +102,9 @@ class ServerAPI{ console("[INFO] [UPnP] Trying to port forward..."); UPnP_PortForward($this->getProperty("port")); } + if(($ip = Utils::getIP()) !== false){ + console("[INFO] External IP: ".$ip); + } if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ console("[INFO] Checking for new server version"); console("[INFO] Last check: ".date("Y-m-d H:i:s", $this->getProperty("last-update"))); diff --git a/src/classes/Utils.class.php b/src/classes/Utils.class.php index 0ffa02461..580586aa2 100644 --- a/src/classes/Utils.class.php +++ b/src/classes/Utils.class.php @@ -40,6 +40,21 @@ class Utils extends Thread{ public function run(){ } + + public static function getIP(){ + $ip = trim(Utils::curl_get("http://automation.whatismyip.com/n09230945.asp")); + if($ip != ""){ + return $ip; + }else{ + $ip = trim(Utils::curl_get("http://checkip.dyndns.org/")); + $ip = preg_replace("/Current IP Address: (.*)/", '$1', $ip); + if($ip != ""){ + return $ip; + }else{ + return false; + } + } + } public static function getOS(){ $uname = strtoupper(php_uname("s")); @@ -310,7 +325,7 @@ class Utils extends Thread{ public static function curl_get($page){ $ch = curl_init($page); - curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Minecraft PHP Client 2")); + curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP")); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); @@ -328,7 +343,7 @@ class Utils extends Thread{ curl_setopt($ch, CURLOPT_POSTFIELDS, $args); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Minecraft PHP Client 2")); + curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout); $ret = curl_exec($ch);