第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何獲取遠(yuǎn)程IP地址如180.171.121.32

如何獲取遠(yuǎn)程IP地址如180.171.121.32

car 2017-10-29 12:45:55
????private?static?String?getRemoteIp(HttpServletRequest?request)?{ ????????//x-forwarded-for:代表客戶端,也就是HTTP的請(qǐng)求端真實(shí)的IP,只有在通過了HTTP代理或者負(fù)載均衡服務(wù)器時(shí)才會(huì)添加該項(xiàng) ????????String?ip?=?request.getHeader("x-forwarded-for"); ????????//Proxy-Client-IP和WL-Proxy-Client-IP:?只有在Apache(Weblogic?Plug-In?Enable)+WebLogic搭配下出現(xiàn),其中“WL”就是WebLogic的縮寫 ????????//訪問路徑是:Client?->?Apache?WebServer?+?Weblogic?http?plugin?->?Weblogic?Instances ????????if?(ip?==?null?||?ip.length()?==?0?||?"unknown".equalsIgnoreCase(ip))?{ ????????????ip?=?request.getHeader("Proxy-Client-IP"); ????????} ????????if?(ip?==?null?||?ip.length()?==?0?||?"unknown".equalsIgnoreCase(ip))?{ ????????????ip?=?request.getHeader("WL-Proxy-Client-IP"); ????????} ????????if?(ip?==?null?||?ip.length()?==?0?||?"unknown".equalsIgnoreCase(ip))?{ ????????????ip?=?request.getRemoteAddr(); ????????} //????????ip?=?"61.51.253.90"; //????????ip?=?"218.25.19.153"; ????????//0:0:0:0:0:0:0:1:?IPV6的形式,win7下可能會(huì)出現(xiàn) ????????//獲取遠(yuǎn)程IP地址 ? ????????return?"0:0:0:0:0:0:0:1".equals(ip)???"127.0.0.1"?:?ip; ????}這段代碼只能返回0:0:0:0:0:0:0:1
查看完整描述

2 回答

已采納
?
逆光之羽

TA貢獻(xiàn)55條經(jīng)驗(yàn) 獲得超13個(gè)贊


ip是環(huán)回地址不是因?yàn)轫?xiàng)目是在本機(jī)啟動(dòng),然后又是本機(jī)去調(diào)用對(duì)應(yīng)接口造成的么?

查看完整回答
反對(duì) 回復(fù) 2017-10-30
  • car
    car
    意思是項(xiàng)目要在遠(yuǎn)程啟動(dòng),才會(huì)真正的獲得正確IP地址
  • 逆光之羽
    逆光之羽
    其實(shí)我也沒試過,感覺應(yīng)該是這個(gè)問題,代碼本身好像沒問題,主要是沒地方掛項(xiàng)目上去的話不好測(cè)試...
?
言曌博客liuyanzhao_com

TA貢獻(xiàn)164條經(jīng)驗(yàn) 獲得超117個(gè)贊

//獲得物理ip
public?static?String?getIpAddr(HttpServletRequest?request){
????String?ipAddress?=?request.getHeader("x-forwarded-for");
????if(ipAddress?==?null?||?ipAddress.length()?==?0?||?"unknown".equalsIgnoreCase(ipAddress))?{
????????ipAddress?=?request.getHeader("Proxy-Client-IP");
????}
????if(ipAddress?==?null?||?ipAddress.length()?==?0?||?"unknown".equalsIgnoreCase(ipAddress))?{
????????ipAddress?=?request.getHeader("WL-Proxy-Client-IP");
????}
????if(ipAddress?==?null?||?ipAddress.length()?==?0?||?"unknown".equalsIgnoreCase(ipAddress))?{
????????ipAddress?=?request.getRemoteAddr();
????????if(ipAddress.equals("127.0.0.1")?||?ipAddress.equals("0:0:0:0:0:0:0:1")){
????????????//根據(jù)網(wǎng)卡取本機(jī)配置的IP
????????????InetAddress?inet=null;
????????????try?{
????????????????inet?=?InetAddress.getLocalHost();
????????????}?catch?(UnknownHostException?e)?{
????????????????e.printStackTrace();
????????????}
????????????ipAddress=?inet.getHostAddress();
????????}
????}
????//對(duì)于通過多個(gè)代理的情況,第一個(gè)IP為客戶端真實(shí)IP,多個(gè)IP按照','分割
????if(ipAddress!=null?&&?ipAddress.length()>15){?//"***.***.***.***".length()?=?15
????????if(ipAddress.indexOf(",")>0){
????????????ipAddress?=?ipAddress.substring(0,ipAddress.indexOf(","));
????????}
????}
????return?ipAddress;
}


查看完整回答
反對(duì) 回復(fù) 2017-10-30
  • 2 回答
  • 0 關(guān)注
  • 1928 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)