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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get the IP Address
 
Similar Threads
How to extract country name from IP Address
How to get IP Address of Client Machine?
getting the actual client IP
can we detect location if GPS is not accesible
Can I get source ip address and destination ip address of udp packet?