Created
November 26, 2018 07:47
-
-
Save shawnfeng0/c6f4c72fcc986d6bc28a425f40a66b0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<String> getIpAddressString() { | |
List<String> result = new ArrayList<>(); | |
try { | |
for (Enumeration<NetworkInterface> enNetI = NetworkInterface | |
.getNetworkInterfaces(); enNetI.hasMoreElements(); ) { | |
NetworkInterface netI = enNetI.nextElement(); | |
if (netI.getDisplayName().matches("wlan(.*)") || netI.getDisplayName().matches("eth(.*)")) { | |
for (Enumeration<InetAddress> enumIpAddr = netI | |
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { | |
InetAddress inetAddress = enumIpAddr.nextElement(); | |
if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) { | |
result.add(inetAddress.getHostAddress()); | |
} | |
} | |
} | |
} | |
} catch (SocketException e) { | |
e.printStackTrace(); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment