gpt4 book ai didi

java - ServletRequest.getRemoteAddr()返回的IP格式是什么

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:50:11 25 4
gpt4 key购买 nike

ServletRequest.getRemoteAddr() 的 Javadoc没有提及返回的 IP 地址的格式。这在实现过滤器时很烦人。我们可以指望什么?有没有可以依赖的官方规范?谢谢。

最佳答案

让我们从 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.

(强调我的)

好吧,让我们阅读CGI REMOTE_ADDR spec :

4.1.8. REMOTE_ADDR

The REMOTE_ADDR variable 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].

那里,你有所有可能的格式。

关于java - ServletRequest.getRemoteAddr()返回的IP格式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com