AIM :Get IP address of device in android
Solution:
It returns NULL if there is no network connection.
public static String getipAddress() {
try {
for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress=inetAddress.getHostAddress().toString();
Log.e("ip address",""+ipaddress);
return ipaddress;
}
}
}
} catch (SocketException ex) {
Log.e("Socket exception in GetIP Address of Utilities", ex.toString());
}
return null;
}
try {
for (Enumeration
NetworkInterface intf = en.nextElement();
for (Enumeration
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress=inetAddress.getHostAddress().toString();
Log.e("ip address",""+ipaddress);
return ipaddress;
}
}
}
} catch (SocketException ex) {
Log.e("Socket exception in GetIP Address of Utilities", ex.toString());
}
return null;
}
Call the above method wherever you wnat to get ip address as
String ipaddress=getipAddress();
--------------------------
check the loop curly bracket that whole loop return false,
ReplyDeleteOnce it will going to catch Exception then return Null.
So u need to do Explicitly change IP & get InetAddress API using return IP .getHostAddress();
if u not get send me Email: linkboy10@yahoo.com
Hi, this is not working for me on android 1.5 :( is there any other solution?
ReplyDeleteit works on 1.5 you just need to add android.permission.INTERNET to your project's AndroidManifest.xml
ReplyDeleteThe code is working fine on other devices except on Android OS 4.0.3. It returned the fe80::b607:f9ff:fee5:487e..etc … I dont know why.. Please help me
ReplyDeletepublic String getLocalIpAddress() {
Deletetry {
for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
Log.e(LOG_TAG, ex.toString());
}
return null;
From: http://stackoverflow.com/questions/10835017/android-get-ip-over-wifi-on-ics
I am genuinely pleased to read this web site posts which includes tons of useful facts, thanks for providing such
ReplyDeletestatistics.
My web page : sci-fi book blog
I'm really enjoying the theme/design of your website. Do you ever run into any web browser compatibility issues? A number of my blog audience have complained about my site not operating correctly in Explorer but looks great in Safari. Do you have any advice to help fix this issue?
ReplyDeleteMy homepage : Webmaster Daily Deals
It's awesome to go to see this web site and reading the views of all mates on the topic of this article, while I am also keen of getting experience.
ReplyDeleteHere is my homepage :: benefits of digestive enzymes
You should take part in a contest for one of the
ReplyDeletehighest quality websites on the internet. I most certainly will highly recommend this blog!
Here is my web blog i want a tattoo xtranormal
Hi to every , for the reason that I am actually eager of
ReplyDeletereading this blog's post to be updated regularly. It carries good stuff.
Visit my web page; watch movies on computer
I like the helpful information you provide in your articles.
ReplyDeleteI will bookmark your blog and check again here frequently.
I'm quite certain I will learn many new stuff right here! Good luck for the next!
Also visit my page secret of lock picking
It's a shame you don't have a donate button! I'd without a doubt donate to this brilliant blog! I guess for now i'll settle
ReplyDeletefor bookmarking and adding your RSS feed to my
Google account. I look forward to new updates and will share this website with
my Facebook group. Chat soon!
Here is my web site :: Piano Methods
Does your website have a contact page? I'm having trouble locating it but, I'd like to shoot you an email.
ReplyDeleteI've got some creative ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it improve over time.
my site ... Violin Lessons Dvd
Thank you for the good writeup. It in fact was
ReplyDeletea amusement account it. Look advanced to more added agreeable from you!
However, how could we communicate?
Have a look at my homepage vocal training Courses
This piece of writing will assist the internet visitors for setting
ReplyDeleteup new web site or even a blog from start to end.
Feel free to visit my weblog - laser tattoo removal cost
My web site: laser tattoo removal cost
I'm gone to tell my little brother, that he should also pay a quick visit this website on regular basis to take updated from most recent information.
ReplyDeletemy page; How Belly Dancing dna
is it possible to get the internet ip address ? (no need for device ip) can u help me to get internet ip (if they are using wifi or 3g or 2g internet or whatever, internet connection using, that internet ip needed)
ReplyDeletee cigarette forum, best electronic cigarettes, e cigarette, smokeless cigarettes, electronic cigarette starter kit, electronic cigarette brands
ReplyDelete