how to get the IP address in linux using java

hi i have an application which returns an Ip addess .The problem is it giving the valid IP address in windows but in linux i am getting invalid IP address please help me outthanls
[216 byte] By [nandashivaa] at [2007-11-27 7:40:14]
# 1
Some code would probably help. As well as a better description.
masijade.a at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 2

try {

InetAddress inetAddress = InetAddress.getLocalHost();

strIPAddress = inetAddress.getHostAddress();

} catch (UnknownHostException e) {}

its giving correct IP address in windows but if i run the same code on linux it not giving the ip address as i got in windows

please help

nandashivaa at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 3
Does it give you the same IP Address that pinging the name that the command "hostname" returns gives you?
masijade.a at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 4
Is it throwing an exception that you are ignoring in that dreadful empty catch {} block?
ejpa at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 5
it is not throwing any exception.it printing 127.0.0.1 ,which is not the ip of my computer
nandashivaa at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 6
Oh yes it is.It is the loopback address.Check your /etc/hosts file.This is a well-known Linux problem.
ejpa at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 7
what should i do in /etc/hosts , please help
nandashivaa at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 8
Change the line that associates your hostname with 127.0.0.1 to associate 127.0.0.1 with 'localhost' and change the line with your real IP address to associate it with your hostname.
ejpa at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 9
is there any way to change the hostname and the ip address using java code
nandashivaa at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...
# 10

Of course there is, if the user running it has "root" privileges (actually root userid or groupid if the permissions have been changed), but if you are going to do that, then why use the lookup at all, simply hardcode it in the program.

If it is because you don't know how to do it, then I would say to find someone you know who can show you how. That is infinately easier than trying to explain the structure and purpose of the hosts file to you here.

masijade.a at 2007-7-12 19:20:42 > top of Java-index,Core,Core APIs...