您的位置 首页 知识分享

如何改进IP地址匹配代码以支持多种数据库格式?

教你从左到右匹配一部分 原始代码从左到右匹配一部分: dim aa, iplist, ip, found aa…

如何改进IP地址匹配代码以支持多种数据库格式?

教你从左到右匹配一部分

原始代码从左到右匹配一部分:

dim aa, iplist, ip, found aa = "11.9.67.180" iplist = array("99.88", "110.52", "43.80.235", "11.9.") found = false  for each ip in iplist     if instr(aa, ip) > 0 then         found = true         exit for     end if next  if found then     response.write "ok"     response.end end if
登录后复制

改动后只能完全匹配:

dim aa, iplist, ip, found, dbiplist aa = request.servervariables("remote_addr")  dbiplist = rs("ip")  iplist = split(dbiplist, ",")  found = false  for each ip in iplist     ip = trim(ip)     if instr(aa, ip) > 0 then         found = true         exit for     end if next  if found then     response.write "ok"     response.end end if
登录后复制

要同时处理两种数据库内容格式,需修改如下:

Dim aa, ipList, ip, found, dbIPList aa = Request.ServerVariables("REMOTE_ADDR")  dbIPList = Rs("ip")  ' 增加一个去除双引号的操作,确保两种数据库内容格式都能正常处理 dbIPList = Replace(dbIPList, """, """)  ipList = Split(dbIPList, ",")  found = False  For Each ip In ipList     ip = Trim(ip)     If InStr(aa, ip) > 0 Then         found = True         Exit For     End If Next  If found Then     Response.Write "ok"     Response.End End If
登录后复制

以上就是如何改进IP地址匹配代码以支持多种数据库格式?的详细内容,更多请关注php中文网其它相关文章!

本文来自网络,不代表甲倪知识立场,转载请注明出处:http://www.spjiani.cn/wp/5961.html

作者: nijia

发表评论

您的电子邮箱地址不会被公开。

联系我们

联系我们

0898-88881688

在线咨询: QQ交谈

邮箱: email@wangzhan.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部