Java code to get inet address in linux
hi all.. i encounter a problem. I have a servlet that is deploy in apache tomcat which is running the linux OS. I need to get the inet address in order to let client access the server.
I coded these lines of code in my servlet:
InetAddress localhost = InetAddress.getLocalHost();
String hostAddr = localhost.getHostAddress();
However, i encounter null for hostAddr but it works perfectly well in Windows. I want to get the ip address of the server, example: 203.204.423.52 and not 127.0.0.1.
Anyone knows how to solve the above issue? Do i need to make any changes to the coding to cater for linux? Any suggestion or comment is welcome. Thanks!
|