IP of the Host

@return void
189760
protected function _ip()
    {
        if (PSI_USE_VHOST === true) {
           if ((CommonFunctions::readenv('SERVER_ADDR', $result) || CommonFunctions::readenv('LOCAL_ADDR', $result)) //is server address defined
               && !strstr($result, '.') && strstr($result, ':')) { //is IPv6, quick version of preg_match('/\(([[0-9A-Fa-f\:]+)\)/', $result)
                $dnsrec = dns_get_record($this->sys->getHostname(), DNS_AAAA);
                if (isset($dnsrec[0]['ipv6'])) { //is DNS IPv6 record
                    $this->sys->setIp($dnsrec[0]['ipv6']); //from DNS (avoid IPv6 NAT translation)
                } else {
                    $this->sys->setIp(preg_replace('/^::ffff:/i', '', $result)); //from SERVER_ADDR or LOCAL_ADDR
                }
            } else {
                $this->sys->setIp(gethostbyname($this->sys->getHostname())); //IPv4 only
            }
        } else {
            if (CommonFunctions::readenv('SERVER_ADDR', $result) || CommonFunctions::readenv('LOCAL_ADDR', $result)) {
                $this->sys->setIp(preg_replace('/^::ffff:/i', '', $result));
            } else {
                $this->sys->setIp(gethostbyname($this->sys->getHostname()));
            }
        }
    }
135160
private function getCustomerIP()
    {
        $ip = null;
        if(array_key_exists('X-Forwarded-For', $_SERVER)) {
            $ip = $_SERVER['X-Forwarded-For'];
        } elseif(array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif(array_key_exists('REMOTE_ADDR', $_SERVER)) {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        return $ip;
    }
68712
public function ip() 
    {
        if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') > 0) {
                $addr = explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']);
                return trim($addr[0]);
            } else {
                return $_SERVER['HTTP_X_FORWARDED_FOR'];
            }
        } else {
            return $_SERVER['REMOTE_ADDR'];
        }
    }
840605
public static function IP(){
   switch(true){
     case !empty($_SERVER['HTTP_X_FORWARDED_FOR']):
       $ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_FOR'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_FOR']);
     break;
     case !empty($_SERVER['HTTP_X_FORWARDED_HOST']):
       $ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_HOST'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_HOST']);
     break;
     case !empty($_SERVER['REMOTE_ADDR']):    $ip = $_SERVER['REMOTE_ADDR']; break;
     case !empty($_SERVER['HTTP_CLIENT_IP']): $ip = $_SERVER['HTTP_CLIENT_IP']; break;
     default:                                 $ip = ''; break;
   }
   return Filter::with('core.request.IP',$ip);
  }
1205274
public function getClientIp()
    {
        if (!empty($this->getHeader('X-Forwarded-For'))) {
            $ip = preg_replace('/(?:,.*)/', '', $this->hasHeader('X-Forwarded-For'));
        } elseif (!empty($this->getHeader('Client-Ip'))) {
            $ip = $this->getHeader('Client-Ip');
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return trim($ip);
    }
433897
public static function getClientIp()
    {
        if (getenv("HTTP_CLIENT_IP")){
            $ip = getenv("HTTP_CLIENT_IP");
        }
        else if (getenv("HTTP_X_FORWARDED_FOR")){
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        }
        else if (getenv("HTTP_X_FORWARDED")){
            $ip = getenv("HTTP_X_FORWARDED");
        }
        else if (getenv("HTTP_FORWARDED_FOR")){
            $ip = getenv("HTTP_FORWARDED_FOR");
        }
        else if (getenv("HTTP_FORWARDED")){
            $ip = getenv("HTTP_FORWARDED");
        }
        else{
            $ip = $_SERVER["REMOTE_ADDR"];
        }
        return $ip;
    }
533735
public function getClientIp()
    {
        $ipaddress = getenv('HTTP_CLIENT_IP') ?:
            getenv('HTTP_X_FORWARDED_FOR') ?:
                getenv('HTTP_X_FORWARDED') ?:
                    getenv('HTTP_FORWARDED_FOR') ?:
                        getenv('HTTP_FORWARDED') ?:
                            getenv('REMOTE_ADDR');
			    
	//Try to get client IP from SERVER variables
        if(!$ipaddress)
        {
            return $this->getClientIpFromServerVar();
        }
        return $ipaddress;
    }
375484
public function getClientIP()
    {
        if (getenv('HTTP_CLIENT_IP')) {
            $ipaddress = getenv('HTTP_CLIENT_IP');
        } else if (getenv('HTTP_X_FORWARDED_FOR')) {
            $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
        } else if (getenv('HTTP_X_FORWARDED')) {
            $ipaddress = getenv('HTTP_X_FORWARDED');
        } else if (getenv('HTTP_FORWARDED_FOR')) {
            $ipaddress = getenv('HTTP_FORWARDED_FOR');
        } else if (getenv('HTTP_FORWARDED')) {
            $ipaddress = getenv('HTTP_FORWARDED');
        } else if (getenv('REMOTE_ADDR')) {
            $ipaddress = getenv('REMOTE_ADDR');
        } else if (isset($_SERVER['REMOTE_ADDR'])) {
            $ipaddress = $_SERVER['REMOTE_ADDR'];
        } else {
            $ipaddress = '127.0.0.0';
        }
        return $ipaddress;
    }
406736
public function getHostname()
    {
        if (is_null($this->hostname)) {
            $this->hostname = gethostbyaddr($this->ip);
        }

        return $this->hostname;
    }
543094
public static function getIp()
    {
        if (isset(Request::getServerParams()['HTTP_CLIENT_IP'])) {
            $client = Request::getServerParams()['HTTP_CLIENT_IP'];
        }
        if (isset(Request::getServerParams()['HTTP_X_FORWARDED_FOR'])) {
            $forward = Request::getServerParams()['HTTP_X_FORWARDED_FOR'];
        }

        $remote = Request::getServerParams()['REMOTE_ADDR'];

        if (isset($client) && filter_var($client, FILTER_VALIDATE_IP)) {
            return $client;
        } elseif (isset($forward) && filter_var($forward, FILTER_VALIDATE_IP)) {
            return $forward;
        }

        return $remote;
    }
425769
private function getRemoteIp()
    {
        if ($this->remote) {
            $ip = file_get_contents('http://ipecho.net/plain');

            if ($ip && self::isValid($ip)) {
                return $ip;
            }
        }
    }
382480
public function getIp()
    {
        if ($this->X_FORWARDED_FOR) {
            return $this->X_FORWARDED_FOR;
        }

        if ($this->CLIENT_IP) {
            return $this->CLIENT_IP;
        }

        if ($this->SERVER_NAME) {
            return gethostbyname($this->SERVER_NAME);
        }

        return $this->REMOTE_ADDR;
    }
1154914
public function getIp()
    {
        $keys = ['X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR', 'CLIENT_IP', 'REMOTE_ADDR'];

        foreach ($keys as $key) {
            $ip = $this->getServerParam($key);

            if (!$ip) {
                continue;
            }

            $ip = preg_replace('/,.*$/u', '', $ip);
            $ip = trim($ip);

            return $ip;
        }

        return null;
    }
918228
private function setClientIPs()
    {
        if ($this->isUsingTrustedProxy()) {
            $this->clientIps = [$this->server->get('REMOTE_ADDR')];
        }
        $clientIps = [];

        if ($this->header->has(self::$trustedHeaderNames[RequestHeaderConstants::FORWARDED])) {
            $header = $this->header->get(self::$trustedHeaderNames[RequestHeaderConstants::FORWARDED]);
            preg_match_all("/for=(?:\"?\[?)([a-z0-9:\.\-\/_]*)/", $header, $matches);
            $clientIps = $matches[1];
        } elseif ($this->header->has(self::$trustedHeaderNames[RequestHeaderConstants::CLIENT_IP])) {
            $clientIps = explode(',', $this->header->get(self::$trustedHeaderNames[RequestHeaderConstants::CLIENT_IP]));
            $clientIps = array_map('trim', $clientIps);
        }

        $clientIps[] = $this->server->get('REMOTE_ADDR');
        $fallbackClientIps = [$clientIps[0]];

        foreach ($clientIps as $index => $clientIp) {
            // Check for valid IPs
            if (!filter_var($clientIp, FILTER_VALIDATE_IP)) {
                unset($clientIps[$index]);

                continue;
            }

            // Don't allow trusted proxies
            if (in_array($clientIp, self::$trustedProxies)) {
                unset($clientIps[$index]);
            }
        }

        $this->clientIps = (count($clientIps) == 0) ? $fallbackClientIps : array_reverse($clientIps);
    }
1251550
public function ip()
    {
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip_add = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWADED_FOR'])) {
            $ip_add = $_SERVER['HTTP_X_FORWADED_FOR'];
        } else {
            $ip_add = $_SERVER['REMOTE_ADDR'];
        }

        return $ip_add;
    }
657328
def get_my_ip():
    """"""
    ip = subprocess.check_output(GET_IP_CMD, shell=True).decode('utf-8')[:-1]
    return ip.strip()
135567
public function getIpAddress()
    {
        foreach ($this->headers as $k)
        {
            if (isset($this->server[$k]))
            {
                // header can be comma separated
                $ips = explode(',', $this->server[$k]);
                $ip = trim(end($ips));
                $ip = filter_var($ip, FILTER_VALIDATE_IP);
                if (false !== $ip)
                {
                    return $ip;
                }
            }
        }

        // no valid ip found
        return false;
    }