使用request.getRemoteAddr(),如题。
预期结果是127.0.0.1
其实是这样的。
0:0:0:0:0:0:0:1是ipv6的表现形式,对应ipv4来说相当于127.0.0.1,也就是本机。
C:WindowsSystem32driversetchosts这个文件中的配置问题。
hosts文件中默认有:
# 127.0.0.1 localhost
# 0:0:0:0:0:0:0:1 localhost
只需要把# 0:0:0:0:0:0:0:1 localhost 注释或者删除就行