Ejemplo n.º 1
0
    def NATPMP(self, action):
        """
		Call NAT-PMP on router to get port 5500 forwarded.

		@author: Dennis Koot
		"""
        if sys.platform == 'darwin' or re.match('(?:open|free|net)bsd|linux',
                                                sys.platform):
            if self.enablePMP:
                if action == 'request':
                    lifetime = 3600
                    print "Request port 5500 (NAT-PMP)."
                else:
                    lifetime = 0
                    print "Give up port 5500 (NAT-PMP)."

                pubpriv_port = int(5500)
                protocol = NATPMP.NATPMP_PROTOCOL_TCP

                try:
                    gateway = NATPMP.get_gateway_addr()
                    print NATPMP.map_port(protocol,
                                          pubpriv_port,
                                          pubpriv_port,
                                          lifetime,
                                          gateway_ip=gateway)
                except:
                    print "Warning: Unable to automap port."
Ejemplo n.º 2
0
 def open(self, port, ptype = 'TCP', manual = False):
     # Supported?
     if not _natpmp_supported:
         return
     # Check
     if manual:
         self.map[ptype][port] = 1
     elif not self.map[ptype].has_key(port):
         return False
     # Map
     try:
         NATPMP.map_port(self.protocols[ptype], port, port, 3600)
     except NATPMP.NATPMPError, e:
         print "Error: NAT-PMP operation failed (port %d %s closed)." % (port, ptype), "Details:", e
         return False
Ejemplo n.º 3
0
	def NATPMP(self, action):
		"""
		Call NAT-PMP on router to get port 5500 forwarded.

		@author: Dennis Koot
		"""
		if sys.platform == 'darwin' or re.match('(?:open|free|net)bsd|linux',sys.platform):
			if self.enablePMP:
				if action == 'request':
					lifetime = 3600
					print "Request port 5500 (NAT-PMP)."
				else:
					lifetime = 0
					print "Give up port 5500 (NAT-PMP)."

				pubpriv_port = int(5500)
				protocol = NATPMP.NATPMP_PROTOCOL_TCP

				try:
					gateway = NATPMP.get_gateway_addr()
					print NATPMP.map_port(protocol, pubpriv_port, pubpriv_port, lifetime, gateway_ip=gateway)
				except:
					print "Warning: Unable to automap port."
Ejemplo n.º 4
0
 def remove_mapping(self, local_port, external_port, protocol):
     NATPMP.map_port(protocol_from_string(protocol), external_port, local_port, lifetime=0)
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 def external_ip(self):
     external_ip = NATPMP.get_public_address()
     self.logger.info('ip: {0}'.format(external_ip))
     return external_ip
Ejemplo n.º 7
0
 def remove_mapping(self, local_port, external_port, protocol):
     NATPMP.map_port(protocol_from_string(protocol), external_port, local_port, lifetime=0)
Ejemplo n.º 8
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
Ejemplo n.º 9
0
 def external_ip(self):
     external_ip = NATPMP.get_public_address()
     self.logger.info('ip: {0}'.format(external_ip))
     return external_ip