Convert an IP to a long integer.
347322
function ip2long( a, b, c, d ) {
   for (
     c = b = 0;
     d = a.split('.')[b++];
     c +=
     d >> 8
     |
     b > 4 ?
     NaN
     :
     d * (1 << -8 * b)
     )
   d = parseInt(
     +d
     &&
     d
     );
   return c
   }
1189645
public long convertIPBytes(byte[] ipBytes) {
        if (ipBytes.length == 4) {
            long ipLong = (((long)ipBytes[0]) << 24);
            ipLong |= (((long)ipBytes[1]) << 16);
            ipLong |= (((long)ipBytes[2]) << 8);
            ipLong |= (long)ipBytes[3];
            return ipLong;
        }
        return -1;
    }
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
593584
public static Long convertToInt(RLPElement rpe) {
	Long result=0L;
	byte[] rawBytes=rpe.getRawData();
	if ((rawBytes!=null)) {
			// fill leading zeros
			if (rawBytes.length<EthereumUtil.INT_SIZE) {
				byte[] fullBytes=new byte[EthereumUtil.INT_SIZE];
				int dtDiff=EthereumUtil.INT_SIZE-rawBytes.length;
				for (int i=0;i<rawBytes.length;i++) {
					fullBytes[dtDiff+i]=rawBytes[i];
					result=(long) ByteBuffer.wrap(fullBytes).getInt()& 0x00000000ffffffffL;
				}
			} else {
				result=(long) ByteBuffer.wrap(rawBytes).getInt() & 0x00000000ffffffffL;
			}
	}
	return result;
}
706738
private Optional<Integer> longToInt(Optional<Long> optLong) {

        if (optLong.isPresent()) {
            return Optional.fromNullable((Integer.valueOf((int)optLong.get().longValue())));
        } else {
            return Optional.absent();
        }
    }
596667
public static int ipv4ToInt( final Inet4Address    addr )
    {
        int    value = 0;

        for( byte    chunk : addr.getAddress() )
        {
            value <<= 8;
            value |= chunk & 0xff;
        }

        return value;
    }
225953
def ipv6_to_str(ip):
    
    if isinstance(ip, numbers.Integral):
        return addrconv.ipv6.bin_to_text(type_desc.Int16.from_user(ip))
    else:
        return addrconv.ipv6.bin_to_text(ip)
759106
public static function IPv4toInteger($ip)
    {
        $ips = explode('.', $ip);
        $integer = 0;
        for ($i = 0; $i < 4; $i++)
        {
            $ips[$i] = intval($ips[$i] % 256);
            $ips[$i] = pow(256, 3 - $i) * intval($ips[$i]);
            $integer += $ips[$i];
        }
        return $integer;
    }
1310288
static byte[] validIpV4ToBytes(String ip) {
        int i;
        return new byte[] {
                ipv4WordToByte(ip, 0, i = ip.indexOf('.', 1)),
                ipv4WordToByte(ip, i + 1, i = ip.indexOf('.', i + 2)),
                ipv4WordToByte(ip, i + 1, i = ip.indexOf('.', i + 2)),
                ipv4WordToByte(ip, i + 1, ip.length())
        };
    }
891238
public static Long convertVarNumberToLong(RLPElement rpe) {
		Long result=0L;
		if (rpe.getRawData()!=null) {
			if (rpe.getRawData().length==0) {
				result=0L;
			} else
			if (rpe.getRawData().length<2) {
				result=(long) EthereumUtil.convertToByte(rpe);
			} else if (rpe.getRawData().length<3) {
				result = (long) EthereumUtil.convertToShort(rpe);
			} else if (rpe.getRawData().length<5) {
				result=(long) EthereumUtil.convertToInt(rpe);
			} else if (rpe.getRawData().length<9) {
				result=EthereumUtil.convertToLong(rpe);
			}
		}
		return result;
}
1305817
def next_ip(arg)
      octets = arg.split(/\./, 4).map(&:to_i)
      octets[3] += 1
      raise "out of ips!" if octets[3] > 255
      return octets.map(&:to_s).join(".")
    end
771699
def ip_in_subnet(ip, subnet):
    """"""
    ipaddr = int(''.join(['%02x' % int(x) for x in ip.split('.')]), 16)
    netstr, bits = subnet.split('/')
    netaddr = int(''.join(['%02x' % int(x) for x in netstr.split('.')]), 16)
    mask = (0xffffffff << (32 - int(bits))) & 0xffffffff
    return (ipaddr & mask) == (netaddr & mask)
745084
def obfuscate_ip(ip):
    
    if is_valid_ipv4(ip):
        res = "0x%s" % "".join(hex(int(x))[2:] for x in ip.split("."))
    else:
        raise ValueError('Invalid IP value %r' % ip)
    assert is_obfuscated_ip(res),  '%r obfuscation error' % res
    return res
866155
def _ipv4_text_to_int(self, ip_text):
        """"""
        if ip_text is None:
            return None
        assert isinstance(ip_text, str)
        return struct.unpack('!I', addrconv.ipv4.text_to_bin(ip_text))[0]
729073
public String convertIPBackToString(long ip) {
        StringBuffer sb = new StringBuffer(16);
        sb.append(Long.toString((ip >> 24)& 0xFF));
        sb.append('.');
        sb.append(Long.toString((ip >> 16)& 0xFF));
        sb.append('.');
        sb.append(Long.toString((ip >> 8) & 0xFF));
        sb.append('.');
        sb.append(Long.toString(ip & 0xFF));
        return sb.toString();
    }
301676
def i2osp(self, long_integer, block_size):
        ''
        hex_string = '%X' % long_integer
        if len(hex_string) > 2 * block_size:
            raise ValueError('integer %i too large to encode in %i octets' % (long_integer, block_size))
        return a2b_hex(hex_string.zfill(2 * block_size))
1281857
private static long bytesToLong(byte[] address) {
        long ipnum = 0;
        for (int i = 0; i < 4; ++i) {
            long y = address[i];
            if (y < 0) {
                y += 256;
            }
            ipnum += y << ((3 - i) * 8);
        }
        return ipnum;
    }