Java Long to IP Address longToIPv4(final long ipaddress)

Here you can find the source of longToIPv4(final long ipaddress)

Description

Convert a long to an IP Address, as four dotted octets.

License

Open Source License

Parameter

Parameter Description
ipaddress a parameter

Return

String

Declaration


public static String longToIPv4(final long ipaddress) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

public class Main {
    /***********************************************************************************************
     * Convert a long to an IP Address, as four dotted octets.
     */* ww  w . ja v a2 s  . c  o  m*/
     * @param ipaddress
     *
     * @return String
     */

    public static String longToIPv4(final long ipaddress) {
        final String SOURCE = "NetworkScannerHelper.longToIPv4() ";
        final int octet1;
        final int octet2;
        final int octet3;
        final int octet4;
        final String strIP;

        //LOGGER.logTimedEvent(SOURCE + "Long [address=" + ipaddress + "]");

        octet1 = (int) ((ipaddress & 0x00000000FF000000L) >>> 24);
        octet2 = (int) ((ipaddress & 0x0000000000FF0000L) >>> 16);
        octet3 = (int) ((ipaddress & 0x000000000000FF00L) >>> 8);
        octet4 = (int) (ipaddress & 0x00000000000000FFL);

        strIP = String.valueOf(octet1) + "." + octet2 + "." + octet3 + "." + octet4;

        //LOGGER.logTimedEvent(SOURCE + "String [address=" + strIP + "]");

        return (strIP);
    }
}

Related

  1. longToIp(long ip)
  2. LongToIp(long longIp)
  3. longToIp(long longValue)
  4. longToIp(String ip)
  5. longToIpAddress(long ip)
  6. longToIpV4(long ip)
  7. longToIpV4(long longIp)
  8. longToIpV4(long longIp)
  9. longToIpV6(long highBits, long lowBits)