Commit 6b563d69 by 陶光胜

取数平台调整

parent 70e937d2
...@@ -7,7 +7,10 @@ import com.gic.cloud.data.hook.api.dto.DownloadRecord; ...@@ -7,7 +7,10 @@ import com.gic.cloud.data.hook.api.dto.DownloadRecord;
import com.gic.cloud.data.hook.service.impl.FlatQueryResultServiceImpl; import com.gic.cloud.data.hook.service.impl.FlatQueryResultServiceImpl;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List; import java.util.List;
public class DataInitUtils { public class DataInitUtils {
...@@ -35,13 +38,35 @@ public class DataInitUtils { ...@@ -35,13 +38,35 @@ public class DataInitUtils {
} }
private static String getHost(){ private static String getHost(){
try{ String localip = null;// 本地IP,如果没有配置外网IP则返回它
String hostAddress = InetAddress.getLocalHost().getHostAddress(); String netip = null;// 外网IP
return hostAddress; try {
}catch (Exception e){ Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
boolean finded = false;// 是否找到外网IP
while (netInterfaces.hasMoreElements() && !finded) {
NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
Enumeration address = ni.getInetAddresses();
while (address.hasMoreElements()) {
ip = (InetAddress) address.nextElement();
if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 外网IP
netip = ip.getHostAddress();
finded = true;
break;
} else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 内网IP
localip = ip.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace(); e.printStackTrace();
} }
return "";
if (netip != null && !"".equals(netip)) {
return netip;
} else {
return localip;
}
} }
public static void main(String[] args){ public static void main(String[] args){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment