用于检查 Windows 中端口可用性的 VBS 脚本 [英] VBS Script to Check Port Availability in Windows

查看:159
本文介绍了用于检查 Windows 中端口可用性的 VBS 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查某个软件的先决条件.我有一组脚本可以检查磁盘空间、内存可用性等内容.

I am trying to check preconditions for a certain piece of software. I have a set of scripts that goes through and checks for things such as disk space, memory availability, etc.

我需要创建一个脚本来检查某些端口是否打开并可访问.我正在使用 WMI 检查其他网络配置项,但找不到任何检查端口可用性的参考.

I need to create a script that can check if certain ports are open and accessible. I am using the WMI to check other network configuration items, but cannot find any references to checking port availability.

任何人都知道我可以在哪里找到 WMI 构造来让我查看和管理端口,或者任何其他关于如何构建新脚本以检查端口可用性的想法?

Anyone have any ideas where I can find a WMI construct to let me view and manage ports or any other ideas for how to structure a new script to check port availability?

推荐答案

所以我找到了一个有人不久前制作的脚本.它使用 netStat.应该可以在任何 Windows 机器上工作.我想我被使用 WMI 的欲望蒙蔽了双眼.

So I found a script someone had made a while back. It uses netStat. Should work on just about any windows machine. I think I was blinded by my desire to use the WMI.

Sub PortMonitor (strCommand2)

  Set StdOut = WScript.StdOut
  Set objShell = CreateObject("WScript.Shell")
  set objScriptExec = objShell.Exec (strCommand2)

  strPingResults = LCase(objScriptExec.StdOut.ReadAll)

  if len (strPingResults) > 0 then
     WScript.Echo "Established!"
  End if
end Sub

Dim strcommand
strCommand = "cmd /C ""netStat -n |find ""127.0.0.1:1137"" | find ""ESTABLISHED"""""
Call PortMonitor (strCommand)

操作:http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_27476065.html#

这篇关于用于检查 Windows 中端口可用性的 VBS 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆