On Error Resume Next
' 创建一个WbemLocator对象
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if Err.Number Then
WScript.Echo "Message:" & Err.Description
WScript.Quit(1)
End If
Select Case WScript.Arguments.Count
Case 3
strComputer = Wscript.Arguments(0)
strUsername = Wscript.Arguments(1)
strPassword = Wscript.Arguments(2)
Set wbemServices = objWbemLocator.ConnectServer(strComputer, "Root\CIMV2", strUsername, strPassword)
Case Else
WScript.Echo "Message: Error in number of parameters passed"
WScript.Quit(1)
End Select
If Err.Number Then
WScript.Echo "Message:" & Err.Description
WScript.Quit(1)
End If
' 指定要检查的端口范围
intStartPort = 1
intEndPort = 65535
' 检查每个端口是否开放
For intPort = intStartPort to intEndPort
' 创建一个TCP连接对象
Set objTCP = CreateObject("MSWinsock.Winsock")
' 设置超时时间为1秒
objTCP.ReceiveTimeout = 1000
' 尝试连接端口
objTCP.Connect(strComputer, intPort)
' 检查连接状态
If objTCP.State = 7 Then
strPortStatus = "Open"
Else
strPortStatus = "Closed"
End If
' 输出端口状态
WScript.Echo "Port " & intPort & ": " & strPortStatus
' 关闭TCP连接
objTCP.Close
Next
WScript.Quit(0)