Python: Open a Listening Port Behind a Router (upnp?)

后端 未结 5 889
长发绾君心
长发绾君心 2020-12-25 14:16

I\'ve developed an application that is essentially just a little ftp server with the ability to specify which directory you wish to share on startup. I\'m using ftplib for t

5条回答
  •  佛祖请我去吃肉
    2020-12-25 14:48

    Simple example for miniupnp. It creates a mapping on the discovered gateway from external port 43210 to the interface connected to port 43210 on the interface connected to the discovered gateway.

    import miniupnpc
    
    upnp = miniupnpc.UPnP()
    
    upnp.discoverdelay = 10
    upnp.discover()
    
    upnp.selectigd()
    
    port = 43210
    
    # addportmapping(external-port, protocol, internal-host, internal-port, description, remote-host)
    upnp.addportmapping(port, 'TCP', upnp.lanaddr, port, 'testing', '')
    

提交回复
热议问题