public class IpUtils extends Object
IP工具类集
2019-11-21 12:04
| 构造器和说明 |
|---|
IpUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
getIpByHost(String hostName)
通过域名获取IP地址
|
static Region |
getIpLocationByBinary(String ip)
获取指定IP地址的实际地理位置
使用 二进制搜索算法 算法 |
static Region |
getIpLocationByBtree(String ip)
获取指定IP地址的实际地理位置
使用 b-tree 算法 |
static Region |
getIpLocationByMemory(String ip)
获取指定IP地址的实际地理位置
使用内存搜索 memorySearch 算法 |
static InetAddress |
getLocalhost()
获取本机网卡的IP地址和计算机名
|
static String |
getLocalhostStr()
获取本机网卡IP地址,这个地址为所有网卡中非回路地址的第一个
如果获取失败调用 InetAddress.getLocalHost()方法获取。 |
static String |
hideIpPart(String ip)
隐藏掉IP地址的最后一部分,使用 * 代替
|
static boolean |
isInnerIp(String ip)
判断是否为内网IP
|
static boolean |
isUsableLocalPort(int port)
检测本地端口是否可用
|
static boolean |
isValidPort(int port)
是否为有效的端口
此方法并不检查端口是否被占用 有效端口是0~65535 |
public static String getIpByHost(String hostName)
hostName - 域名信息(注意不要加http或https,类似于cmd的ping命令)public static InetAddress getLocalhost()
public static String getLocalhostStr()
nullpublic static String hideIpPart(String ip)
ip - 需要操作的IP地址public static boolean isInnerIp(String ip)
ip - IP地址public static boolean isUsableLocalPort(int port)
port - 需要被检测的端口public static boolean isValidPort(int port)
port - 需要被检测的端口public static Region getIpLocationByMemory(String ip)
ip - 需要查询的IP地址信息public static Region getIpLocationByBtree(String ip)
ip - 需要查询的IP地址信息Copyright © 2020. All rights reserved.