The Javadoc of ServletRequest.getRemoteAddr() does not mention anything about the format of returned IP addresses. This is annoying when implementing filters. What can we count on? Is there any official specification one can rely on? Thanks.
Let's start at ServletRequest#getRemoteAddr() javadoc:
getRemoteAddr
java.lang.String getRemoteAddr()Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable
REMOTE_ADDR.
(emphasis mine)
Okay, let's read CGI REMOTE_ADDR spec:
4.1.8. REMOTE_ADDR
The
REMOTE_ADDRvariable MUST be set to the network address of the client sending the request to the server.REMOTE_ADDR = hostnumber hostnumber = ipv4-address | ipv6-address ipv4-address = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit ipv6-address = hexpart [ ":" ipv4-address ] hexpart = hexseq | ( [ hexseq ] "::" [ hexseq ] ) hexseq = 1*4hex *( ":" 1*4hex )The format of an IPv6 address is described in RFC 3513 [15].
There, you've all possible formats.
It's an IPv4 or IPv6 address in standard textual notation.
192.168.254.1. I couldn't find an RFC that defines it. Wikipedia mentions that it's acceptable to use octal, binary or hexadecimal notation for any of the quads (and even to mix-and-match), but I've never seen anything but decimal.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With