如何使用VB脚本检查远程服务器上的端口状态 [英] How to check the Ports Status on a remote server using VB Script
本文介绍了如何使用VB脚本检查远程服务器上的端口状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
任何人都可以帮我解决如何使用VB脚本检查远程服务器上的端口状态(打开和启用)
任何形式的帮助都非常值得......
Thnx
-FH
Hello Friends,
Can any body help me out in "how to check the Ports Status (opened & enabled) on a remote server using VB Script
Any sort of help is highly appreciable.....
Thnx
-FH
推荐答案
嗨
i认为这段代码工作正常,但它有循环来检查我无法接受的状态,但我不能用vbs同时我认为我们不能做其他事情,因为我们无法收到vbs中的事件
''VBScript源代码
函数CheckPort( Byval Server,Byval Port)
Dim SockObject
set SockObject = CreateObject(" MSWinsock.Winsock.1")
SockObject.Protocol = 0''TCP
调用SockObject.Close
调用SockObject.Connect(服务器,端口)
while((SockObject.State = 6)或(SockObject.State = 3))''套接字状态<>连接或连接待定
''什么都不做
wend
if(SockObject.State = 7)然后''如果socket连接
msgbox" Port OPen"
msgbox"错误"
elseif(SockObject.State = 0)然后''关闭
msgbox"连接被拒绝>
结束如果
调用SockObject。关闭
设置SockObject =无
结束功能
呼叫CheckPort(服务器,445)
和plz考虑到你的想法Winsock COM Class只安装了vb6组件,你不会在没有vb6组件的PC中找到它
最好的问候
hi
i think this code work well but it have loop to check for state that i cant accept but im not good in vbs and in same time i think we cant do other thing because we cant receve events in vbs
'' VBScript source code
Function CheckPort(Byval Server,Byval Port)
Dim SockObject
set SockObject=CreateObject("MSWinsock.Winsock.1")
SockObject.Protocol=0 '' TCP
Call SockObject.Close
Call SockObject.Connect (Server,Port)
while ((SockObject.State=6) or (SockObject.State=3)) ''socket state <> connecting or connection pending
''do nothing
wend
if(SockObject.State=7) then '' if socket connected
msgbox "Port OPen"
elseif(SockObject.State=9)then'' If Error
msgbox "error"
elseif(SockObject.State=0)then ''Closed
msgbox "connection refused"
end if
call SockObject.Close
set SockObject=nothing
End Function
Call CheckPort("Server",445)
and plz take in ur mind Winsock COM Class is only installed with vb6 component and u will not find it in PC that not have vb6 components
Best Regards
感谢Ahmed,
逻辑正是我想要的,但我认为这不能完全解决我的问题,我需要在我的所有目标或远程服务器上安装VB6我需要运行此代码(这是我不能做的),a nyways我得到这个错误
Microsoft VBScript运行时错误:ActiveX组件无法创建对象:''MSWinsock.Winsock.1''
有没有其他方法可以获得这些信息
Thnx一百万
FH
Thanks Ahmed,
The logic is exactly what Iwant but I think this will not completely solve my problem, I need to install VB6 on all my target or remote servers on which I need to run this code (and this I cannot do), anyways I am getting this errror
Microsoft VBScript runtime error: ActiveX component can''t create object: ''MSWinsock.Winsock.1''
is there any other way to get this info
Thnx a million
FH
艾哈迈德,
结束了,我有这个代码,但这仅限于检查端口在本地机器上的状态,无法在远程服务器上执行
################ CODE ##################
设置objFirewall = CreateObject(" HNetCfg.FwMgr")
设置objPolicy = objFirewall.LocalPolicy.CurrentProfile
设置colPorts = objPolicy.GloballyOpenPorts
对于colPorts中的每个objPort
Wscript.Echo"端口名称:" &安培; objPort.Name
Wscript.Echo" Port number:" &安培; objPort.Port
Wscript.Echo" Port protocol:" &安培; objPort.Protocol
Wscript.Echo" Port enabled:" &安培; objPort.Enabled
下一步
Ahmed,
More over, I have this code, but this is limited to check the ports'' status on local machine, cannot be executed on a remote server
################ CODE ##################
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
Set colPorts = objPolicy.GloballyOpenPorts
For Each objPort in colPorts
Wscript.Echo "Port name: " & objPort.Name
Wscript.Echo "Port number: " & objPort.Port
Wscript.Echo "Port protocol: " & objPort.Protocol
Wscript.Echo "Port enabled: " & objPort.Enabled
Next
这篇关于如何使用VB脚本检查远程服务器上的端口状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文