aspose file tools*
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
Author

get the IP Address

Mike Abayon
Greenhorn

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.
Regards,
Amit
Mike Abayon
Greenhorn

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

Joined: Aug 05, 2001
Posts: 2545
Thanks for the informations!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: get the IP Address