Guest User

Untitled

a guest
Jan 23rd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
  2. InetAddress inetAddress = enumIpAddr.nextElement();
  3. if (!inetAddress.isLoopbackAddress()) {
  4. networkIpAdress = inetAddress.getHostAddress().toString();
  5. }
  6. }
  7.  
  8. WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
  9. WifiInfo wifiInfo = wifiManager.getConnectionInfo();
  10. int ipAddress = wifiInfo.getIpAddress();
  11.  
  12. HttpClient httpclient = new DefaultHttpClient();
  13. HttpGet httpget = new HttpGet("http://ip2country.sourceforge.net/ip2c.php?format=JSON");
  14. HttpResponse response;
  15. response = httpclient.execute(httpget);
  16. HttpEntity entity = response.getEntity();
  17. entity.getContentLength();
  18. JSONObject json_data = new JSONObject(EntityUtils.toString(entity));
  19. String networkIpAdress = json_data.getString("ip");
Add Comment
Please, Sign In to add comment