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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取ip的接口

獲取ip的接口

田心楓 2017-05-31 23:53:06
介紹幾個 ?怎么樣獲取真實的IP ?過濾掉代理的IP
查看完整描述

2 回答

已采納
?
翔仔

TA貢獻35條經(jīng)驗 獲得超44個贊

//同學(xué)試試這個
????public?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)卡取本機配置的IP??
????????????????????InetAddress?inet=null;??
????????????????????try?{??
????????????????????????inet?=?InetAddress.getLocalHost();??
????????????????????}?catch?(UnknownHostException?e)?{??
????????????????????????e.printStackTrace();??
????????????????????}??
????????????????????ipAddress=?inet.getHostAddress();??
????????????????}??
????????????}??
????????????//對于通過多個代理的情況,第一個IP為客戶端真實IP,多個IP按照','分割??
????????????if(ipAddress!=null?&&?ipAddress.length()>15){?//"***.***.***.***".length()?=?15??
????????????????if(ipAddress.indexOf(",")>0){??
????????????????????ipAddress?=?ipAddress.substring(0,ipAddress.indexOf(","));??
????????????????}??
????????????}??
????????????return?ipAddress;???
????}


查看完整回答
1 反對 回復(fù) 2017-06-01
  • 2 回答
  • 4 關(guān)注
  • 1776 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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