Annotation of embedaddon/miniupnpc/pymoduletest.py, revision 1.1.1.1

1.1       misho       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: 
                      7: # import the python miniupnpc module
                      8: import miniupnpc
                      9: import sys
                     10: 
                     11: # create the object
                     12: u = miniupnpc.UPnP()
                     13: print 'inital(default) values :'
                     14: print ' discoverdelay', u.discoverdelay
                     15: print ' lanaddr', u.lanaddr
                     16: print ' multicastif', u.multicastif
                     17: print ' minissdpdsocket', u.minissdpdsocket
                     18: u.discoverdelay = 200;
                     19: #u.minissdpdsocket = '../minissdpd/minissdpd.sock'
                     20: # discovery process, it usualy takes several seconds (2 seconds or more)
                     21: print 'Discovering... delay=%ums' % u.discoverdelay
                     22: print u.discover(), 'device(s) detected'
                     23: # select an igd
                     24: try:
                     25:   u.selectigd()
                     26: except Exception, e:
                     27:   print 'Exception :', e
                     28:   sys.exit(1)
                     29: # display information about the IGD and the internet connection
                     30: print 'local ip address :', u.lanaddr
                     31: print 'external ip address :', u.externalipaddress()
                     32: print u.statusinfo(), u.connectiontype()
                     33: 
                     34: #print u.addportmapping(64000, 'TCP',
                     35: #                       '192.168.1.166', 63000, 'port mapping test', '')
                     36: #print u.deleteportmapping(64000, 'TCP')
                     37: 
                     38: port = 0
                     39: proto = 'UDP'
                     40: # list the redirections :
                     41: i = 0
                     42: while True:
                     43:        p = u.getgenericportmapping(i)
                     44:        if p==None:
                     45:                break
                     46:        print i, p
                     47:        (port, proto, (ihost,iport), desc, c, d, e) = p
                     48:        #print port, desc
                     49:        i = i + 1
                     50: 
                     51: print u.getspecificportmapping(port, proto)
                     52: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>