Skip to content

Instantly share code, notes, and snippets.

@nighthawk24
Last active August 29, 2015 13:58
Show Gist options
  • Save nighthawk24/10023211 to your computer and use it in GitHub Desktop.
Save nighthawk24/10023211 to your computer and use it in GitHub Desktop.
Android network related methods
public String getLocalIpAddressInfo() {
WifiManager wifii= (WifiManager) getSystemService(getApplicationContext().WIFI_SERVICE);
DhcpInfo d=wifii.getDhcpInfo();
String s_dns1="DNS 1: " + Formatter.formatIpAddress(Integer.valueOf(d.dns1));
String s_dns2="DNS 2: "+ Formatter.formatIpAddress(Integer.valueOf(d.dns2));
String s_gateway="Default Gateway: " + Formatter.formatIpAddress(Integer.valueOf(d.gateway));
String s_ipAddress="IP Address: "+ Formatter.formatIpAddress(Integer.valueOf(d.ipAddress));
String s_leaseDuration="Lease Time: "+ Integer.valueOf(d.leaseDuration);
String s_netmask="Subnet Mask: "+ Formatter.formatIpAddress(Integer.valueOf(d.netmask));
String s_serverAddress="Server IP: "+ Formatter.formatIpAddress(Integer.valueOf(d.serverAddress));
return "Network Info\n"+s_dns1+"\n"+s_dns2+"\n"+s_gateway+"\n"+s_ipAddress+"\n"+s_leaseDuration+"\n"+s_netmask+"\n"+s_serverAddress;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment