1、获取Tomcat端口
MBeanServer bs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> obname= null;
try {
obname = bs
.queryNames(new ObjectName("*:type=Connector,*"), Query
.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
} catch (MalformedObjectNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
port = obname.iterator().next().getKeyProperty("port");
System.out.println(port);
2、获取应用服务器IP地址
for (Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface networkinterface = enumeration.nextElement();
if (!name .contains("docker") && !name.contains("lo")) {
for (Enumeration<InetAddress> iparr = networkinterface.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress address = iparr.nextElement();
if (!address.isLoopbackAddress()) {
String ipaddress = address.getHostAddress().toString();
if (!ipaddress.contains("::")
&& !ipaddress.contains("0:0:")
&& !ipaddress.contains("fe80")) {
System.out.println(ipaddress);
}
}
}
}
}