正则表达式检查来访IP是否合法的实际应用

时间:2022-08-14 20:20:39

正则表达式检查来访IP是否合法的实际应用

  1. sub chkIP(boardid) 
  2. dim rsIP 
  3. dim ipArr 
  4. dim ignored 
  5. dim i 
  6. dim ip 
  7. dim sql  
  8. ip=Request.ServerVariables("REMOTE_ADDR")  
  9. ignored=false 
  10. if not isempty(boardid) then  
  11. sql="select ignoreip from board where boardid="&cstr(boardid) 
  12. set rsIP=conn.execute(sql) 
  13. if not (rsIP.eof and rsIP.bof) then  
  14. if instr(cstr(rsIP("ignoreip")&""),chr(13)&chr(10)) then  
  15. iparr=split(rsIP("ignoreip"),chr(13)&chr(10)) 
  16. for i=0 to ubound(iparr) 
  17. if trim(iparr(i))<>"" and left(ip,len(trim(iparr(i))))=trim(iparr(i)) then  
  18. ignored=true 
  19. exit for 
  20. end if 
  21. next 
  22. else 
  23. iparr=rsIP("ignoreip"
  24. if ip=trim(iparr) then  
  25. ignored=true 
  26. end if 
  27. end if 
  28. end if 
  29. rsIP.close 
  30. end if 
  31. if ignored then  
  32. response.write "<script language=javascript>window.location.href='ignoreip.htm'</script>" 
  33. end if 
  34. end sub