need more coffee
COMate - control COM objects via automation - OBSOLETE!
LoL
nope, the below is only supposed to return information for globally open ports and doesn't change anything, just collects info:
and this is the original code:
Code: Select all
#NET_FW_IP_PROTOCOL_TCP = 6 ; for TCP ports
Protected objFirewall.COMateObject
Protected objPolicy.COMateObject
Protected colPorts.COMateObject
Protected objPort.ComateObject
objFirewall = COMate_CreateObject("HNetCfg.FwMgr")
objPolicy = objFirewall\GetObjectProperty("LocalPolicy()\CurrentProfile()")
colPorts = objPolicy\GetObjectProperty("GloballyOpenPorts()")
count = colPorts\GetIntegerProperty("Count()")
;seems to be working to here OK - count returns 38 ports which is correct per manual count
for I = 0 to count
objPort = colPorts\GetObjectProperty("Item(" + Str(I) + ", " + Str(#NET_FW_IP_PROTOCOL_TCP) + ")")
; the rest goes here
Next
objFirewall\Release()
Code: Select all
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 IP version: " & objPort.IPVersion
Wscript.Echo "Port protocol: " & objPort.Protocol
Wscript.Echo "Port scope: " & objPort.Scope
Wscript.Echo "Port remote addresses: " & objPort.RemoteAddresses
Wscript.Echo "Port enabled: " & objPort.Enabled
Wscript.Echo "Port built-in: " & objPort.Builtin
Next
To manually add a port you have to do it in the firewall interface its self. I do have a script that will progmatically add it if thats what you want? But were not adding ports here, just enumerating whats already there and getting info.srod wrote:I get a count of zero open global ports here!!! How do I manually add a port?
However, you do want For I = 0 to Count -1 do you not?
I don't think I = 0 to Count -1 is correct in this case, it doesn't work that way with the existing vbs script and throws an error. besides the count would start at -1 instead of 0 then.
it returns 38 ports here, which is correct for this setup because there are actually 38 global open ports. So I tend to think this part at least is correct because the manual count says its 38 and it returns the same with the .vbs as well which I already know works properly.
Last edited by SFSxOI on Tue Mar 31, 2009 2:18 pm, edited 2 times in total.
Well if count is 0 then I would have thought that you would not want the loop to run; which is what For I = 0 to count-1 will ensure.
With no ports added then there is no way I can test the code; although I still think that you may need to create an enumeration etc.
With no ports added then there is no way I can test the code; although I still think that you may need to create an enumeration etc.
I may look like a mule, but I'm not a complete ass.
Actually you do want the loop to run in this case I think because port 0 always exists even though it doesn't do anything, but for a firewall there is always a port 0. But I just tried the -1 and indeed the loop doesn't run which makes sense, but when the loop does run there is still the problem with objPort. So I know the ports exist and are in the collection already in GloballyOpenPorts() which is the collection, and I know they are there because the count tells me so. You think the COMate enum functions are needed here?
Last edited by SFSxOI on Tue Mar 31, 2009 2:31 pm, edited 1 time in total.
Thats odd, I still get the 'One or more arguments are invalid' thingsrod wrote:Okay, have added a port and it is being picked up.... let's have a look at this code then...
I am getting a general exception error with the objPort = colPorts\GetObjectProperty("Item(" + Str(I) + ", " + Str(#NET_FW_IP_PROTOCOL_TCP) + ")") line.
The following works here :
**EDIT : sorry, if I had looked at the VB Script which you posted then I would have been absolutely definite from the beginning that you needed to use COMate's enumeration functions etc!
Code: Select all
IncludePath "..\"
XIncludeFile "COMate.pbi"
Global objExcel.COMateObject
#NET_FW_IP_PROTOCOL_TCP = 6 ; for TCP ports
Define objFirewall.COMateObject
Define objPolicy.COMateObject
Define colPorts.COMateEnumObject
Define objPort.ComateObject
objFirewall = COMate_CreateObject("HNetCfg.FwMgr")
If objFirewall
objPolicy = objFirewall\GetObjectProperty("LocalPolicy()\CurrentProfile()")
If objPolicy
colPorts = objPolicy\CreateEnumeration("GloballyOpenPorts()")
If colPorts
objPort = colPorts\GetNextObject()
While objPort
Debug objPort\GetStringProperty("Name")
objPort\Release()
objPort = colPorts\GetNextObject()
Wend
colPorts\Release()
EndIf
objPolicy\Release()
EndIf
objFirewall\Release()
EndIf
I may look like a mule, but I'm not a complete ass.
hmmmm...strange...doesn't work here, nothing returned in the Debug objPort\GetStringProperty("Name")srod wrote:The following works here :
Code: Select all
IncludePath ".." XIncludeFile "COMate.pbi" Global objExcel.COMateObject #NET_FW_IP_PROTOCOL_TCP = 6 ; for TCP ports Define objFirewall.COMateObject Define objPolicy.COMateObject Define colPorts.COMateEnumObject Define objPort.ComateObject objFirewall = COMate_CreateObject("HNetCfg.FwMgr") If objFirewall objPolicy = objFirewall\GetObjectProperty("LocalPolicy()\CurrentProfile()") If objPolicy colPorts = objPolicy\CreateEnumeration("GloballyOpenPorts()") If colPorts objPort = colPorts\GetNextObject() While objPort Debug objPort\GetStringProperty("Name") objPort\Release() objPort = colPorts\GetNextObject() Wend colPorts\Release() EndIf objPolicy\Release() EndIf objFirewall\Release() EndIf
You using Vista or XP?

