域名的匹配,即测试两个网站的url是不是层次匹配的,
来源:互联网 发布:淘宝购物车营销下架了 编辑:程序博客网 时间:2024/06/03 23:44
public class DNSStringMatching {public static boolean DNSStrMatch(String dns,String url){boolean flag = false ;String tmpdns = dns.trim();//去空格String tmpstr="";String tmpurl = url.trim();if(tmpdns.length() > tmpurl.length()) return flag;if(tmpdns.length()>=7){tmpstr = tmpdns.substring(0, 7);if(tmpstr.equals("http://")){tmpdns = tmpdns.substring(7);//截取http://后面的内容}}if(tmpdns.length()>=4){tmpstr = tmpdns.substring(0, 4);if(tmpstr.equals("www.")){tmpdns = tmpdns.substring(4);//截取www.后面的内容}}if(tmpurl.length()>=7){tmpstr = tmpurl.substring(0, 7);if(tmpstr.equals("http://")){tmpurl = tmpurl.substring(7);//截取http://后面的内容}}if(tmpurl.length()>=4){tmpstr = tmpurl.substring(0, 4);if(tmpstr.equals("www.")){tmpurl = tmpurl.substring(4);//截取www.后面的内容}}int pos = tmpurl.indexOf(tmpdns);//tmpdns在url中的起始位置String ss = "";if(pos > 0) ss = tmpurl.substring( 0 , pos);int ishx = ss.indexOf("/");//判断是否是伪造的int strlen = tmpdns.length();//tmpdns的长度int dotposd = tmpdns.indexOf(".");int dotposu = tmpurl.indexOf(".");if(tmpdns.substring(strlen-1).equals("/"))//tmpdns最后一个字符是'/',则只要url中存在tmpdns则肯定能匹配{if(-1 != pos){if(-1 != ishx)//存在"/",则说明是伪造的return false ;else{if(!tmpdns.substring(0, dotposd).equals(tmpurl.substring(0, dotposu))){while(0 <= (pos-1)){if(tmpurl.substring(pos - 1, pos).equals("."))return true ;else return false ;}}else{flag = true;}}}}else{String tag="";if(-1 != pos){if(-1 != ishx)//存在"/",则说明是伪造的return false ;else{int ulen = tmpurl.length() - pos;if(ulen == tmpdns.length()){//dns与url右边的子串匹配if(!tmpdns.substring(0, dotposd).equals(tmpurl.substring(0, dotposu))){while(0 <= (pos-1)){if(tmpurl.substring(pos - 1, pos).equals("."))return true ;else return false ;}}else return true ;}else{//不是和右边的子串匹配tag = tmpurl.substring(pos + strlen, pos + strlen +1);}}}if(tag.equals("/")){ if(!tmpdns.substring(0, dotposd).equals(tmpurl.substring(0, dotposu))){while(0 <= (pos-1)){if(tmpurl.substring(pos - 1, pos).equals("."))return true ;else return false ;}}else return true ;}}return flag;}public static void main(String[] args){String dns[]={"http://www.people.com.cn/","http://xinhuanet.com","www.hb.xinhuanet.com/","www.hb.xinhuanet.com","www.b.xinhuanet.com/","www.b.xinhuanet.com","www.xinhuanet.com/","xinhuanet.com/2013-08/14","http://www.hnb.n.xinhuanet.com.cn","www.b.xinhuanet.com/","xinhuanet.com/2013-08/14/c_116945022.htm","http://xinhuanet.com/ ","b.xinhuanet.com/","http://xinhuanet.com/ ","tv.cn","xinhuanet.com","www.xinhuanet.com","http://www.xinhuanet.com","xinhuanet.org"};//这些是测试用例String url="http://fujian.people.com.cn/n/2013/0705/c181466-19006919.html";for(String str:dns){if(DNSStringMatching.DNSStrMatch(str, url))System.out.println("DNS:"+str+" URL:"+ url + " Match success!");elseSystem.out.println("DNS:"+str + " URL:"+url+ " Match failed!");}}}
0 0
- 域名的匹配,即测试两个网站的url是不是层次匹配的,
- javascript 正则匹配url的域名、文件名字
- 匹配URL的正则
- URL的正则匹配
- httpd的url匹配
- 匹配域名的正则表达式
- webpy的url动态匹配
- url-pattern的匹配规则
- 第一篇博客:nginx在重写url时,如果server_name有两个以上匹配的域名,重写规则里面不能包含$server_name
- 匹配IP字串、域名的正则表达式
- 匹配IP字串、域名的正则表达式
- 匹配IP字串、域名的正则表达式
- 匹配IP字串、域名的正则表达式
- 匹配IP字串、域名的正则表达式
- 匹配IP字串、域名的正则表达式
- 匹配顶级域名的正则表达式
- 匹配IP字串、域名的正则表达式
- 匹配IP字串、域名的正则表达式
- Activity停止的时候,取消部分未完成的网络请求
- UVA568 Just the Facts
- 微软SQL Server引入Hadoop大数据处理能力
- 1.5 C的主调函数与参数
- Oracle11.2.0.1.0节点1集群不能正常启动,报CRS-4535,CRS-4530
- 域名的匹配,即测试两个网站的url是不是层次匹配的,
- java 容器
- HDU 1593 find a way to escape
- solr boost设置
- 小愿望
- Activity停止的时候,取消部分未完成的网络请求
- Activity停止的时候,取消部分未完成的网络请求
- erlang shell表格数据对齐
- Activity停止的时候,取消部分未完成的网络请求