Java InetAddress from ipToLong(InetAddress ip)

Here you can find the source of ipToLong(InetAddress ip)

Description

ip To Long

License

Open Source License

Declaration

public static long ipToLong(InetAddress ip) 

Method Source Code

//package com.java2s;

import java.net.InetAddress;

public class Main {
    public static long ipToLong(InetAddress ip) {
        byte[] octets = ip.getAddress();
        long result = 0;
        for (byte octet : octets) {
            result <<= 8;//from  w  w w  .j  av a2  s  .co m
            result |= octet & 0xff;
        }
        return result;
    }
}

Related

  1. int2InetAddress(int val)
  2. IntegerToInetAddress(int ipAddress)
  3. intToInetAddress(int i)
  4. ip2Long(InetAddress ip)
  5. ipToBytesByInetAddress(String ip)
  6. long2InetAddress(long val)
  7. toInetAddress(String host)