Issue
Started working on a network monitoring app and I was wondering if there was a way to find out the ISP assigned IP address?
I've looked into the Inet and WifiManager API's and all they seem to give you is your local network ip address. The code I tried below, just gives me my local address.
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
TextView ipaddr = (TextView)findViewById(R.id.address);
ipaddr.setText("Your IP Address is: " + ip);
Solution
Try this:
try {
URL ip = new URL("http://checkip.amazonaws.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(ip.openStream()));
System.out.println(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
Answered By - Planck Constant
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.