Finding IP address of your Android device programatically

 You can find more about finding IP address of Android device programatically



public String getLocalIpAddress()
  {
          try {
              for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                  NetworkInterface intf = en.nextElement();
                  for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                      InetAddress inetAddress = enumIpAddr.nextElement();
                      if (!inetAddress.isLoopbackAddress()) {
                          return inetAddress.getHostAddress().toString();
                      }
                  }
              }
          } catch (Exception ex) {
              Log.e("IP Address", ex.toString());
          }
          return null;
      }

Add below permission in the manifest file.
   <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


Happy coding :-)

61 comments:

  1. I am not getting the required IP address.. I am staying India & its showing canada ip address.. what might be the problem.I am using same code.. working fine but showing wrong IP address.

    ReplyDelete
    Replies
    1. Ok! You mayn't find the exact location of IP network provider.

      Delete
    2. OK! You may not find the exact location of IP network provider address for solving your service grievances, however you search the IP address at IP-Details.com for the required IP details.

      Delete
  2. Thank you very much :)

    ReplyDelete
  3. This is not correct. Please don't use this code.

    ReplyDelete
  4. Where to write this code? Is there any emulator for android ?

    ReplyDelete
  5. instead of
    if (!inetAddress.isLoopbackAddress()) {

    use
    if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {

    for getting ipv4 address

    ReplyDelete
  6. not correct, bad code!
    it may work in some scenario.
    better list all IP addresses than give just the first not equal to 127.0.0.1

    ReplyDelete
  7. Here i am posting complete solution for getting IP Address for any type of network

    public static String getLocalIpAddress() {
    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() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
    return inetAddress.getHostAddress().toString();
    }
    }
    }

    } catch (Exception ex) {

    }
    return null;
    }

    Thanks & Regards
    Manoj
    +91-8553540873
    manoj.cs.iu@gmail.com

    ReplyDelete
    Replies
    1. I got error in "InetAddressUtils". How can I solve it. Android Studio suggest me to create class. What's the solution?

      Thanks.

      Delete
  8. i want the external ip address if the user is connected to wifi.

    ReplyDelete
  9. Hi! If you need any technical help regarding QuickBooks issues, dial QuickBooks Support Phone Number +1-877-751-0742 for instant help.

    ReplyDelete
  10. I really love your blog post. Thanks for sharing. chord gitar

    ReplyDelete
  11. I am so pleased I situated your blog site, I actually situated you by mistake, while I was taking a look at on google for another point, Anyways I am below now in addition to additionally would certainly just like to insist give thanks to for an outstanding blog post along with an all-around entertaining internet site 먹튀

    ReplyDelete
  12. I truly love your blog.. Very nice colors & theme. Did you make this web site yourself? Please reply back as I’m hoping to create my own personal blog and would love to find out where you got this from or what the theme is named. Thank you. It¦s really a great and useful piece of information. I¦m happy that you just shared this useful information with us. Please keep us informed like this. Thank you for sharing. Do you know if they make any plugins to help with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good gains. If you know of any please share. Thanks! This website definitely has all the info I needed concerning this subject and didn’t know who to ask. 먹튀검증

    ReplyDelete
  13. Good day. Very cool blog!! Man .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds additionally…I am glad to locate numerous useful info right here within the post. Thank you for sharing. I can see that you are an somebody in this matter. I am beginning a site soon, and your information will be very effective for me.. Thanks for all your help and wishing you all the prosperity in your business. Amazing blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple adjustements would really make my blog jump out. Please let me know where you got your design. Cheers I came across your blog after i did a search for winter hair cair tips at Yahoo. I wanted to say thank you for taking time to create this site and letting me post 메이저놀이터

    ReplyDelete
  14. I’m amazed, I have to admit. Seldom do I come across a blog that’s equally educative and amusing, and let me tell you, you've hit the nail on the head. The problem is something not enough people are speaking intelligently about. Now i'm very happy that I found this in my hunt for something relating to this. I'm still learning from you, but I'm making my way to the top as well. I definitely enjoy reading all that is posted on your blog.Keep the tips coming. I enjoyed it! Everything is very open with a really clear clarification of the challenges. It was truly informative. Your website is very useful. Thank you for sharing! 우리카지노

    ReplyDelete
  15. Your style is really unique compared to other people I have read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this web site. A fascinating discussion is worth comment. I think that you ought to write more about this subject matter, it might not be a taboo subject but usually people don’t talk about these issues. To the next! Cheers!! Greetings! Very helpful advice in this particular article! It is the little changes that will make the greatest changes. Thanks for sharing! I have to thank you for the efforts you have put in penning this website. I really hope to check out the same high-grade content by you in the future as well. In truth, your creative writing abilities has inspired me to get my own, personal site now 😉 우리카지노

    ReplyDelete
  16. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. I know this is one of the most meaningful information for me. And I'm animated reading your article. But should remark on some general things, the website style is perfect; the articles are great. Thanks for the ton of tangible and attainable help . What a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much . I don’t have time right now to write a lot, but when I returned tomorrow evening, I will explain in depth why I disagree with this article. After study many of the blog posts on your own internet site now, and i genuinely much like your means of blogging. 우리카지노

    ReplyDelete
  17. "Aw, this was an incredibly nice post. Taking a few minutes and actual effort to create a very good articleÖ but what can I sayÖ I hesitate a whole lot and don’t manage to get anything done. I got this site from my buddy who told me regarding this site and at the moment this time I am
    visiting this website and reading very informative posts here. Good day! Do you use Twitter? I’d like to follow you if that would be okay. I’m absolutely enjoying your blog and look forward to new posts. Way cool! Some extremely valid points! I appreciate you penning this write-up plus the rest of the website is also really good. I think this is an informative post and it is very useful and knowledgeable. Therefore, I would like to thank you for the efforts you have made in writing this article." 엔트리파워볼

    ReplyDelete
  18. Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks . You share really interesting news which I never read on any website. Thanks for sharing here . After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article. I appreciate the time you put into this post. In fact your writing has me wanting to kickoff my own webblog now. Thanks again for sharing this up. This surely helps me in my work. Lol, thanks for your comment! wink Glad you found it helpful. 먹튀폴리스

    ReplyDelete
  19. I appreciate several from the Information which has been composed, and especially the remarks posted I will visit once more. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our . I always choose to study The great and glad i found this thing in you put up. thank you . Good post! We wilpl be linking to this great post on our site. Keep up the goodd writing. I just want to give an full-size thumbs up for the pleasant info you've got right here in this put up. Lovely blog! I am loving it!! Will come back again. I am bookmarking your feeds also. 먹튀폴리스

    ReplyDelete
  20. Very interesting information!Perfect just what I was looking for!..Here you can find youngsters of perfection who make some incredible memories fulfilling your dreams. You could call this spot heaven! Our high-class Goa Escorts...Yes, I am entirely agreed with this article, and I just want say that this article is very helpful and enlightening. I also have some precious piece of concerned info !!!!!!Thanks. 먹튀검증업체

    ReplyDelete
  21. I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while. Its as if you had a wonderful grasp on the subject matter, but you forgot to include your readers. Perhaps you should think about this from far more than one angle. Or maybe you shouldnt generalise so considerably. Its better if you think about what others may have to say instead of just going for a gut reaction to the subject. Think about adjusting your own believed process and giving others who may read this the benefit of the doubt. This is a good influencing take on this specific thought. I am glad you shared your thoughts as well as ideas and I find that i am in agreement. I certainly like the straightforward writing additionally , the work you’ve you spend working on this post. This is really exciting, You’re an especially skilled writer. I’ve enrolled with your feed plus look ahead to enjoying the excellent write-ups. 먹튀검증업체

    ReplyDelete
  22. "Hello, I read your blogs like every week. Your humoristic style is awesome, keep it up!" Appreciation to my father who shared with me concerning this web site, this weblog is genuinely remarkable. I am genuinely pleased to glance at this web site posts which consists of lots of helpful data, thanks for providing these information Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Once I initially commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any method you can take away me from that service? Thanks! 먹튀검증업체

    ReplyDelete
  23. Thanks , I have recently been searching for information approximately this subject for a while and yours is the best I have found out so far. However, what about the bottom line? Are you positive about the supply? That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more . It is an excellent blog, I have ever seen. I found all the material on this blog utmost unique and well written. And, I have decided to visit it again and again 먹튀폴리스

    ReplyDelete
  24. After looking into a few of the blog posts on your website, I honestly like your technique of blogging. I saved it to my bookmark site list and will be checking back in the near future. Please check out my web site too and tell me your opinion. Greetings, I do think your web site might be having browser compatibility issues. Whenever I take a look at your web site in Safari, it looks fine however when opening in I.E., it has some overlapping issues. I merely wanted to provide you with a quick heads up! Other than that, wonderful website! Your style is unique in comparison to other folks I’ve read stuff from. Thanks for posting when you’ve got the opportunity, Guess I will just bookmark this blog. 파워볼사이트

    ReplyDelete
  25. thanks for this first-rate positioned up, i find it very exciting and very well concept out and prepare. I sit up for studying your paintings in the future. That is my first visit in your internet journal! We are a fixed of volunteers and new sports inside the identical specialty. Internet site gave us useful information to work. Thank you for the blog loaded with such quite a few statistics. Preventing via your blog helped me to get what i used to be looking for. Superb net site! I adore the manner it is straightforward on my eyes it's far. Thanks for supporting people get the facts they want. First-rate stuff as normal. Maintain up the remarkable artwork!!! I examine your blog publish and that is remarkable blog submit.. Thanks for taking the time to proportion with us. Have a nice day . The writer has inspired me with the coolest satisfactory art work proper here. I will make certain that i share this article with as many people as i'm able to. I suppose it is vital to elevate attention about this issue. The best manner to accomplish that is by way of sharing. First-rate weblog. I enjoyed investigating your articles. That is to a exquisite degree an extraordinary investigated for me. I've bookmarked it and i'm suspecting examining new articles. Maintain doing spectacular! Admiring the time and effort you positioned into your blog and wonderful facts you offer! The net website on-line is lovingly serviced and saved as a lot as date. So it ought to be, thanks for sharing this with us. I’ve been attempting to find a few first rate stuff on the concern and feature now not had any fulfillment up till this aspect, you just have been given a new largest fan! I found your this submit on the equal time as searching out a few associated records on blog are searching for... Its a very good put up.. Keep posting and update the facts . That could be a top notch article and exquisite read for me. It is my first go to for your weblog, and i have determined it so beneficial and informative specially this . I observe your blog submit and that is first rate blog publish.. Thank you for taking the time to proportion with us. Have a nice day . The internet internet site is lovingly serviced and stored as plenty as date. So it must be, thanks for sharing this with us 메이저놀이터

    ReplyDelete
  26. I am so pleased I situated your blog site, I actually situated you by mistake, while I was taking a look at on google for another point, Anyways I am below now in addition to additionally would certainly just like to insist give thanks to for an outstanding blog post along with an all-around entertaining internet site. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don’t forget, keep sharing useful info: 메이저사이트

    ReplyDelete
  27. Thanks for sharing excellent informations. Your web-site is very cool. I’m impressed by the details that you have on this site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. I found simply the information I already searched all over the place and simply couldn’t come across. What a great web-site. I’m really impressed about the info you provide in your articles. I must say am highly overwhelmed by your whole story. It’s not easy to get such quality information online nowadays. I look forward to staying here for a long time. I just wanted to say that I love every time visiting your wonderful post! Very powerful and have true and fresh information.Thanks for the post and effort! Please keep sharing more such a blog. 안전놀이터

    ReplyDelete
  28. Newstyle Print offers high end, low cost banner printing in the UK 에볼루션카지노

    ReplyDelete
  29. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article. 메이저사이트

    ReplyDelete
  30. Very informative post ! There is a lot of information here that can help any business get started with a successful social networking campaign 토토사이트

    ReplyDelete
  31. You actually make it look so easy with your performance but I find this matter to be actually something which I think I would never comprehend. It seems too complicated and extremely broad for me. I'm looking forward for your next post, I’ll try to get the hang of it! 토토검증

    ReplyDelete
  32. I know this is one of the most meaningful information for me. And I'm animated reading your article. But should remark on some general things, the website style is perfect; the articles are great. Thanks for the ton of tangible and attainable help 먹튀

    ReplyDelete
  33.  I want to have this great information. I love it so much! buy zopiclone 7.5mg

    ReplyDelete
  34. It’s impressive that you are getting thoughts from this piece of writing as well as from our discussion made at this time.
    카지노


    >cc

    ReplyDelete
  35. Hi! I hope you are doing well. In case you are facing any difficulty in managing your accounts, then go for QuickBooks.
    Moreover, if you encounter any error in this software, dial QuickBooks Customer Service Phone Number (888)-807-0601 and get your query resolved quickly.

    ReplyDelete
  36. Hey! Nice Blog. Keep up the excellent work.
    QuickBooks is a popular accounting software; however, sometimes it’s working is often hindered by QuickBooks Error 3030.
    To get solutions for such issues, dial QuickBooks Customer Service Phone Number Oklahoma (888)-497-2598 and get assistance from the experts.

    ReplyDelete
  37. Hi! Nice blog. If you are using QuickBooks software as your business accounting software, then you may face QuickBooks Error 1722 in your software.
    To fix such issues, dial QuickBooks Customer Service Phone Number Ohio 888-903-0715 and get the best methods from their end.

    ReplyDelete
  38. Wow! What an excellent post. Keep it up and never stop writing such magnificent blogs.
    Moreover, if you have difficulty managing payrolls for your employees in today's multinational business world then go for QuickBooks accounting software.
    It has the best payroll management system. Call QuickBooks Customer Support Phone Number(888)-807-0601 in case of any difficulty.

    ReplyDelete
  39. "I am a normal visitor of your web site and appreciate you taking the time to maintain the excellent site. I will be a frequent visitor for a long time.

    " 토토사이트

    ReplyDelete
  40. Amazing blog! Thanks for sharing. reach us at - House for Sale in Puzhal, Apartments in Madhavaram. Sivanta Foundations are a passionate team of builders with superior expertise in the planning, development and construction of truly distinctive residences for a diverse client base. Book Now!

    ReplyDelete
  41. A good team can handle every hurdle, and im amazed by your teamwork. Everything on your website is tremendous. Winter Sale Jacket

    ReplyDelete