Java IP Address to Long ipToLong(String ip)

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

Description

ip To Long

License

Apache License

Declaration

public static long ipToLong(String ip) throws UnknownHostException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    public static long ipToLong(String ip) throws UnknownHostException {
        byte[] address = InetAddress.getByName(ip).getAddress();
        long ipnum = 0;
        for (int i = 0; i < 4; ++i) {
            long y = address[i];
            if (y < 0) {
                y += 256;//www.j a  v a  2s  . c o m
            }
            ipnum += y << ((3 - i) * 8);
        }
        return ipnum;
    }
}

Related

  1. ipToLong(String addr)
  2. ipTolong(String address)
  3. ipToLong(String ip)
  4. ipToLong(String ip)
  5. ipToLong(String ip)
  6. ipToLong(String ip)
  7. ipToLong(String ipAddress)
  8. ipToLong(String ipAddress)
  9. ipToLong(String ipStr)