|
|
|
@ -1,13 +1,23 @@
|
|
|
|
|
package com.alibaba.cloud.nacos.intetuntil;
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2013-2018 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.springframework.cloud.commons.util.InetUtils;
|
|
|
|
|
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
|
|
|
|
package com.alibaba.cloud.nacos.intetuntil;
|
|
|
|
|
|
|
|
|
|
import java.io.Closeable;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
import java.net.Inet6Address;
|
|
|
|
|
import java.net.InetAddress;
|
|
|
|
|
import java.net.NetworkInterface;
|
|
|
|
@ -19,10 +29,17 @@ import java.util.concurrent.Executors;
|
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
|
|
import org.springframework.cloud.commons.util.InetUtils;
|
|
|
|
|
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author HH
|
|
|
|
|
*/
|
|
|
|
|
public class InetIPv6Utils implements Closeable {
|
|
|
|
|
|
|
|
|
|
private final ExecutorService executorService;
|
|
|
|
|
|
|
|
|
|
private final Log log = LogFactory.getLog(InetIPv6Utils.class);
|
|
|
|
@ -47,7 +64,8 @@ public class InetIPv6Utils implements Closeable {
|
|
|
|
|
InetAddress address = this.findFirstNonLoopbackIPv6Address();
|
|
|
|
|
if (address != null) {
|
|
|
|
|
return this.convertAddress(address);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
InetUtils.HostInfo hostInfo = new InetUtils.HostInfo();
|
|
|
|
|
this.properties.setDefaultIpAddress("0:0:0:0:0:0:0:1");
|
|
|
|
|
hostInfo.setHostname(this.properties.getDefaultHostname());
|
|
|
|
@ -61,8 +79,8 @@ public class InetIPv6Utils implements Closeable {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
int lowest = Integer.MAX_VALUE;
|
|
|
|
|
for (Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
|
|
|
|
|
nics.hasMoreElements();) {
|
|
|
|
|
for (Enumeration<NetworkInterface> nics = NetworkInterface
|
|
|
|
|
.getNetworkInterfaces(); nics.hasMoreElements();) {
|
|
|
|
|
NetworkInterface ifc = nics.nextElement();
|
|
|
|
|
if (ifc.isUp()) {
|
|
|
|
|
log.trace("Testing interface:" + ifc.getDisplayName());
|
|
|
|
@ -155,4 +173,5 @@ public class InetIPv6Utils implements Closeable {
|
|
|
|
|
hostInfo.setIpAddress(address.getHostAddress());
|
|
|
|
|
return hostInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|