列出所有到本机80端口ESTABLISHED连接的小脚本

朋友需要,我搞了个脚本出来玩,直接运行netstat -an取得输出用正则匹配。

Dim oShell
Dim oExec
Dim strOut
Dim oRegExp
Dim Matches
Dim Match
Dim Num

Set oShell = WScript.CreateObject("WScript.Shell")
Set oExec = oShell.Exec("netstat -an")
Set oRegExp = new RegExp
oRegExp.Pattern 
= "TCP[\s]+[\d\.]+:80[\s]+[\d\.]+:[\d]+[\s]+ESTABLISHED"
oRegExp.IgnoreCase 
= True
oRegExp.Global 
= True

Do While Not oExec.StdOut.AtEndOfStream
    strOut 
= strOut & oExec.StdOut.ReadLine() & Chr(13& Chr(10)
Loop

Set Matches = oRegExp.Execute(strOut)

Num 
= 0
For Each Match In Matches
    WScript.Echo Match.Value
    Num 
= Num + 1
Next

WScript.Echo 
"合计:共" & Num & "个连接"

Set Matches = Nothing
Set oRegExp = Nothing
Set oExec = Nothing
Set oShell = Nothing
原文地址:https://www.cnblogs.com/luoluo/p/301947.html