hello,
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
to get list of the available interfaces. but when i println
i get this output
the mac address, then the ip address. how to get only the "192.168.1. 2" part?
i've tried using
but i get the following output
another consideration is, which interface address should i use? i can check if it's a loopback interface since NetworkInterfac e has the isLoopback method.
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.
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
Code:
NetworkInterface.getNetworkInterfaces();
Code:
NetworkInterface iface = en.nextElement(); System.err.println(iface.getInterfaceAddresses());
Code:
[/fe80:0:0:0:216:36ff:feac:d855%2/64 [null], /192.168.1.2/24 [/192.168.1.255]]
i've tried using
Code:
iface.getInetAddresses()
Code:
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.
Comment