用vbscript来添加ip策略 自动封IP

(编辑:jimmy 日期: 2025/5/13 浏览:2)

程序主要是读取这个网站的iis日志,分析出其中的IP地址,用安全策略自动封闭。VBS代码如下:
复制代码 代码如下:
  '代码开始

  Set fileobj=CreateObject("Scripting.filesystemobject")
  logfilepath="E:w3logW3SVC237ex070512old.log" '注意指定受攻击网站的日志路径。
  '如果是虚拟主机,要查是哪个网站受攻击,可以查看:C:WINDOWSsystem32LogFilesHTTPERR ,

  根据错误日志很容易分析出来。
  writelog "netsh ipsec static add policy name=XBLUE"
  writelog "netsh ipsec static add filterlist name=denyip"

  overip=""
  f_name=logfilepath
  '指定日志文件

  '程序功能:把logfiles中的IP提取成ipsec需要的过滤格式,导入ipsec中过滤。适合某个网站受大量CC攻击的情况。

  set fileobj88=CreateObject("Scripting.FileSystemObject")
  Set MYFILE=fileobj88.OpenTextFile(f_name,1,false)
  contentover=MYFILE.ReadAll()
  contentip=lcase(contentover)
  MYFILE.close
  set fileobj88=nothing
  on error resume next
  myline=split(contentip,chr(13))
  for i=0 to ubound(myline)-1

  myline2=split(myline(i)," ")
  newip=myline2(6)
  '指定分离的标识字符串!
  if instr(overip,newip)=0 then '去除重复的IP。
  overip=overip&newip
  dsafasf=split(newip,".")
  if ubound(dsafasf)=3 then
  writelog "netsh ipsec static add filter filterlist=denyip srcaddr="&newip&" dstaddr=Me

  dstport=80 protocol=TCP"
  end if
  else
  wscript.echo newip &" is exits!"
  end if
  next
  writelog "netsh ipsec static add filteraction name=denyact action=block"
  writelog "netsh ipsec static add rule name=kill3389 policy=XBLUE filterlist=denyip

  filteraction=denyact"
  writelog "netsh ipsec static set policy name=XBLUE assign=y"


  Sub writelog(errmes) '导出IPsec的策略文件为一个bat文件。
  ipfilename="denyerrorip.bat"
  Set logfile=fileobj.opentextfile(ipfilename,8,true)
  logfile.writeline errmes
  logfile.close
  Set logfile=nothing
  End Sub

  '代码结束

  把上述代码存为一个.vbs文件,设置好其中日志的路径。双击运行即可,运行完毕后生成一个denyerrorip.bat文件,这个是ipsec所需要的策略文件,直接双击运行即可。
一句话新闻
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?