示例#1
0
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)
示例#2
0
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
示例#3
0
文件: client.py 项目: jaraco/nat-pmp
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)
示例#4
0
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)
示例#5
0
 def remove_mapping(self, local_port, external_port, protocol):
     natpmp.map_port(protocol_from_string(protocol), external_port, local_port, lifetime=0)
示例#6
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