def main(): if len(sys.argv) < 3: print( "usage: natpmp-client.py [-u] [-l lifetime] [-g gateway_addr] public_port private_port" ) sys.exit(-1) opts, args = getopt.getopt(sys.argv[1:], "ul:g:") public_port = int(args[0]) private_port = int(args[1]) protocol = NATPMP.NATPMP_PROTOCOL_TCP lifetime = 3600 gateway = None for opt in opts: name, val = opt if name == "-u": protocol = NATPMP.NATPMP_PROTOCOL_UDP elif name == "-l": lifetime = int(val) elif name == "-g": gateway = val if not gateway: gateway = NATPMP.get_gateway_addr() print NATPMP.map_port(protocol, public_port, private_port, lifetime, gateway_ip=gateway)
def period_upnp(): public_port1 = 8621 private_port1 = 8621 public_port2 = 8888 private_port2 = 8888 protocol = NATPMP.NATPMP_PROTOCOL_TCP lifetime = int(3600) gateway = NATPMP.get_gateway_addr() print >>sys.stderr,time.asctime(),'-', "NatPMP: gateway=", gateway if gateway: resp1 = NATPMP.map_port(protocol, public_port1, private_port1, lifetime, gateway_ip=gateway, use_exception=False) if resp1: print >>sys.stderr,time.asctime(),'-', "NatPMP: ", resp1 resp2 = NATPMP.map_port(protocol, public_port2, private_port2, lifetime, gateway_ip=gateway, use_exception=False) print >>sys.stderr,time.asctime(),'-', "NatPMP: ", resp2
def main(): args = get_args() res = natpmp.map_port( args.protocol, args.public_port, args.private_port, args.lifetime, gateway_ip=args.gateway or natpmp.get_gateway_addr(), ) print(res)
def main(): if len(sys.argv) < 3: print("usage: natpmp-client.py [-u] [-l lifetime] [-g gateway_addr] public_port private_port") sys.exit(-1) opts, args = getopt.getopt(sys.argv[1:], "ul:g:") public_port = int(args[0]) private_port = int(args[1]) protocol = NATPMP.NATPMP_PROTOCOL_TCP lifetime = 3600 gateway = None for opt in opts: name, val = opt if name == "-u": protocol = NATPMP.NATPMP_PROTOCOL_UDP elif name == "-l": lifetime = int(val) elif name == "-g": gateway = val if not gateway: gateway = NATPMP.get_gateway_addr() print NATPMP.map_port(protocol, public_port, private_port, lifetime, gateway_ip=gateway)
def remove_mapping(self, local_port, external_port, protocol): natpmp.map_port(protocol_from_string(protocol), external_port, local_port, lifetime=0)
def add_mapping(self, local_port, external_port, protocol): response = natpmp.map_port(protocol_from_string(protocol), external_port, local_port) return response.public_port