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

  • Home
  • SEARCH
  • 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 790753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:43:47+00:00 2026-05-14T21:43:47+00:00

How can i get the LAN IP-address of a computer using Java? I want

  • 0

How can i get the LAN IP-address of a computer using Java? I want the IP-address which is connected to the router and the rest of the network.

I’ve tried something like this:

Socket s = new Socket("www.google.com", 80);
String ip = s.getLocalAddress().getHostAddress();
s.close();

This seem to work on some cases, but sometimes it returns the loopback-address or something completely different. Also, it requires internet connection.

Does anyone got a more accurate method of doing this?

EDIT: Thought it would be better to ask here than in a comment..

What if you got many interfaces? For example, one for cable, one for wifi and one for virtual box or so. Is it impossible to actually see which one is connected to the network?

  • 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-05-14T21:43:48+00:00Added an answer on May 14, 2026 at 9:43 pm

    Try java.net.NetworkInterface

    import java.net.NetworkInterface;
    
    ...
    
    for (
        final Enumeration< NetworkInterface > interfaces =
            NetworkInterface.getNetworkInterfaces( );
        interfaces.hasMoreElements( );
    )
    {
        final NetworkInterface cur = interfaces.nextElement( );
    
        if ( cur.isLoopback( ) )
        {
            continue;
        }
    
        System.out.println( "interface " + cur.getName( ) );
    
        for ( final InterfaceAddress addr : cur.getInterfaceAddresses( ) )
        {
            final InetAddress inet_addr = addr.getAddress( );
    
            if ( !( inet_addr instanceof Inet4Address ) )
            {
                continue;
            }
    
            System.out.println(
                "  address: " + inet_addr.getHostAddress( ) +
                "/" + addr.getNetworkPrefixLength( )
            );
    
            System.out.println(
                "  broadcast address: " +
                    addr.getBroadcast( ).getHostAddress( )
            );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 450k
  • Answers 450k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What you'd probably need is an InterfaceMapping. You can get… May 15, 2026 at 8:38 pm
  • Editorial Team
    Editorial Team added an answer In your views & layouts, you're looking for the session… May 15, 2026 at 8:38 pm
  • Editorial Team
    Editorial Team added an answer You can simply overload the comparison operator for the T… May 15, 2026 at 8:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.