Skip to content

Instantly share code, notes, and snippets.

@geekykant
Created July 17, 2019 13:37
Show Gist options
  • Save geekykant/bef65efaf5f7ec823dfb131ce3dc8201 to your computer and use it in GitHub Desktop.
Save geekykant/bef65efaf5f7ec823dfb131ce3dc8201 to your computer and use it in GitHub Desktop.
Get Hotspot IP Address
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