当前位置:网站首页>IP tools
IP tools
2022-07-07 19:39:00 【Scarecrow 0.0】
public class IPUtils {
public IPUtils() {
}
public static String convertIPToString(long ipLong) {
if (ipLong < 0L) {
ipLong += 4294967296L;
}
StringBuilder builder = new StringBuilder(15);
builder.append(ipLong >> 24);
builder.append('.');
builder.append((ipLong & 16777215L) >> 16);
builder.append('.');
builder.append((ipLong & 65535L) >> 8);
builder.append('.');
builder.append(ipLong & 255L);
return builder.toString();
}
public static Long convertIPToLong(String ipAddr, Long defaultValue) {
try {
return convertIPToLong(ipAddr);
} catch (IllegalArgumentException var3) {
return defaultValue;
}
}
public static long convertIPToLong(String ipAddr) throws IllegalArgumentException {
if (ipAddr != null && isIPAddr(ipAddr)) {
String[] ips = ipAddr.split("\\.");
long ipLong = 0L;
ipLong += Long.parseLong(ips[0]) << 24;
ipLong += Long.parseLong(ips[1]) << 16;
ipLong += Long.parseLong(ips[2]) << 8;
ipLong += Long.parseLong(ips[3]);
return ipLong;
} else {
throw new IllegalArgumentException("`" + ipAddr + "` is not a valid IP address!");
}
}
public static Integer convertIPToInt(String ipAddr, Integer defaultValue) {
try {
return convertIPToInt(ipAddr);
} catch (IllegalArgumentException var3) {
return defaultValue;
}
}
public static int convertIPToInt(String ipAddr) {
long ipVal = convertIPToLong(ipAddr);
if (ipVal > 2147483647L) {
ipVal -= 4294967296L;
}
return Long.valueOf(ipVal).intValue();
}
public static boolean isIPAddr(String addr) {
if (addr != null && addr.trim().length() != 0) {
String[] ips = addr.split("\\.");
if (ips.length != 4) {
return false;
} else {
try {
int ipa = Integer.parseInt(ips[0]);
int ipb = Integer.parseInt(ips[1]);
int ipc = Integer.parseInt(ips[2]);
int ipd = Integer.parseInt(ips[3]);
return ipa >= 0 && ipa <= 255 && ipb >= 0 && ipb <= 255 && ipc >= 0 && ipc <= 255 && ipd >= 0 && ipd <= 255;
} catch (NumberFormatException var6) {
return false;
}
}
} else {
return false;
}
}
}
边栏推荐
- 编译原理 实验一:词法分析器的自动实现(Lex词法分析)
- [RT thread env tool installation]
- PMP practice once a day | don't get lost in the exam -7.7
- 杰理之手动配对方式【篇】
- CMD command enters MySQL times service name or command error (fool teaching)
- el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
- 一张图深入的理解FP/FN/Precision/Recall
- Redis master-slave and sentinel master-slave switchover are built step by step
- The top of slashdata developer tool is up to you!!!
- How to share the same storage among multiple kubernetes clusters
猜你喜欢
网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
杰理之相同声道的耳机不允许配对【篇】
Micro service remote debug, nocalhost + rainbow micro service development second bullet
项目经理『面试八问』,看了等于会了
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
State mode - Unity (finite state machine)
Business experience in virtual digital human
Responsibility chain model - unity
cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
博睿数据入选《2022爱分析 · IT运维厂商全景报告》
随机推荐
浏览积分设置的目的
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
2022.07.02
Numpy——2. Shape of array
String - string (Lua)
炒股如何开户?请问一下手机开户股票开户安全吗?
编译原理 实验一:词法分析器的自动实现(Lex词法分析)
注解。。。
648. 单词替换
指定opencv非标准安装的版本
R语言ggplot2可视化:使用ggpubr包的ggecdf函数可视化分组经验累积密度分布函数曲线、linetype参数指定不同分组曲线的线型
The top of slashdata developer tool is up to you!!!
【Confluence】JVM内存调整
Big Ben (Lua)
Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
2022.07.05
[mime notes]
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
项目经理『面试八问』,看了等于会了
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix