All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.drc.utils.NetUtils Maven / Gradle / Ivy

There is a newer version: 5.0.0.1-cloud.beta
Show newest version
package com.aliyun.drc.utils;

/**
 * Created by jianjundeng on 4/22/15.
 */
public class NetUtils {

    public static long ipToLong(String strIp){
        long[] ip = new long[4];
        //???IP??????.???
        int position1 = strIp.indexOf(".");
        int position2 = strIp.indexOf(".", position1 + 1);
        int position3 = strIp.indexOf(".", position2 + 1);
        //???.???????????
        ip[0] = Long.parseLong(strIp.substring(0, position1));
        ip[1] = Long.parseLong(strIp.substring(position1+1, position2));
        ip[2] = Long.parseLong(strIp.substring(position2+1, position3));
        ip[3] = Long.parseLong(strIp.substring(position3+1));
        return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy