Getting an IP Address as byte[]

A

Albretch

From:

file:///C:/apps/jakarta-tomcat-4.1.18/docs/javax/servlet/ServletRequest.html#getRemoteAddr()

public java.lang.String getRemoteAddr():
Returns the Internet Protocol (IP) address of the client that sent
the request. For HTTP servlets, same as the value of the CGI variable
REMOTE_ADDR.
Returns: a String containing the IP address of the client that
sent the request

Now, this String should look like d.d.d.d for Inet4 or
FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 for an Inet6 kind of address

Now, where is a method in Java which, given an IP Address returns to
you a byte[]. Four bytes in case of Inet4 and 16 in the case of Inet6?

Say, you would like to format IP Addresses you get from a client's
browser request using only 4 (or 16) bytes.

How do you combine the method getRemoteAddr() from the ServletRequest
with getAddress() from java.net.InetAddress to get the IP Address of
the remote user as a byte[] array?

The thing is that java.net.InetAddress.getAddress() gives you given a
host name, its corresponding IP address.

Of course you could always parse it off, but I think there should be
a method in the API.

Where is it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top