Tags down


java InetAddress.getLocalHost(); returns ... how to get REAL IP?

By : Iskandar Properties
Date : October 15 2020, 11:12 PM
I hope this helps you . If you actually want to work with all of the IP addresses on the machine you can get those with the NetworkInterface class. Of course, then you need to which one you actually want to use, but that's going to be different depending on what you're using it for, or you might need to expand the way you're using it to account for multiple addresses.
code :

Share : facebook icon twitter icon

InetAddress.getLocalHost().getHostAddress() returns in Android

By : hannah sofian
Date : March 29 2020, 07:55 AM
it fixes the issue Modified few bits and this one is working as desired for getting IPv4 addresses. !inetAddress.isLoopbackAddress() removes all the loopback address. !inetAddress.isLinkLocalAddress() and inetAddress.isSiteLocalAddress()) removes all IPv6 addresses. I hope this will help someone in here.
code :
    StringBuilder IFCONFIG=new StringBuilder();
    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() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress()) {

    } catch (SocketException ex) {
        Log.e("LOG_TAG", ex.toString());

Java. InetAddress.getLocalHost returns strange IP

By : Heythere
Date : March 29 2020, 07:55 AM
I hope this helps you . The problem is that my hostname will consists only of numbers and could not be resolved. I change my /etc/hostname with characters at first position and problem has solved.

why does InetAddress.getLocalHost().getHostAddress() returns in android .But works fine in JAVA program

By : Charles Young
Date : March 29 2020, 07:55 AM
Any of those help This is expected behavior on Android. Please refer to the javadoc for getLocalHost():

What's the difference between InetAddress.getLocalHost().getHostAddress() and InetAddress.getLocalHost().getAddress()?

By : Leandro Araujo
Date : March 29 2020, 07:55 AM
Any of those help getHostAddress() and getAddress() returns the same information, the only difference between them is the information representation.
getHostAddress() returns String, which is a human readable text. For example, in my computer, it is "".

Java InetAddress.getLocalHost().getHostAddress() returns invalid IP

By : Chris HolmesParker
Date : March 29 2020, 07:55 AM
With these it helps Finally managed to fix it.
The issue, as @guest pointed out, is for some reason connecting to VPN messes up name resolution, so that my localhost is resolved to some remote IP.
Related Posts Related Posts :
  • Cannot convert from type object to long
  • Java consumes too much memory
  • Problem with the length of path in GCC
  • Java-lib for XML tree visualization
  • Which Data Structure? LinkedList or Any Other in Java?
  • Compilation error when instantiating a new ArrayList
  • How do I make this mouselistener only care about one object?
  • Why can't I assign a 'long' a value of 4 billion?
  • Trying to measure elapsed time in Java
  • JTabbedPane swing update error
  • C/C++ versus Java/C# in high-performance applications
  • Java JMenu setAccelerator() problem
  • Is this a perfect problem for the factory pattern?
  • Image based captcha
  • database polling using Java
  • pagerank implementation in java
  • Difficulty understanding Java MouseEvent
  • Java this.dispose not closing window when called
  • this.getClass().getClassLoader() and ClassLoader
  • Compare two tables in Java
  • Closing JFrame with button click
  • What is the need of Void class in Java
  • Sqlite on Android: How to create a sqlite dist db function - to be used in the app for distance calculation using lat, l
  • Using jsp:param / c:param in a Portlet Environment
  • Google AppEngine + Local JUnit Tests + Jersey framework + Embedded Jetty
  • junit test suites
  • Is it possible to use a different datastore for each subdomain with Google App Engine?
  • Dynamically creating colors with different brightness
  • What are those features which java has and others dont?
  • Solr date range storing help
  • Why can't java use thread context classloader when a method is literally called?
  • How to return a complex object from an axis web service
  • Cannot obtain shared variable value in separate threads
  • Is it possible to simultaneously and generically subclass both a bounded generic class and a generic interface?
  • How do I match a quoted string followed by a string in curly brackets?
  • Java Port scanner
  • Consume ado.net data service from android 2.1
  • Adding a .dll file to a jar
  • Do you use Java annotations?
  • What are the issues with preallocating objects in Java?
  • Confusion in form based authentication in java
  • Compress components with gzip - Java EE
  • Launching and debugging a Java application on a remote or virtual machine
  • Howto access properties file from Java EE web application?
  • what is the best way to merge pdfs in java
  • Regarding double dataype
  • Why does the Java compiler complain about a local variable not having been initialized here?
  • How do I restrict object creation not more than 3 in Java class?
  • Problem to display a pdf from my JSF Portlet of Liferay
  • How do I use "Remember Me" authentication with Spring Security and LDAP?
  • How do I get Maven to use the correct repositories?
  • hashtable Synchronization
  • Going crazy with these mouseEvent methods in Java
  • With JavaEE6, do we still need Spring, Hibernate or other frameworks?
  • Reading Java serialized object that has been split across two files?
  • Would a regex like this work for these lines of text?
  • List in java using Random numbers
  • What is more advisable to create a thread by extending a Thread class or implementing Runnable?
  • How do you get an instance of java.lang.Class for a generic collection like Collection<SomeObject>?
  • Code for Variations with repetition (combinatorics)?
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org