Created
July 17, 2019 13:37
-
-
Save geekykant/bef65efaf5f7ec823dfb131ce3dc8201 to your computer and use it in GitHub Desktop.
Get Hotspot IP Address
This file contains 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
private String getHotspotIpAddress() { | |
String ip = ""; | |
try { | |
Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface | |
.getNetworkInterfaces(); | |
while (enumNetworkInterfaces.hasMoreElements()) { | |
NetworkInterface networkInterface = enumNetworkInterfaces | |
.nextElement(); | |
Enumeration<InetAddress> enumInetAddress = networkInterface | |
.getInetAddresses(); | |
while (enumInetAddress.hasMoreElements()) { | |
InetAddress inetAddress = enumInetAddress.nextElement(); | |
if (inetAddress.isSiteLocalAddress()) { | |
ip += "SiteLocalAddress: " | |
+ inetAddress.getHostAddress() + "\n"; | |
} | |
} | |
} | |
} catch (SocketException e) { | |
e.printStackTrace(); | |
} | |
return ip; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment