" binary search method
        " param: ip
173272
def binarySearch(self, ip):
        
        if not ip.isdigit(): ip = self.ip2Long(ip)

        if self.__indexLen < 1:
            self.__f.seek(0)
            b = self.__f.read(8)
            self.__sPtr = self.getLong(b, 0)
            endPtr      = self.getLong(b, 4)
            self.__indexLen = endPtr - self.__sPtr

        startPtr = self.__sPtr
        indexLen = self.__indexLen

        self.__f.seek(startPtr)
        b = self.__f.read(indexLen+12)

        l, h, mixPtr = (0, int(indexLen/12), 0)
        while l <= h:
            m   = int((l+h)/2)
            ptr = startPtr + m*12
            self.__f.seek(ptr)

            b   = self.__f.read(12)
            sip = self.getLong(b, 0)
            eip = self.getLong(b, 4)

            if ip >= sip:
                if ip > eip:
                    l = m + 1
                else:
                    mixPtr = self.getLong(b, 8)
                    break;
            else:
                h = m - 1

        if mixPtr == 0: return "N2"

        return self.returnData(mixPtr)
1235999
function isIPv4(val) {
  // It will accept anything with three dots (.) and numeric digits
  const ipv4Regex = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
  if (!ipv4Regex.test(val)) {
    return false;
  }
  // This part of code do checking for any invalid IP address like 256.256.256.256
  var parts = val.split('.').sort(function (a, b) {
    return a - b;
  });
  return parts[3] <= 255;
}
102219
def _check_ip(ip: str) -> bool:
    
    address = ipaddress.IPv4Address(ip)
    return address in allowed_ips
261793
def maybe_ip_addr(addr):
    

    if six.PY2 and isinstance(addr, str):
        addr = unicode(addr)  # noqa
    try:
        return ipaddress.ip_address(addr)
    except ValueError:
        pass
    return str(addr)
1371022
int binarySearch(int fromIndex, int toIndex, long key, long value) {
		if (ind.isUnique()) {
			return binarySearchUnique(fromIndex, toIndex, key);
		}
		return binarySearchNonUnique(fromIndex, toIndex, key, value);
	}
1340875
def _get_ipv6_from_binary(self, bin_addr):
        """"""

        hi = bin_addr >> 64
        lo = bin_addr & 0xFFFFFFFF
        return socket.inet_ntop(socket.AF_INET6, struct.pack("!QQ", hi, lo))
221457
function pton4(addr, dest, index = 0) {
  if (typeof addr !== 'string') {
    throw new TypeError('Argument 1 should be a string.')
  }

  if (arguments.length >= 3) {
    if (typeof index !== 'number') {
      throw new TypeError('Argument 3 should be a Number.')
    }
  }

  const isbuffer = Buffer.isBuffer(dest)

  if (isbuffer) {
    if (index + IPV4_OCTETS > dest.length) {
      throw new Error('Too small target buffer.')
    }
  }

  const buf = isbuffer ? dest : Buffer.allocUnsafe(IPV4_OCTETS)

  let octets = 0
  let sawDigit = false
  let number = 0

  for (let i = 0; i < addr.length; ++i) {
    const char = code(addr[i])

    if (isDigit(char)) {
      number = (number * 10) + (char - CHAR0)

      if (sawDigit && number === 0) {
        einval()
      }

      if (number > 0xFF) {
        einval()
      }

      if (!sawDigit) {
        if (++octets > IPV4_OCTETS) {
          einval()
        }
        sawDigit = true
      }
    } else if (char === CHARPOINT && sawDigit) {
      if (octets === IPV4_OCTETS) {
        einval()
      }

      buf[index++] = number
      number = 0
      sawDigit = false
    } else {
      einval()
    }
  }

  if (octets < IPV4_OCTETS) {
    einval()
  }

  if (sawDigit) {
    buf[index] = number
  }

  return buf
}
356458
def _get_binary_from_ipv4(self, ip_addr):
        """"""

        return struct.unpack("!L", socket.inet_pton(socket.AF_INET,
                                                    ip_addr))[0]
1299837
def qs_for_ip(cls, ip_str):
        
        ip = int(netaddr.IPAddress(ip_str))

        # ignore IPv6 addresses for now (4294967295 is 0xffffffff, aka the
        # biggest 32-bit number)
        if ip > 4294967295:
            return cls.objects.none()

        ip_range_query = {
            'start__lte': ip,
            'stop__gte': ip
        }

        return cls.objects.filter(**ip_range_query)
877573
def matches_ip(self, ip):
        """"""

        # Check the cache if caching is enabled
        if self.cache is not None:
            matches_ip = self.cache.get(ip)
            if matches_ip is not None:
                return matches_ip

        # Query MongoDB to see if the IP is blacklisted
        matches_ip = IPNetwork.matches_ip(
            ip, read_preference=self.read_preference)

        # Cache the result if caching is enabled
        if self.cache is not None:
            self.cache[ip] = matches_ip

        return matches_ip
779472
def __phpot_decoder(ip)
			octets = ip.split(/\./)
			if octets.length != 4 or octets[0] != "127"
				return "invalid response"
			elsif octets[3] == "0"
				search_engines = ["undocumented", "AltaVista", "Ask", "Baidu", "Excite", "Google", "Looksmart", "Lycos", "MSN", "Yahoo", "Cuil", "InfoSeek", "Miscellaneous"]
				sindex = octets[2].to_i
				if sindex >= search_engines.length
					return "type=search engine,engine=unknown"
				else
					return "type=search engine,engine=#{search_engines[sindex]}"
				end
			else
				days, threatscore, flags = octets[1,3]
				flags = flags.to_i
				types = []
				if (flags & 0x1) == 0x1
					types << "suspicious"
				end
				if (flags & 0x2) == 0x2
					types << "harvester"
				end
				if (flags & 0x4) == 0x4
					types << "comment spammer"
				end
				if (flags & 0xf8) > 0
					types << "reserved"
				end
				type = types.join(",")
				return "days=#{days},score=#{threatscore},type=#{type}"
			end
		end
334675
def is_binary_address(value: Any) -> bool:
    
    if not is_bytes(value):
        return False
    elif len(value) != 20:
        return False
    else:
        return True
391716
def _is_ipv4(self, ip):
        
        try:
            p = IPy.IP(ip)
        except ValueError:
            return False

        if p.version() == 4:
            return True
        return False
73213
def binary(self, url, timeout=None):
        
        response = self.get_response(url, timeout=timeout)
        if response:
            return response.content
        else:
            return None
96425
def ip(ip_addr, return_tuple=True):
    
    regex_ip = __re.compile("^((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))$")
    if return_tuple:
        while not regex_ip.match(ip_addr):
            print("Not a good IP.")
            print("Please try again.")
            ip_addr = input("Please enter a IP address in the following format x.x.x.x: ")
        return ip_addr
    elif not return_tuple:
        if not regex_ip.match(ip_addr):
            return False
        else:
            return True
924898
def iphexval(ip):
    '''
    
    '''
    a = ip.split('.')
    hexval = ['%02X' % int(x) for x in a]  # pylint: disable=E1321
    return ''.join(hexval)
936315
def normalize_ip(ip)
      case ip
      when nil then nil
      when String then IPAddr.new(ip)
      when Integer then IPAddr.new(ip, Socket::AF_INET)
      when IPAddr then ip
      else raise ArgumentError, "IP must be a String, IPAddr, or Integer, not: #{ip.inspect}"
      end
    end