像移動閘道器一樣,iisforward這個isapi過濾器也會對request物件進行再包裝,附加一些wls要用的頭資訊。這種情況下,直接用request.getremoteaddr()
是無法取到真正的客戶ip的。
實際的iisforward附加頭如下:
wl-proxy-client-ip=211.161.1.239綜上,正確作法如下:proxy-client-ip=211.161.1.239
x-forwarded-for=211.161.1.239
wl-proxy-client-keysize=
wl-proxy-client-secretkeysize=
x-weblogic-request-clusterinfo=true
x-weblogic-keepalivesecs=30
x-weblogic-force-jvmid=-327089098
wl-proxy-ssl=false
private string getipaddr()
if(ipaddress == null || ipaddress.length() == 0 || "unknown".equalsignorecase(ipaddress))
if(ipaddress == null || ipaddress.length() == 0 || "unknown".equalsignorecase(ipaddress)) catch (unknownhostexception e)
ipaddress= inet.gethostaddress();}}
//對於通過多個**的情況,第乙個ip為客戶端真實ip,多個ip按照','分割
if(ipaddress!=null && ipaddress.length()>15)
}return ipaddress;
}
Java獲取請求客戶端的真實IP位址
通常通過request.getremoteaddr 取得客戶端的ip位址,做鑑權和校驗,邏輯沒問題,那麼肯定request.getremoteaddr 出了問題,google下,發現有人遇到類似的問題。最終定位為request.getremoteaddr 這種方法在大部分情況下都是有效的。但是在通過...
Java獲取客戶端的真實IP
發生的場景 伺服器端接收客戶端請求的時候,一般需要進行簽名驗證,客戶端ip限定等情況,在進行客戶端ip限定的時候,需要首先獲取該真實的ip。一般分為兩種情況 方式一 客戶端未經過 直接訪問伺服器端 nginx,squid,haproxy 方式二 客戶端通過多級 最終到達伺服器端 nginx,squi...
轉 Java獲取請求客戶端的真實IP位址
通常通過request.getremoteaddr 取得客戶端的ip位址,做鑑權和校驗,邏輯沒問題,那麼肯定request.getremoteaddr 出了問題,google下,發現有人遇到類似的問題。最終定位為request.getremoteaddr 這種方法在大部分情況下都是有效的。但是在通過...