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

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
 
R

Ratheesh Panakkil

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
 
G

GS

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
 
G

GS

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
 
S

SOS

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top