com.aliyun.drc.utils.NetUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client Show documentation
Show all versions of client Show documentation
The core java client for accessing Data Transmission Service
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];
}
}