MCPcopy Create free account
hub / github.com/Hello-hao/Tbed / getLocalPort

Method getLocalPort

src/main/java/cn/hellohao/utils/IPPortUtil.java:23–34  ·  view source on GitHub ↗

@return @throws MalformedObjectNameException 获取当前机器的端口号

()

Source from the content-addressed store, hash-verified

21 * 获取当前机器的端口号
22 */
23 public static String getLocalPort() {//throws MalformedObjectNameException
24 MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
25 Set<ObjectName> objectNames = null;
26 try {
27 objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"),
28 Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
29 } catch (MalformedObjectNameException e) {
30 e.printStackTrace();
31 }
32 String port = objectNames.iterator().next().getKeyProperty("port");
33 return port;
34 }
35
36 /**
37 * @return

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected