Get IP geolocation.

    Args:
        ip (str): IP address to use if no data provided.
        hit_api (bool): whether to hit api if info not found.

    Returns:
        str: latitude and longitude, comma-separated.
11291
def ip_geoloc(ip, hit_api=True):
    
    from ..logs.models import IPInfoCheck
    try:
        obj = IPInfoCheck.objects.get(ip_address=ip).ip_info
    except IPInfoCheck.DoesNotExist:
        if hit_api:
            try:
                obj = IPInfoCheck.check_ip(ip)
            except RateExceededError:
                return None
        else:
            return None
    return obj.latitude, obj.longitude
1152571
def get_self_ip():
        '''
        
        '''
        sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        try:
            sck.connect(('1.255.255.255', 1))  # Does not needs to be reachable
            ip_addr = sck.getsockname()[0]
        except Exception:
            ip_addr = socket.gethostbyname(socket.gethostname())
        finally:
            sck.close()
        return ip_addr
695568
async def _check_ip(self, addr):
        

        tasks = []
        for provider in self.providers:
            tasks.append(self.dnsbl_request(addr, provider))
        results = await asyncio.gather(*tasks)
        return DNSBLResult(addr=addr, results=results)
269578
def get_or_create_from_ip(ip):
        
        data = ip_api_handler.get(ip)
        if data and any(v for v in data.values()):
            if data.get('ip_address', None) is None or not data['ip_address']:
                data['ip_address'] = ip
            return IPInfo.objects.get_or_create(**data)
        return None, False
1271622
def get_user_ip(request):
    
    ip = get_real_ip(request)
    if ip is None:
        ip = get_ip(request)
        if ip is None:
            ip = '127.0.0.1'
    return ip
1152027
def fetch_host_ip_and_country(host: str) -> Tuple:
    
    ip = fetch_host_ip(host)
    if not host:
        return '', ''

    country = fetch_country_by_ip(ip)

    return ip, country
1109998
public static function is_iplocation($ip, $location)
	{
		$iplocation = false;
		if ($ip && $location)
		{
			if (!($gdb = self::getGeoDBO()))
			{
				return $iplocation;
			}

			$sql = "SELECT COUNT(*) FROM iplocation WHERE ipfrom <= INET_ATON(" . $gdb->quote($ip) . ") AND ipto >= INET_ATON(" . $gdb->quote($ip) . ") AND LOWER(location) = LOWER(" . $gdb->quote($location) . ")";
			$gdb->setQuery($sql);
			$c = $gdb->loadResult();
			if ($c > 0)
			{
				$iplocation = true;
			}
		}
		return $iplocation;
	}
161154
def get_by_ip(cls, ip):
        ''
        ret = cls.hosts_by_ip.get(ip)
        if ret is None:
            ret = cls.hosts_by_ip[ip] = [Host(ip)]
        return ret
1253320
def lookup_ips (ips):
    
    hosts = set()
    for ip in ips:
        try:
            hosts.add(socket.gethostbyaddr(ip)[0])
        except socket.error:
            hosts.add(ip)
    return hosts
1167100
def get_ip_address_from_request(request):
    
    PRIVATE_IPS_PREFIX = ('10.', '172.', '192.', '127.')
    ip_address = ''
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', '')
    if x_forwarded_for and ',' not in x_forwarded_for:
        if not x_forwarded_for.startswith(PRIVATE_IPS_PREFIX) and is_valid_ip(x_forwarded_for):
            ip_address = x_forwarded_for.strip()
    else:
        ips = [ip.strip() for ip in x_forwarded_for.split(',')]
        for ip in ips:
            if ip.startswith(PRIVATE_IPS_PREFIX):
                continue
            elif not is_valid_ip(ip):
                continue
            else:
                ip_address = ip
                break
    if not ip_address:
        x_real_ip = request.META.get('HTTP_X_REAL_IP', '')
        if x_real_ip:
            if not x_real_ip.startswith(PRIVATE_IPS_PREFIX) and is_valid_ip(x_real_ip):
                ip_address = x_real_ip.strip()
    if not ip_address:
        remote_addr = request.META.get('REMOTE_ADDR', '')
        if remote_addr:
            if not remote_addr.startswith(PRIVATE_IPS_PREFIX) and is_valid_ip(remote_addr):
                ip_address = remote_addr.strip()
            if remote_addr.startswith(PRIVATE_IPS_PREFIX) and is_valid_ip(remote_addr):
                ip_address = remote_addr.strip()
    if not ip_address:
            ip_address = '127.0.0.1'
    return ip_address
301952
def get_client_ip_address(request: HttpRequest) -> str:
    

    client_ip_address, _ = ipware.ip2.get_client_ip(
        request,
        proxy_order=settings.AXES_PROXY_ORDER,
        proxy_count=settings.AXES_PROXY_COUNT,
        proxy_trusted_ips=settings.AXES_PROXY_TRUSTED_IPS,
        request_header_order=settings.AXES_META_PRECEDENCE_ORDER,
    )

    return str(ip_address(client_ip_address))
915671
def _get(self, ip):
        
        # Geoloc updated up to once a week:
        # http://ipinfo.io/developers/data#geolocation-data
        retries = 10
        for retry in range(retries):
            try:
                response = requests.get('http://ipinfo.io/%s/json' % ip,
                                        verify=False, timeout=1)  # nosec
                if response.status_code == 429:
                    raise RateExceededError
                return response.json()
            except (requests.ReadTimeout, requests.ConnectTimeout):
                pass
        return {}
1045903
def google_maps_geoloc_link(data):
    
    if isinstance(data, str):
        lat_lon = ip_geoloc(data)
        if lat_lon is None:
            return ''
        lat, lon = lat_lon
    else:
        lat, lon = data
    loc = '%s,%s' % (lat, lon)
    return 'https://www.google.com/maps/place/@%s,17z/' \
           'data=!3m1!4b1!4m5!3m4!1s0x0:0x0!8m2!3d%s!4d%s' % (
            loc, lat, lon)
663154
def _get_ip_address(self, request):
        
        ipaddr = request.META.get("HTTP_X_FORWARDED_FOR", None)
        if ipaddr:
            # X_FORWARDED_FOR returns client1, proxy1, proxy2,...
            return ipaddr.split(",")[0].strip()
        return request.META.get("REMOTE_ADDR", "")
657328
def get_my_ip():
    """"""
    ip = subprocess.check_output(GET_IP_CMD, shell=True).decode('utf-8')[:-1]
    return ip.strip()
1070921
private GeoPoint getLocation() {

        //sample data
        //{"timestamp": 1483742439, "iss_position": {"latitude": "-50.8416", "longitude": "-41.2701"}, "message": "success"}

        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

        GeoPoint pt = null;
        if (isConnected) {
            try {
                JSONObject jsonObject = json.makeHttpRequest(url_select);
                JSONObject iss_position = (JSONObject) jsonObject.get("iss_position");
                double lat = iss_position.getDouble("latitude");
                double lon = iss_position.getDouble("longitude");
                //valid the data
                if (lat <= 90d && lat >= -90d && lon >= -180d && lon <= 180d) {
                    pt = new GeoPoint(lat, lon);
                } else
                    Log.e(TAG, "invalid lat,lon received");
            } catch (Throwable e) {
                Log.e(TAG, "error fetching json", e);
            }
        }
        return pt;
    }
889054
def detect(self):
        
        theip = find_ip(family=self.opts_family)
        self.set_current_value(theip)
        return theip