Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:32:50+00:00 2026-06-05T17:32:50+00:00

Q:-Now a days I am facing problem in getting IP address of android device

  • 0

Q:-Now a days I am facing problem in getting IP address of android device using programming. Can any one give ma a code for solving that problem. I have already read lot of thread about it but not getting solid answer from that. Please give me any suggesting about it its appreciated.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:32:52+00:00Added an answer on June 5, 2026 at 5:32 pm

    The problem is that you cannot know if your current in use network device is really has a public IP. You could however check if this is the case but you need to contact a external server.

    In this case we can use http://www.whatismyip.com to check (almost copied from another SO question):

    public static InetAddress getExternalIp() throws IOException {
        URL url = new URL("http://automation.whatismyip.com/n09230945.asp");
        URLConnection connection = url.openConnection();
        connection.addRequestProperty("Protocol", "Http/1.1");
        connection.addRequestProperty("Connection", "keep-alive");
        connection.addRequestProperty("Keep-Alive", "1000");
        connection.addRequestProperty("User-Agent", "Web-Agent");
    
        Scanner s = new Scanner(connection.getInputStream());
        try {
            return InetAddress.getByName(s.nextLine());
        } finally {
            s.close();
        }
    }
    

    To check that this ip is bound to one of your network interfaces:

    public static boolean isIpBoundToNetworkInterface(InetAddress ip) {
    
        try {
            Enumeration<NetworkInterface> nets = 
                NetworkInterface.getNetworkInterfaces();
    
            while (nets.hasMoreElements()) {
                NetworkInterface intf = nets.nextElement();
                Enumeration<InetAddress> ips = intf.getInetAddresses();
                while (ips.hasMoreElements())
                    if (ip.equals(ips.nextElement()))
                        return true;
            }
        } catch (SocketException e) {
            // ignore
        }
        return false;
    }
    

    Test code:

    public static void main(String[] args) throws IOException {
    
        InetAddress ip = getExternalIp();
    
        if (!isIpBoundToNetworkInterface(ip))
            throw new IOException("Could not find external ip");
    
        System.out.println(ip);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now days I am getting a problem in attaching JAR files in Blackberry..... I
I am facing the above problem frequently now a days for many of our
I have been using Subversion for a few days now and have a question...
been working on this for two days now and seem to be getting nowhere.
Now a days, I make one application in Silverlight to get Emails from MS
For few days now I'm trying to solve this problem. I have table group_user,
I have searched the web for days now but I can't seem to find
I've been trying for days now to create an application client server,both on android,running
For several days now I've been messing around with Ajax calls using different combinations
i'm struggling around for days now ...this is the scenario: a user can upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.