Submitted By: Sean D. Wheeler
Leverages Netstat.exe to determine the executable files using the ports on a computer. Requires Windows XP or later.
set fso = createobject("scripting.filesystemobject") set sh = createobject("wscript.shell") set net = createobject("wscript.network") set oExec = sh.exec ("tasklist") do while not oExec.stdout.atendofstream line = oExec.stdout.readline if (trim(left(line,25)) <> "Image Name") and (trim(left(line,25)) <> "=========================") then processes = processes & ucase(trim(left(line,25))) & "," PIDs = PIDs & trim(mid(line,27,6)) & "," end if loop PID = split(PIDs,",") Process = split(processes,",") set oExec = sh.exec ("netstat -ano") do while not oExec.stdout.atendofstream line = oExec.stdout.readline if (trim(left(line,5)) <> "TCP") and (trim(left(line,5)) <> "UDP") then wscript.echo line else netpid = trim(right(line,6)) for x = 0 to ubound(PID) if netpid = PID(x) then exit for next if x <= ubound(PID) then wscript.echo line & vbtab & Process(x) else wscript.echo line end if end if loop
set fso = createobject("scripting.filesystemobject") set sh = createobject("wscript.shell") set net = createobject("wscript.network") set oExec = sh.exec ("tasklist") do while not oExec.stdout.atendofstream line = oExec.stdout.readline if (trim(left(line,25)) <> "Image Name") and (trim(left(line,25)) <> "=========================") then processes = processes & ucase(trim(left(line,25))) & "," PIDs = PIDs & trim(mid(line,27,6)) & "," end if loop PID = split(PIDs,",") Process = split(processes,",") set oExec = sh.exec ("netstat -ano") do while not oExec.stdout.atendofstream line = oExec.stdout.readline if (trim(left(line,5)) <> "TCP") and (trim(left(line,5)) <> "UDP") then wscript.echo line else netpid = trim(right(line,6)) for x = 0 to ubound(PID) if netpid = PID(x) then exit for next if x <= ubound(PID) then wscript.echo line & vbtab & Process(x) else wscript.echo line end if end if loop