当前位置:网站首页>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;
}
}
}
边栏推荐
- cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
- 实训九 网络服务的基本配置
- 杰理之关于 TWS 配对方式配置【篇】
- [HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
- 2022.07.02
- Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
- The research group of the Hunan Organizing Committee of the 24th China Association for science and technology visited Kirin Xin'an
- 杰理之开机自动配对【篇】
- How to estimate the value of "not selling pens" Chenguang?
- Pasqal首席技术官:模拟量子计算率先为工业带来量子优势
猜你喜欢
# 欢迎使用Markdown编辑器
Kirin Xin'an cloud platform is newly upgraded!
Numpy——2.数组的形状
Business experience in virtual digital human
How to estimate the value of "not selling pens" Chenguang?
Seize Jay Chou
5billion, another master fund was born in Fujian
Install mysql8 for Linux X ultra detailed graphic tutorial
How to share the same storage among multiple kubernetes clusters
Zhong Xuegao wants to remain innocent in the world
随机推荐
Chief technology officer of Pasqual: analog quantum computing takes the lead in bringing quantum advantages to industry
杰理之开机自动配对【篇】
Command mode - unity
Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
索引总结(突击版本)
Numpy——axis
Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
杰理之相同声道的耳机不允许配对【篇】
The top of slashdata developer tool is up to you!!!
2022年投资哪个理财产品收益高?
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
LeetCode 890(C#)
5billion, another master fund was born in Fujian
谷歌seo外链Backlinks研究工具推荐
Seize Jay Chou
Teach your sister to write the message queue hand in hand
Version 2.0 of tapdata, the open source live data platform, has been released
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线