Java IP Address Convert To convertIp(String ip)

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

Description

convert Ip

License

Apache License

Declaration

public static String convertIp(String ip) 

Method Source Code

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

public class Main {

    public static String convertIp(String ip) {
        String[] iplist = ip.split("\\.");
        int ip0 = Integer.parseInt(iplist[0]);
        int ip1 = Integer.parseInt(iplist[1]);
        int ip2 = Integer.parseInt(iplist[2]);
        int ip3 = Integer.parseInt(iplist[3]);
        String result = Integer.toHexString((ip0 << 24) + (ip1 << 16) + (ip2 << 8) + ip3);
        for (int i = result.length(); i < 8; i++) {
            result = '0' + result;
        }//from w  w  w .ja v  a  2s.  co m
        return result;
    }
}

Related

  1. convertIP6Address(byte[] bytes)
  2. convertIPAdressToBytes(String ip)
  3. convertIpPortToUniqueId(byte[] quad, int port)
  4. convertIpv4Address(String ip)