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

Method getLocalIP

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

@return 获取当前机器的IP

()

Source from the content-addressed store, hash-verified

38 * 获取当前机器的IP
39 */
40 public static String getLocalIP() {
41 InetAddress addr = null;
42 try {
43 addr = InetAddress.getLocalHost();
44 } catch (Exception e) {
45 e.printStackTrace();
46 }
47 byte[] ipAddr = addr.getAddress();
48 String ipAddrStr = "";
49 for (int i = 0; i < ipAddr.length; i++) {
50 if (i > 0) {
51 ipAddrStr += ".";
52 }
53 ipAddrStr += ipAddr[i] & 0xFF;
54 }
55 return ipAddrStr;
56 }
57}

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected