generated from mingliqiye/lib-tem
Compare commits
2 Commits
133fd1a77d
...
f645ffacdf
Author | SHA1 | Date | |
---|---|---|---|
f645ffacdf | |||
2a15ab653f |
@ -1,5 +1,5 @@
|
|||||||
GROUPSID=com.mingliqiye
|
GROUPSID=com.mingliqiye
|
||||||
ARTIFACTID=network-endpoint
|
ARTIFACTID=network-endpoint
|
||||||
VERSIONS=1.0.2
|
VERSIONS=1.0.3
|
||||||
MAINCLASS=com.mingliqiye
|
MAINCLASS=com.mingliqiye
|
||||||
JDKVERSIONS=1.8
|
JDKVERSIONS=1.8
|
||||||
|
@ -56,12 +56,14 @@ public class NetworkAddress implements Serializable {
|
|||||||
public static NetworkAddress of(String domip) {
|
public static NetworkAddress of(String domip) {
|
||||||
return new NetworkAddress(domip);
|
return new NetworkAddress(domip);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NetworkAddress of(InetAddress inetAddress) {
|
public static NetworkAddress of(InetAddress inetAddress) {
|
||||||
return new NetworkAddress(inetAddress.getHostAddress());
|
return new NetworkAddress(inetAddress.getHostAddress());
|
||||||
}
|
}
|
||||||
public InetAddress toInetAddress(){
|
|
||||||
|
public InetAddress toInetAddress() {
|
||||||
try {
|
try {
|
||||||
return InetAddress.getByName(domain);
|
return InetAddress.getByName(ip != null ? ip : domain);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -74,7 +76,8 @@ public class NetworkAddress implements Serializable {
|
|||||||
* @return IP地址
|
* @return IP地址
|
||||||
* @throws UnknownHostException 没找到对应的IP
|
* @throws UnknownHostException 没找到对应的IP
|
||||||
*/
|
*/
|
||||||
public static String getHostIp(@NotNull String domain) throws UnknownHostException {
|
public static String getHostIp(@NotNull String domain)
|
||||||
|
throws UnknownHostException {
|
||||||
InetAddress[] addresses = InetAddress.getAllByName(domain.trim());
|
InetAddress[] addresses = InetAddress.getAllByName(domain.trim());
|
||||||
return addresses[0].getHostAddress();
|
return addresses[0].getHostAddress();
|
||||||
}
|
}
|
||||||
@ -110,9 +113,10 @@ public class NetworkAddress implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return isdom?StringUtil.format("NetworkAddress(IP='{}',type='{}'," +
|
return isdom ? StringUtil.format(
|
||||||
"domain='{}')",ip,IPv,domain):
|
"NetworkAddress(IP='{}',type='{}'," + "domain='{}')", ip, IPv,
|
||||||
StringUtil.format("NetworkAddress(IP='{}',type='{}')",ip,IPv);
|
domain) :
|
||||||
|
StringUtil.format("NetworkAddress(IP='{}',type='{}')", ip, IPv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user