Hi,
I am trying to do FTP file transferring using java language.
Found a code from a site and trying to modify it as I need. It works fine on Windows but I need on Linux (I'm working on CentOS 5.5).
When I run it on Linux it doesn't success, as I found because it gets the local IP as 127.0.0.1. (but in Windows it get the real IP)
The code part that gets the IP:
Code:
private static boolean openPort(ServerSocket serverSocket) throws IOException
{
int localport = serverSocket.getLocalPort();
// get local ip address
InetAddress inetaddress = serverSocket.getInetAddress();
InetAddress localip;
java.net.InetAddress addr = java.net.InetAddress.getLocalHost();
try {
localip = inetaddress.getLocalHost();
} catch(UnknownHostException e) {
debugPrint("Can't get local host");
return false;
}
....
}
Here the 'localip' variable gets 127.0.0.1.
Can somebody help me to get the real IP of the PC? (172.16.102.xxx)
Really appreciate your helps.
Thanks in advance!