当前位置:网站首页>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;
}
}
}
边栏推荐
- [RT thread env tool installation]
- PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
- Install mysql8 for Linux X ultra detailed graphic tutorial
- Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
- Borui data was selected in the 2022 love analysis - Panoramic report of it operation and maintenance manufacturers
- 杰理之相同声道的耳机不允许配对【篇】
- 一张图深入的理解FP/FN/Precision/Recall
- 超分辨率技术在实时音视频领域的研究与实践
- tp6 实现佣金排行榜
- Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
猜你喜欢

杰理之测试盒配置声道【篇】
![[tpm2.0 principle and Application guide] Chapter 9, 10 and 11](/img/7f/0d4d91142bc3d79ea445a8f64afba7.png)
[tpm2.0 principle and Application guide] Chapter 9, 10 and 11

Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
让这个 CRMEB 单商户微信商城系统火起来,太好用了!

2022.07.02

爬虫实战(七):爬王者英雄图片

el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。

Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)

Kirin Xin'an cloud platform is newly upgraded!

博睿数据入选《2022爱分析 · IT运维厂商全景报告》
随机推荐
PV static creation and dynamic creation
爬虫实战(七):爬王者英雄图片
[tpm2.0 principle and Application guide] Chapter 9, 10 and 11
testing and SQA_ Dynamic white box test [easy to understand]
The top of slashdata developer tool is up to you!!!
MySQL、sqlserver oracle数据库连接方式
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置position参数配置不同分组数据点的分离程度
How to estimate the value of "not selling pens" Chenguang?
Initial experience of cache and ehcache "suggestions collection"
Flipping game (enumeration)
指定opencv非标准安装的版本
Key points of anti reptile: identifying reptiles
解决rosdep的报错问题
LeetCode 515(C#)
ant desgin 多选
what‘s the meaning of inference
吞吐量Throughout
杰理之关于 TWS 交叉配对的配置【篇】
Zhong Xuegao wants to remain innocent in the world
时间工具类