Esempio n. 1
0
 public function getServerIP()
 {
     if (self::$_serverIp) {
         return self::$_serverIp;
     }
     $request = "<ip><get/></ip>";
     $response = pm_ApiRpc::getService('1.6.5.0')->call($request);
     if ('ok' != $response->ip->get->result->status) {
         throw new pm_Exception("Unable to get server IP. Error: {$response->ip->get->result->errtext}");
     }
     // Get default IP
     foreach ($response->ip->get->result->addresses->ip_info as $address) {
         if (!isset($address->default)) {
             continue;
         }
         return self::$_serverIp = (string) $address->public_ip_address ?: (string) $address->ip_address;
     }
     // Get first IP
     foreach ($response->ip->get->result->addresses->ip_info as $address) {
         return self::$_serverIp = (string) $address->public_ip_address ?: (string) $address->ip_address;
     }
     throw new pm_Exception("Unable to get server IP: empty result.");
 }