i'm developing a J2SE VoIP app. i used the InetAddress.get LocalHost() to get the address of the local machine.
it works in xp, but not in Ubuntu. in Ubuntu it gives me "127.0.1.1" , which is listed in /etc/hosts file.
after some search, some advice to use
Expand|Select|Wrap|Line Numbers
- NetworkInterface.getNetworkInterfaces();
Expand|Select|Wrap|Line Numbers
- NetworkInterface iface = en.nextElement();
- System.err.println(iface.getInterfaceAddresses());
Expand|Select|Wrap|Line Numbers
- [/fe80:0:0:0:216:36ff:feac:d855%2/64 [null], /192.168.1.2/24 [/192.168.1.255]]
i've tried using
Expand|Select|Wrap|Line Numbers
- iface.getInetAddresses()
Expand|Select|Wrap|Line Numbers
- java.net.NetworkInterface$1checkedAddresses@1884a40
but sometimes, a machine has two or more NIC with one connected to the local network and the other one to the internet. if the user chooses to connect to a local server, i should choose the interface connected the LAN. and the same thing apply if the user wants to connect to a public server in the internet, i should choose the address connected to the internet.
how to determine this?
Thank you.