find internet ip address in android mobile programmatically , no need device ip address

蹲街弑〆低调 提交于 2019-12-06 14:16:15
LondonAppDev

You can use this website and their API to get it: http://www.externalip.net/

Specifically http://api.externalip.net/ip

Alternatively (as mentioned by someone in the comments) you could create a PHP file on your server:

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

Android code using the externalip.net url (adapted from this answer)

HttpGet httppost = new HttpGet("http://api.externalip.net/ip");
HttpResponse response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
InputStream is = buf.getContent();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder total = new StringBuilder();
String ipaddress = r.readLine();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!