1、獲取Tomcat埠
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = null;
try {
objectNames = beanServer
.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 = objectNames.iterator().next().getKeyProperty("port");
System.out.println(port);
2、獲取應用服務器IP地址
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
if (!name.contains("docker") && !name.contains("lo")) {
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress = inetAddress.getHostAddress().toString();
if (!ipaddress.contains("::")
&& !ipaddress.contains("0:0:")
&& !ipaddress.contains("fe80")) {
System.out.println(ipaddress);
}
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/261035.html
標籤:其他
上一篇:手擼六足機器人(三)----------確定控制方式“搖桿模塊+LCD螢屏顯示+藍牙通訊”及原始碼示例[STM32實作]
