Python Forum

Full Version: Can't see my UPnP Opened Ports
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Interesting situation - apologies for the long Preface:
After setting Port Forwards via UPnP on a Google Fiber modem, the modem decided to ignore them after a few days. The ports were still listed using MiniUPnPC (upnpc -l , in Linux), but I could not connect to them and did not show up as 'Open' using various Port Testing Web tools.
Once I deleted them and recreated them, they became 'active', I could connect and they showed as 'Open' on the Port Testing Web sites.

The Code:
So I found this very nice little Python code to test Ports:
import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)                                      #2 Second Timeout
result = sock.connect_ex(('xxx.xxx.xxx.xxx',yyyyy))
if result == 0:
  print 'port OPEN'
else:
  print 'port CLOSED, connect_ex returned: '+str(result)
And tried it on the Google Modem I was behind.
Oddly, those Ports Opened Manually through Google's Admin Web interface returned 'port OPEN', while those opened via UPnP always showed 'port CLOSED, connect_ex returned: 111'.
Testing from another location (not behind the Google Fiber modem, the above code worked correctly for both Manually opened Ports and those opened via UPnP.

Finally to my Question:
I need to be able to test if a given port is actually open from behind the Google Fiber modem, and then delete/add it again if not. Is there something wrong with the above code to do this, or another way to test, or perhaps a setting in Google Fiber modem that I missed?

Sorry if this is not appropriate for this forum. It covers so many different areas, I'm not sure where to post it...

Thank you for your time.