Hi,
I need to get the machine name that my java code is running on. I wrote this to test a couple functions that look promising:
but when I run it, I get:
MyMachineName
127.0.1.1
MyMachineName
I looked in my /etc/hosts file and saw that 127.0.1.1 was the 2nd line after 127.0.0.1
Do those functions just look in /etc/hosts or in /etc/hostname or do they use some other way of determining the Host Name? I just want to make sure my code doesn't stop working if it's run on a machine that has nothing but the 127.0.0.1 localhost in the /etc/hosts file...
Also, how can I get my real IP Address rather than my loopback address?
I need to get the machine name that my java code is running on. I wrote this to test a couple functions that look promising:
Code:
public static void main( String[] args ) throws IOException
{
InetAddress addr = InetAddress.getLocalHost();
System.out.println( addr.getHostName() );
System.out.println( addr.getHostAddress() );
System.out.println( addr.getCanonicalHostName() );
}
but when I run it, I get:
MyMachineName
127.0.1.1
MyMachineName
I looked in my /etc/hosts file and saw that 127.0.1.1 was the 2nd line after 127.0.0.1
Do those functions just look in /etc/hosts or in /etc/hostname or do they use some other way of determining the Host Name? I just want to make sure my code doesn't stop working if it's run on a machine that has nothing but the 127.0.0.1 localhost in the /etc/hosts file...
Also, how can I get my real IP Address rather than my loopback address?