2
0

pymoduletest.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #! /usr/bin/python
  2. # MiniUPnP project
  3. # Author : Thomas Bernard
  4. # This Sample code is public domain.
  5. # website : http://miniupnp.tuxfamily.org/
  6. # import the python miniupnpc module
  7. import miniupnpc
  8. import sys
  9. # create the object
  10. u = miniupnpc.UPnP()
  11. print 'inital(default) values :'
  12. print ' discoverdelay', u.discoverdelay
  13. print ' lanaddr', u.lanaddr
  14. print ' multicastif', u.multicastif
  15. print ' minissdpdsocket', u.minissdpdsocket
  16. u.discoverdelay = 200;
  17. #u.minissdpdsocket = '../minissdpd/minissdpd.sock'
  18. # discovery process, it usualy takes several seconds (2 seconds or more)
  19. print 'Discovering... delay=%ums' % u.discoverdelay
  20. print u.discover(), 'device(s) detected'
  21. # select an igd
  22. try:
  23. u.selectigd()
  24. except Exception, e:
  25. print 'Exception :', e
  26. sys.exit(1)
  27. # display information about the IGD and the internet connection
  28. print 'local ip address :', u.lanaddr
  29. print 'external ip address :', u.externalipaddress()
  30. print u.statusinfo(), u.connectiontype()
  31. #print u.addportmapping(64000, 'TCP',
  32. # '192.168.1.166', 63000, 'port mapping test', '')
  33. #print u.deleteportmapping(64000, 'TCP')
  34. port = 0
  35. proto = 'UDP'
  36. # list the redirections :
  37. i = 0
  38. while True:
  39. p = u.getgenericportmapping(i)
  40. if p==None:
  41. break
  42. print i, p
  43. (port, proto, (ihost,iport), desc, c, d, e) = p
  44. #print port, desc
  45. i = i + 1
  46. print u.getspecificportmapping(port, proto)