jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes get the IP Address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "get the IP Address" Watch "get the IP Address" New topic

get the IP Address

Mike Abayon

Joined: Jun 14, 2001
Posts: 8
Is there a way to get the IP address of a client computer that just connected to the server?
Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
Hi mike,
what is the method you are using for the connection between the client and the server?
If you are using TCP then use the Socket that you get from ServerSocket.accept().
Socket.getInetAddress() will give the InetAddress object.
You can use InetAddress.getHostAddress() to get a string representation of the IP Address. You can look at the InetAddress class documentation for other useful methods.
If you are using UDP then use the DatagramPacket object you received.
The DatagramPacke.getAddress() will also return an InetAddress object.
Mike Abayon

Joined: Jun 14, 2001
Posts: 8
Thanks Amit!
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Thanks for the informations!
I agree. Here's the link: http://aspose.com/file-tools
subject: get the IP Address
It's not a secret anymore!