How to write a VBA code to check whether TCP port (e.g.3306) isblocked or not?

  • Thread starter Thread starter SOS
  • Start date Start date
S

SOS

Hi,

Can anyone please help me to find out a way to check whether a local TCP Outbound/Inbound blocked or not? Many thanks in advance!

Best regards
Ratheesh
 
Hi Garry,

Thanks for your help! goes a very long way.

Finally I found a way to get the TCP port status, I hope this would help someone.

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
Set objPort = CreateObject("HNetCfg.FwOpenPort")

objPort.Port = YourPortNumber

Then check whether it is enabled or not - objPort.Enabled

Hope this will help

Best regards
Ratheesh
 
Or simply...


Function IsTcpEnabled(Optional PortNum&) As Boolean
If PortNum = 0 Then PortNum = 119 '//edit to actual
With CreateObject("HNetCfg.FwOpenPort")
.Port = PortNum: IsTcpEnabled = .Enabled
End With
End Function

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Note that this only 'assigns' a port#, and returns whether or not that
port# is enabled. It does not tell you if an existing port# on
'localhost' is enabled!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Ok.
Actually I need to check the Incoming Port 3306(MySQL) to get a key. If that disabled, I need to open the port for a limited time and get the information.

Many thanks!
Ratheesh
 
Back
Top