Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3909] add domain's judgement #3913

Merged
merged 6 commits into from
Oct 12, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void run() {
nacosIp = ApplicationUtils.getProperty(IP_ADDRESS);
}

if (!StringUtils.isBlank(nacosIp) && !isIP(nacosIp)) {
if (!StringUtils.isBlank(nacosIp) && !(isIP(nacosIp) || isDomain(nacosIp))) {
throw new RuntimeException("nacos address " + nacosIp + " is not ip");
}
String tmpSelfIp = nacosIp;
Expand Down Expand Up @@ -219,6 +219,26 @@ public static boolean isIP(String str) {
return matcher.matches();
}

/**
* juege str is right domain.
*
* @param str nacosIp
* @return nacosIp is domain
*/
public static boolean isDomain(String str) {
try {
String[] split = str.split(":");
horizonzy marked this conversation as resolved.
Show resolved Hide resolved
if (split.length != 2) {
return false;
}
Integer.parseInt(split[1]);
InetAddress address = InetAddress.getByName(split[0]);
return address.isReachable(100);
horizonzy marked this conversation as resolved.
Show resolved Hide resolved
} catch (Exception e) {
return false;
}
}

/**
* {@link com.alibaba.nacos.core.cluster.ServerMemberManager} is listener.
*/
Expand Down