亚洲无码在线播放,欧美性爱一级在线视频,最新国产在线拍揄自揄视频,国产福利在线观看不卡视频,亚洲中文字幕aⅴ无码

<wbr id="au4ne"></wbr>
    1. <source id="au4ne"></source>

      java實(shí)現(xiàn)判斷ip是否在指定ip區(qū)間的工具類

      發(fā)布時(shí)間:2024-09-01
      思路:
      利用ip和ip區(qū)間兩端的值調(diào)用ipisvalid方法。
      (視頻教程推薦:java課程)
      工具類:
      import org.apache.commons.lang.stringutils;import org.springframework.web.context.request.requestcontextholder;import org.springframework.web.context.request.servletrequestattributes;import javax.servlet.http.httpservletrequest;public class iputil { / * 獲得當(dāng)前ip * @return */ public static string getip(){ servletrequestattributes servletrequestattributes = (servletrequestattributes) requestcontextholder.getrequestattributes(); if(servletrequestattributes == null) { return "127.0.0.1"; } httpservletrequest request = servletrequestattributes.getrequest(); string ip = request.getheader("x-forwarded-for"); 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.getheader("http_client_ip"); } if (ip == null || ip.length() == 0 || "unknown".equalsignorecase(ip)) { ip = request.getheader("http_x_forwarded_for"); } if (ip == null || ip.length() == 0 || "unknown".equalsignorecase(ip)) { ip = request.getremoteaddr(); } if ("0:0:0:0:0:0:0:1".equals(ip)) { ip = "127.0.0.1"; } return ip; } / * 判斷ip是否在指定范圍 * @param ipstart * @param ipend * @param ip * @return */ public static boolean ipisvalid(string ipstart,string ipend, string ip) { if (stringutils.isempty(ipstart)) { throw new nullpointerexception("起始ip不能為空!"); } if (stringutils.isempty(ipend)) { throw new nullpointerexception("結(jié)束ip不能為空!"); } if (stringutils.isempty(ip)) { throw new nullpointerexception("ip不能為空!"); } ipstart = ipstart.trim(); ipend = ipend.trim(); ip = ip.trim(); final string regx_ip = "((25[0-5]|2[0-4]\\\\\\\\d|1\\\\\\\\d{2}|[1-9]\\\\\\\\d|\\\\\\\\d)\\\\\\\\.){3}(25[0-5]|2[0-4]\\\\\\\\d|1\\\\\\\\d{2}|[1-9]\\\\\\\\d|\\\\\\\\d)"; final string regx_ipb = regx_ip "\\\\\\\\-" regx_ip; if (!ipstart.matches(regx_ip) || !ip.matches(regx_ip) || !ipend.matches(regx_ip)) { return false; } string[] sips = ipstart.split("\\\\\\\\."); string[] sipe = ipend.split("\\\\\\\\."); string[] sipt = ip.split("\\\\\\\\."); long ips = 0l, ipe = 0l, ipt = 0l; for (int i = 0; i < 4; i) { ips = ips << 8 | integer.parseint(sips[i]); ipe = ipe << 8 | integer.parseint(sipe[i]); ipt = ipt << 8 | integer.parseint(sipt[i]); } if (ips > ipe) { long t = ips; ips = ipe; ipe = t; } return ips <= ipt && ipt <= ipe; }} 相關(guān)教程推薦:java入門教程
      上一個(gè):軸承加熱器有哪些優(yōu)勢
      下一個(gè):在安裝靜電水處理器之前看看本篇會(huì)很有幫助

      埃斯頓擬授出1000萬份股票期權(quán)
      恒溫水浴鍋的工作原理及操作維護(hù)保養(yǎng)的注意事項(xiàng)
      日喀則空運(yùn)(成都物流空運(yùn)日喀則)
      小米3怎么取消拒絕來電,小米怎么取消自動(dòng)拒絕
      變壓器線圈直阻快測儀技術(shù)指標(biāo)
      電纜如何在海底敷設(shè)?
      一文看懂三通角閥機(jī)床的優(yōu)勢
      dichtomatiko型圈油封等配件產(chǎn)品全方位解析(滿足多領(lǐng)域需求)
      防腐風(fēng)機(jī)對(duì)使用電機(jī)的要求
      RC1206FR-07133KL,1206 133KΩ 1% 1/4W 電阻