Helper method to check if the remote real ip of a request is in a network
424606
def is_requestaddress_in_networks(request, networks):
    """"""
    from ipware.ip import get_real_ip, get_ip

    # Get the real IP, i.e. no reverse proxy, no nginx
    ip = get_real_ip(request)
    if not ip:
        ip = get_ip(request)
        if not ip:
            return False

    # For all networks
    for network in networks:
        if is_address_in_network(ip, network):
            return True

    return False
102219
def _check_ip(ip: str) -> bool:
    
    address = ipaddress.IPv4Address(ip)
    return address in allowed_ips
391716
def _is_ipv4(self, ip):
        
        try:
            p = IPy.IP(ip)
        except ValueError:
            return False

        if p.version() == 4:
            return True
        return False
653015
def remote_addr(self):
        
        if not hasattr(self, "_remote_addr"):
            if self.app.config.PROXIES_COUNT == 0:
                self._remote_addr = ""
            elif self.app.config.REAL_IP_HEADER and self.headers.get(
                self.app.config.REAL_IP_HEADER
            ):
                self._remote_addr = self.headers[
                    self.app.config.REAL_IP_HEADER
                ]
            elif self.app.config.FORWARDED_FOR_HEADER:
                forwarded_for = self.headers.get(
                    self.app.config.FORWARDED_FOR_HEADER, ""
                ).split(",")
                remote_addrs = [
                    addr
                    for addr in [addr.strip() for addr in forwarded_for]
                    if addr
                ]
                if self.app.config.PROXIES_COUNT == -1:
                    self._remote_addr = remote_addrs[0]
                elif len(remote_addrs) >= self.app.config.PROXIES_COUNT:
                    self._remote_addr = remote_addrs[
                        -self.app.config.PROXIES_COUNT
                    ]
                else:
                    self._remote_addr = ""
            else:
                self._remote_addr = ""
        return self._remote_addr
1158821
def hasIP(self, ip):
        """"""

        for f in self.features:
            if (f.prop.startswith("net_interface.") and
                    f.prop.endswith(".ip") and f.value == ip):
                return True
        return False
678430
public String remoteIP(){
        String remoteAddr = request.getRemoteAddr();
        
        // This could be a list of proxy IPs, which the developer could
        // provide via some configuration
        if ("127.0.0.1".equals(remoteAddr)) remoteAddr = requestHeader("X-Forwarded-For");
        return remoteAddr;
    }
888877
def is_ip_filter(ip, options=None):
    '''
    
    '''
    return is_ipv4_filter(ip, options=options) or is_ipv6_filter(ip, options=options)
901833
def is_ip(string):
    
    mo = re.match(r'(\d+)\.(\d+)\.(\d+)\.(\d+)', string)
    if mo is None:
        return False
    for group in mo.groups():
        if int(group) not in list(range(0, 256)):
            return False
    return True
1185399
def is_address_in_network(ip, net):
    """"""
    # http://stackoverflow.com/questions/819355/how-can-i-check-if-an-ip-is-in-a-network-in-python
    import socket
    import struct
    ipaddr = struct.unpack('=L', socket.inet_aton(ip))[0]
    netaddr, bits = net.split('/')
    if int(bits) == 0:
        return True
    net = struct.unpack('=L', socket.inet_aton(netaddr))[0]

    mask = ((2L << int(bits) - 1) - 1)

    return (ipaddr & mask) == (net & mask)
1068855
async def get_real_ext_ip(self):
        """"""
        while self._ip_hosts:
            try:
                timeout = aiohttp.ClientTimeout(total=self._timeout)
                async with aiohttp.ClientSession(
                    timeout=timeout, loop=self._loop
                ) as session, session.get(self._pop_random_ip_host()) as resp:
                    ip = await resp.text()
            except asyncio.TimeoutError:
                pass
            else:
                ip = ip.strip()
                if self.host_is_ip(ip):
                    log.debug('Real external IP: %s', ip)
                    break
        else:
            raise RuntimeError('Could not get the external IP')
        return ip
1138462
def show_network_ip_availability(self, network, **_params):
        """"""
        return self.get(self.network_ip_availability_path % (network),
                        params=_params)
803541
def check_ip(ip, log=False):
        """"""
        if log:
            print('Checking ip: {}...'.format(ip))

        request_timeout = 0.1

        try:
            tv_url = 'http://{}:6095/request?action=isalive'.format(ip)
            request = requests.get(tv_url, timeout=request_timeout)
        except requests.exceptions.ConnectTimeout:
            return False

        return request.status_code == 200
1259435
def in_subnet(cidr, addrs=None):
    
    for address in addrs:
        if ip_in_subnet(address, cidr):
            return True
    return False
239794
def dshield_ip_check(ip):
    """"""
    if not is_IPv4Address(ip):
        return None

    headers = {'User-Agent': useragent}
    url = 'https://isc.sans.edu/api/ip/'
    response = requests.get('{0}{1}?json'.format(url, ip), headers=headers)
    return response.json()
1320912
function DetectLocalIPAddress(callback) {
            if (!DetectRTC.isWebRTCSupported) {
                return;
            }

            if (DetectRTC.isORTCSupported) {
                return;
            }

            getIPs(function(ip) {
                //local IPs
                if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/)) {
                    callback('Local: ' + ip);
                }

                //assume the rest are public IPs
                else {
                    callback('Public: ' + ip);
                }
            });
        }
889054
def detect(self):
        
        theip = find_ip(family=self.opts_family)
        self.set_current_value(theip)
        return theip
1327589
def is_internet_available(ips=CONNECTION_IPS, timeout=1.0):
    

    while ips:
        try:
            urllib2.urlopen("http://{0}".format(ips.pop(0)), timeout=timeout)
            return True
        except IndexError as error:
            continue
        except (urllib2.URLError, socket.error) as error:
            continue
    return False