tags:

views:

46

answers:

2

Hi there,

Does anyone know how to get the Local Net Ip Address from a Remote Client in java?

thx

+1  A: 

Is this what you are looking for?

InetAddress addr = InetAddress.getLocalHost();
byte[] ipAddr = addr.getAddress(); // Get IP Address
String hostname = addr.getHostName(); // Get hostname

That gets the IP of the machine the code is running on.

Plaudit Design - Web Design
A: 

Assuming you mean getting the local IP address of a client running behind NAT, you can only do that with the client's cooperation, meaning you have to send it yourself.

What do you need it for anyway?

Bart van Heukelom
@Bart: Don't ask why he needs it. People makes a lot of projects. And you know it is very irritating (can't find a better word in English) when they ask you for what you need what you are asking for.
Martijn Courteaux
I don't ask it without a reason. The local IP seems an odd thing to need to know. If we know why he thinks he needs it, we may have better answers.
Bart van Heukelom
Jeje... well..the idea is that I have a server with a web app in a net and the client in another, so.. for example, if the client is in a building A and server in building B, thus the public ip of the building A, I need to know the subnet where the user connect to the app.Any sugestion?
RhigoHR
But I wonder, why would you need the subnet of the client? I hope it's not for something related to security, because it's not safe.
Bart van Heukelom