Checks to see if an IP address is used for local communications within
    a private network as specified by RFC 1918
427013
def is_rfc1918(ip):
    
    if ip_between(ip, "10.0.0.0", "10.255.255.255"):
        return True
    elif ip_between(ip, "172.16.0.0", "172.31.255.255"):
        return True
    elif ip_between(ip, "192.168.0.0", "192.168.255.255"):
        return True
    else:
        return False
482761
def subintf_real_ip_check_gw_port(self, gw_port, ip_addr, netmask):
        
        if gw_port is not None:
            found = False
            for i in range(len(gw_port['fixed_ips'])):
                target_ip = gw_port['fixed_ips'][i]['ip_address']
                if ip_addr == target_ip:
                    found = True
                    break
            if found is False:
                LOG.info("Subintf real IP is incorrect, deleting")
                return False
            subnet_id = gw_port['fixed_ips'][i]['subnet_id']
            subnet = next(
                sn for sn in gw_port['subnets'] if sn['id'] == subnet_id)
            target_net = netaddr.IPNetwork(subnet['cidr'])
            if netmask != str(target_net.netmask):
                LOG.info("Subintf has incorrect netmask, deleting")
                return False

            return True

        return False
937062
private boolean isIPAddress(@Nonnull String address) {
        return (InetAddressUtils.isIPv4Address(address) || InetAddressUtils.isIPv6Address(address));
    }
1212429
def is_ip(address):
    
    try:
        # Test to see if already an IPv4/IPv6 address
        address = netaddr.IPAddress(address)
        return True
    except (netaddr.AddrFormatError, ValueError):
        return False
1155302
def is_global(self):
        
        return (not (self.network_address in IPv4Network('100.64.0.0/10') and
                self.broadcast_address in IPv4Network('100.64.0.0/10')) and
                not self.is_private)
1214244
def is_private(self):
        
        private_10 = IPv4Network('10.0.0.0/8')
        private_172 = IPv4Network('172.16.0.0/12')
        private_192 = IPv4Network('192.168.0.0/16')
        return (self in private_10 or
                self in private_172 or
                self in private_192)
231824
def check_obfuscated_ip (self):
        """"""
        # check if self.host can be an IP address
        # check for obfuscated IP address
        if iputil.is_obfuscated_ip(self.host):
            ips = iputil.resolve_host(self.host)
            if ips:
                self.host = ips[0]
                self.add_warning(
                   _("URL %(url)s has obfuscated IP address %(ip)s") % \
                   {"url": self.base_url, "ip": ips[0]},
                          tag=WARN_URL_OBFUSCATED_IP)
304339
def resolve_network_cidr(ip_address):
    '''
    
    '''
    netmask = get_netmask_for_address(ip_address)
    return str(netaddr.IPNetwork("%s/%s" % (ip_address, netmask)).cidr)
370335
private static boolean mayBeIPv6Address(String input) {
        if (input == null) {
            return false;
        }

        boolean result = false;
        int colonsCounter = 0;
        int length = input.length();
        for (int i = 0; i < length; i++) {
            char c = input.charAt(i);
            if (c == '.' || c == '%') {
                // IPv4 in IPv6 or Zone ID detected, end of checking.
                break;
            }
            if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')
                    || (c >= 'A' && c <= 'F') || c == ':')) {
                return false;
            } else if (c == ':') {
                colonsCounter++;
            }
        }
        if (colonsCounter >= 2) {
            result = true;
        }
        return result;
    }
149445
def is_reserved(ip):
    
    if ip_between(ip, "0.0.0.0", "0.255.255.255"):
        return True
    elif ip_between(ip, "10.0.0.0", "10.255.255.255"):
        return True
    elif ip_between(ip, "100.64.0.0", "100.127.255.255"):
        return True
    elif ip_between(ip, "127.0.0.0", "127.255.255.255"):
        return True
    elif ip_between(ip, "169.254.0.0", "169.254.255.255"):
        return True
    elif ip_between(ip, "172.16.0.0", "172.31.255.255"):
        return True
    elif ip_between(ip, "192.0.0.0", "192.0.0.255"):
        return True
    elif ip_between(ip, "192.0.2.0", "192.0.2.255"):
        return True
    elif ip_between(ip, "192.88.99.0", "192.88.99.255"):
        return True
    elif ip_between(ip, "192.168.0.0", "192.168.255.255"):
        return True
    elif ip_between(ip, "198.18.0.0", "198.19.255.255"):
        return True
    elif ip_between(ip, "198.51.100.0", "198.51.100.255"):
        return True
    elif ip_between(ip, "203.0.113.0", "203.0.113.255"):
        return True
    elif ip_between(ip, "224.0.0.0", "255.255.255.255"):
        return True
    else:
        return False
1233026
def is_public_ip(ip):
    '''
    
    '''
    if ':' in ip:
        # ipv6
        if ip.startswith('fe80:'):
            # ipv6 link local
            return False
        return True
    addr = ip_to_int(ip)
    if 167772160 < addr < 184549375:
        # 10.0.0.0/8
        return False
    elif 3232235520 < addr < 3232301055:
        # 192.168.0.0/16
        return False
    elif 2886729728 < addr < 2887778303:
        # 172.16.0.0/12
        return False
    elif 2130706432 < addr < 2147483647:
        # 127.0.0.0/8
        return False
    return True
1015697
private function isLocalIp ()
    {
        $ip = $this->serverData["REMOTE_ADDR"];

        if (!is_string($ip))
        {
            return false;
        }

        if (in_array($ip, ['127.0.0.1', 'fe80::1', '::1'], true))
        {
            return true;
        }

        // allowed (= local) IPs include
        // 10.0.0.0 – 10.255.255.255
        // 172.16.0.0 – 172.31.255.255
        // 192.168.0.0 – 192.168.255.255
        return 1 === preg_match("/^(10\\.|192\\.168\\.|172\\.(1[6-9]|2[0-9]|3[0-1])\\.)/", $ip);
    }
1187191
def is_reserved(self):
        
        reserved_nets = [IPv6Network(u'::/8'), IPv6Network(u'100::/8'),
                         IPv6Network(u'200::/7'), IPv6Network(u'400::/6'),
                         IPv6Network(u'800::/5'), IPv6Network(u'1000::/4'),
                         IPv6Network(u'4000::/3'), IPv6Network(u'6000::/3'),
                         IPv6Network(u'8000::/3'), IPv6Network(u'A000::/3'),
                         IPv6Network(u'C000::/3'), IPv6Network(u'E000::/4'),
                         IPv6Network(u'F000::/5'), IPv6Network(u'F800::/6'),
                         IPv6Network(u'FE00::/9')]

        return any(self in x for x in reserved_nets)
834234
def is_reserved_ip(self, ip):
        
        theip = ipaddress(ip)
        for res in self._reserved_netmasks:
            if theip in ipnetwork(res):
                return True
        return False
333923
def ip(self):
        """"""
        r = ''

        # this was compiled from here:
        # https://github.com/un33k/django-ipware
        # http://www.ietf.org/rfc/rfc3330.txt (IPv4)
        # http://www.ietf.org/rfc/rfc5156.txt (IPv6)
        # https://en.wikipedia.org/wiki/Reserved_IP_addresses
        format_regex = re.compile(r'\s')
        ip_regex = re.compile(r'^(?:{})'.format(r'|'.join([
            r'0\.', # reserved for 'self-identification'
            r'10\.', # class A
            r'169\.254', # link local block
            r'172\.(?:1[6-9]|2[0-9]|3[0-1])\.', # class B
            r'192\.0\.2\.', # documentation/examples
            r'192\.168', # class C
            r'255\.{3}', # broadcast address
            r'2001\:db8', # documentation/examples
            r'fc00\:', # private
            r'fe80\:', # link local unicast
            r'ff00\:', # multicast
            r'127\.', # localhost
            r'\:\:1' # localhost
        ])))

        ips = self.ips
        for ip in ips:
            if not format_regex.search(ip) and not ip_regex.match(ip):
                r = ip
                break

        return r
1202376
public boolean isPrivate() {
		// refer to RFC 1918
        // 10/8 prefix
        // 172.16/12 prefix (172.16.0.0 – 172.31.255.255)
        // 192.168/16 prefix
		IPv4AddressSegment seg0 = getSegment(0);
		IPv4AddressSegment seg1 = getSegment(1);
		return seg0.matches(10)
			|| seg0.matches(172) && seg1.matchesWithPrefixMask(16, 4)
			|| seg0.matches(192) && seg1.matches(168);
	}
469868
def is_reserved(self):
        
        reserved_nets = [IPv6Network('::/8'), IPv6Network('100::/8'),
                         IPv6Network('200::/7'), IPv6Network('400::/6'),
                         IPv6Network('800::/5'), IPv6Network('1000::/4'),
                         IPv6Network('4000::/3'), IPv6Network('6000::/3'),
                         IPv6Network('8000::/3'), IPv6Network('A000::/3'),
                         IPv6Network('C000::/3'), IPv6Network('E000::/4'),
                         IPv6Network('F000::/5'), IPv6Network('F800::/6'),
                         IPv6Network('FE00::/9')]

        return any(self in x for x in reserved_nets)