Java IP Address Get getLongIp(byte[] buff)

Here you can find the source of getLongIp(byte[] buff)

Description

get Long Ip

License

Open Source License

Declaration

public static long getLongIp(byte[] buff) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    public static long getLongIp(byte[] buff) {
        long ip;/*from   w  w w .j a v a 2s.c o m*/
        long workLong1, workLong2, workLong3, workLong4;

        workLong1 = (long) buff[0] & 0x000000FF;
        workLong1 = workLong1 << 24;
        workLong2 = (long) buff[1] & 0x000000FF;
        workLong2 = workLong2 << 16;
        workLong3 = (long) buff[2] & 0x000000FF;
        workLong3 = workLong3 << 8;
        workLong4 = (long) buff[3] & 0x000000FF;
        ip = workLong1 | workLong2 | workLong3 | workLong4;

        return ip;
    }

    public static long getLongIp(InetAddress host) {
        return getLongIp(host.getAddress());
    }

    public static long getLongIp(String ip) {
        try {
            return getLongIp(InetAddress.getByName(ip));
        } catch (UnknownHostException ex) {
            return 0;
        }
    }
}

Related

  1. getLocalIpv4()
  2. getLocalIPv6Address()
  3. getLocalNetWorkIp()
  4. getLocalV4Ip()
  5. getLocalV4IpList()
  6. getLongIp(String ipString)
  7. getPublicIP()
  8. getPublicIP()
  9. getPublicIP()