[python-win32] Using win32com to access uPNP
George Gonzalez
ggonzalez at austin.rr.com
Fri Dec 9 02:57:18 CET 2005
I had the same problem. I discovered that I needed to upgrade my
router's firmware. This added an icon for my router in "network
places." At this point though, double clicking on it gave me an error
saying the "device you are currently trying to use is not currently
available on your network" I then went through the network setup
wizard. It all works now. Note that this will only work if your router
is nPnP compatible. If it's not then you'll probably still get
mappingPorts=None. Here's my python terminal output:
>>> theNatter = win32com.client.Dispatch("HNetCfg.NATUPnP")
>>> print theNatter
<COMObject HNetCfg.NATUPnP>
>>> mappingPorts = theNatter.StaticPortMappingCollection
>>> print mappingPorts
<COMObject <unknown>>
>>> mappingPorts.Add(1024, "TCP", 1024, "192.168.1.101", True, "IRC")
<COMObject Add>
>>>
>>> listPorts(mappingPorts)
0: True FTP 21 <router ip> TCP 192.168.1.100 21
1: False Telnet 23 <router ip> TCP 192.168.1.0 23
2: False SMTP 25 <router ip> TCP 192.168.1.0 25
3: False DNS 53 <router ip> UDP 192.168.1.0 53
4: False TFTP 69 <router ip> UDP 192.168.1.0 69
5: False finger 79 <router ip> TCP 192.168.1.0 79
6: False HTTP 80 <router ip> TCP 192.168.1.0 80
7: False POP3 110 <router ip> TCP 192.168.1.0 110
8: False NNTP 119 <router ip> TCP 192.168.1.0 119
9: False SNMP 161 <router ip> UDP 192.168.1.0 161
10: True IRC 1024 <router ip> TCP 192.168.1.101 1024
The original script is in the link below. The current version has a
typo. You'll needed to change "mps[ii]" to "mappingPorts[ii]."
http://icepick.info/python
-George
>I saw this on the internet & am having a similar problem - I think. I'm not a technical person, but have worked out that the script I am running errors ->"Object Required" when it reaches the first line that uses mappingports.
>
>Did you manage to fix this - if so please help! I have tried Microsoft & Netgear but nobody seems to want to help.
>
>Thank you,
>Gavin
>
>
>Your message:
>
>
>>Hi --
>>
>>I'm trying to use the interface in win32com to access the windows uPNP
>>service, the code is as follows:
>>
>>import win32com.client
>>
>>theNatter = win32com.client.Dispatch("HNetCfg.NATUPnP")
>>
>>mappingPorts = theNatter.StaticPortMappingCollection
>>
>>At this point mappingPorts seems to contain the null object, so it would
>>appear that theNatter doesn't have an attribute StaticPortMappingCollection
>>though the msdn docs claim otherwise.
>>
>>Also, i notice there are a number of interfaces common to HNetCfg.dll and
>>NATUPnP - how does the above code differntiate between them ?
>>
More information about the Python-win32
mailing list