当前位置: 首页>>代码示例>>Python>>正文


Python miniupnpc.UPnP方法代码示例

本文整理汇总了Python中miniupnpc.UPnP方法的典型用法代码示例。如果您正苦于以下问题:Python miniupnpc.UPnP方法的具体用法?Python miniupnpc.UPnP怎么用?Python miniupnpc.UPnP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在miniupnpc的用法示例。


在下文中一共展示了miniupnpc.UPnP方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def __init__(self):
        self.upnp = miniupnpc.UPnP()

        self.debug('inital(default) values :')
        self.debug_upnp_values()
        self.upnp.discoverdelay = 200
        self.debug('Discovering... delay=%ums' % self.upnp.discoverdelay)
        self.debug(self.upnp.discover(), 'device(s) detected')

        try:
            self.upnp.selectigd()
            self.upnp_device_available = True
        except Exception as exc:
            print 'Exception :', exc
            self.upnp_device_available = False
            return

        # display information about the IGD and the internet connection
        self.debug_addresses()
        self.debug("Status Info:", self.get_status_info())
        self.debug("Connection Type:", self.get_connection_type())
        self.debug_upnp_values() 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:24,代码来源:upnp.py

示例2: get_upnp_devices

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def get_upnp_devices():
    # Check if UPNP is available and set port forwarding
    upnpc = miniupnpc.UPnP()

    # Discover UPNP devices
    upnpc.discoverdelay = 200

    if debug:
        print 'Check UPNP Support'

    try:
        ndevices = upnpc.discover()
        if debug:
            print ' %d UPNP device(s) detected' % (ndevices)

        if ndevices:
            upnpc.selectigd()
            return upnpc
    except Exception:
        if debug:
            print ' No appropriate UPNP device available'
        return None 
开发者ID:usableprivacy,项目名称:upribox,代码行数:24,代码来源:port_forward.py

示例3: upnp_start

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def upnp_start(self):
        try:
            u = miniupnpc.UPnP()
            u.discoverdelay = 200
            logging.info("Scanning for UPnP devices")
            if u.discover() > 0:
                logging.info("Device discovered")
                u.selectigd()
                if self.ipv6 == "" and self.ip != struct.unpack("!I", socket.inet_aton(u.externalipaddress()))[0]:
                    logging.warning(
                        "Mismatched external address, more than one layers of NAT? UPnP may not work.")
                self.upnp_mapping(u)
            else:
                logging.error("No UPnP devices discovered")
        except Exception:
            logging.error("Error arose in UPnP discovery") 
开发者ID:projectarkc,项目名称:arkc-client,代码行数:18,代码来源:coordinator.py

示例4: upnp_mapping

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def upnp_mapping(self, u):
        # Try to map ports via UPnP
        try:
            r = u.getspecificportmapping(self.remote_port, 'TCP')
            if r is None:
                b = u.addportmapping(self.remote_port, 'TCP', u.lanaddr,
                                     self.remote_port, 'ArkC Client port %u' % self.remote_port, '')
                if b:
                    logging.info("Port mapping succeed")
                    atexit.register(self.exit_handler, upnp_obj=u)
            elif r[0] == u.lanaddr and r[1] == self.remote_port:
                logging.info("Port mapping already existed.")
            else:
                logging.warning(
                    "Remote port " + str(self.remote_port) + " occupied in UPnP mapping")
                if self.remote_port <= 60000:
                    self.remote_port += 1
                logging.warning(
                    "Original remote port used. Retrying with port switched to " + str(self.remote_port))
                self.upnp_mapping(u)

        except Exception:
            logging.error("Error arose when initializing UPnP") 
开发者ID:projectarkc,项目名称:arkc-client,代码行数:25,代码来源:coordinator.py

示例5: forward_all

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def forward_all(self):
        """
            This method deletes all forwards and then re-creates them if possible.
        """

        if self.delete_all():
            for portinfo in self.PORTS:
                port, proto, game = portinfo

                if isinstance(port, list):
                    self._logger.info("Trying to create UPnP port mapping for {} ({}-{}/{})".format(game, port[0], port[-1], proto))

                    for p in port:
                        try:
                            self._upnp.addportmapping(p, proto, self._dreamcast_ip, p, "DreamPi: {}".format(game), '')
                        except Exception as e:
                            self._logger.warn("Could not create UPnP port mapping for {} ({}/{}): {}".format(game, p, proto, e))
                else:
                    self._logger.info("Trying to create UPnP port mapping for {} ({}/{})".format(game, port, proto))

                    try:
                        self._upnp.addportmapping(port, proto, self._dreamcast_ip, port, "DreamPi: {}".format(game), '')
                    except Exception as e:
                        self._logger.warn("Could not create UPnP port mapping for {} ({}/{}): {}".format(game, port, proto, e)) 
开发者ID:Kazade,项目名称:dreampi,代码行数:26,代码来源:port_forwarding.py

示例6: test_many_ports_until_fail

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def test_many_ports_until_fail():
    mapper = UpnpPortMapper(UPnP())
    base_port = 11000
    for port in range(base_port, base_port + 50, 1):
        mapper.add_mapping(port, port, 'TCP') 
开发者ID:syncloud,项目名称:platform,代码行数:7,代码来源:upnpc_experiments.py

示例7: clean_my_mappings

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def clean_my_mappings(self, port):
        """Delete previous OpenBazaar UPnP Port mappings if found."""
        if self.upnp_device_available:
            mappings = self.get_mapping_list()
            for mapping in mappings:
                if mapping.description.startswith(PortMapper.OPEN_BAZAAR_DESCRIPTION) \
                   and mapping.port == port:
                    self.debug('delete_port_mapping -> Found:', str(mapping))
                    try:
                        self.delete_port_mapping(mapping.port, mapping.protocol)
                    except Exception:
                        pass 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:14,代码来源:upnp.py

示例8: upnp_remap_port

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def upnp_remap_port(port):
    log.info(f"Attempting to enable UPnP (open up port {port})")
    try:
        upnp = miniupnpc.UPnP()
        upnp.discoverdelay = 5
        upnp.discover()
        upnp.selectigd()
        upnp.addportmapping(port, "TCP", upnp.lanaddr, port, "chia", "")
        log.info(f"Port {port} opened with UPnP.")
    except Exception:
        log.warning(
            "UPnP failed. This is not required to run chia, but it allows incoming connections from other peers."
        ) 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:15,代码来源:upnp.py

示例9: _upnp_igd_connect

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def _upnp_igd_connect():
    logger.debug("TrSv", "Attempting to connect to uPnP IGD")
    upnpc = miniupnpc.UPnP()
    upnpc.discoverdelay = 3000
    devs = upnpc.discover()
    if devs == 0:
        msg = "Failed to connect to uPnP IGD: no devices found"
        logger.warning("TrSv", msg)
        return
    try:
        upnpc.selectigd()
    except Exception as e:
        msg = "Failed to connect to uPnP IGD: {0}"
        logger.warning("TrSv", msg.format(str(e)))
    return upnpc 
开发者ID:arkOScloud,项目名称:core,代码行数:17,代码来源:tracked_services.py

示例10: exit_handler

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def exit_handler(self, upnp_obj):
        # Clean up UPnP
        try:
            upnp_obj.deleteportmapping(self.remote_port, 'TCP')
        except Exception:
            pass 
开发者ID:projectarkc,项目名称:arkc-client,代码行数:8,代码来源:coordinator.py

示例11: map_port_UPnP

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def map_port_UPnP(self, port, description):
        upnp = miniupnpc.UPnP()

        upnp.discoverdelay = 10
        upnp.discover()

        upnp.selectigd()

        upnp.addportmapping(port, 'TCP', upnp.lanaddr, port, description, '') 
开发者ID:lakewik,项目名称:EasyStorj,代码行数:11,代码来源:tools.py

示例12: __init__

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def __init__(self, dc_ip, logger):
        self._dreamcast_ip = dc_ip
        self._logger = logger
        self._upnp = miniupnpc.UPnP() 
开发者ID:Kazade,项目名称:dreampi,代码行数:6,代码来源:port_forwarding.py

示例13: delete_all

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def delete_all(self):
        """
            This method deletes all forwards, if possible. If the process returns an
            error, we keep trucking.
        """

        try:
            self._upnp.discover()
            self._upnp.selectigd()
        except Exception as e:
            self._logger.info("Could not find a UPnP internet gateway device on your network. Not automatically forwarding ports.")
            return False

        for portinfo in self.PORTS:
            port, proto, game = portinfo

            if isinstance(port, list):
                self._logger.info("Trying to delete UPnP port mapping for {} ({}-{}/{})".format(game, port[0], port[-1], proto))

                for p in port:
                    try:
                        self._upnp.deleteportmapping(p, proto)
                    except Exception as e:
                        self._logger.debug("Could not delete UPnP port mapping for {} ({}/{}): {}".format(game, p, proto, e))
            else:
                self._logger.info("Trying to delete UPnP port mapping for {} ({}/{})".format(game, port, proto))

                try:
                    self._upnp.deleteportmapping(port, proto)
                except Exception as e:
                    self._logger.debug("Could not delete UPnP port mapping for {} ({}/{}): {}".format(game, port, proto, e))

        return True 
开发者ID:Kazade,项目名称:dreampi,代码行数:35,代码来源:port_forwarding.py

示例14: __init__

# 需要导入模块: import miniupnpc [as 别名]
# 或者: from miniupnpc import UPnP [as 别名]
def __init__(self, debug=False, config_dir=None):
        self.platform_config = PlatformConfig(config_dir=config_dir)

        if not logger.factory_instance:
            console = True if debug else False
            level = logging.DEBUG if debug else logging.INFO
            logger.init(level, console, join(self.platform_config.get_platform_log()))

        self.user_platform_config = PlatformUserConfig()

        self.log_aggregator = Aggregator(self.platform_config)

        self.platform_app_paths = AppPaths(PLATFORM_APP_NAME, self.platform_config)
        self.platform_app_paths.get_data_dir()
        self.versions = Versions(self.platform_config)
        self.redirect_service = RedirectService(self.user_platform_config, self.versions)
        self.port_config = PortConfig(self.platform_app_paths.get_data_dir())

        self.nat_pmp_port_mapper = NatPmpPortMapper()
        self.upnp_port_mapper = UpnpPortMapper(UPnP())
        self.port_mapper_factory = PortMapperFactory(self.nat_pmp_port_mapper, self.upnp_port_mapper)
        self.port_drill_factory = PortDrillFactory(self.user_platform_config, self.port_config,
                                                   self.port_mapper_factory)
        self.device_info = DeviceInfo(self.user_platform_config, self.port_config)
        self.snap = Snap(self.platform_config, self.device_info)
        self.platform_cron = PlatformCron(self.platform_config)
        self.systemctl = Systemctl(self.platform_config)
        self.ldap_auth = LdapAuth(self.platform_config, self.systemctl)
        self.event_trigger = EventTrigger(self.snap)
        self.nginx = Nginx(self.platform_config, self.systemctl, self.device_info)
        self.certbot_genetator = CertbotGenerator(self.platform_config, self.user_platform_config,
                                                  self.device_info, self.snap)
        self.tls = CertificateGenerator(self.platform_config, self.user_platform_config, self.device_info, self.nginx,
                                        self.certbot_genetator)
        
        self.device = Device(self.platform_config, self.user_platform_config, self.redirect_service,
                             self.port_drill_factory, self.platform_cron, self.ldap_auth,
                             self.event_trigger, self.tls, self.nginx)

        self.internal = Internal(self.platform_config, self.device, self.redirect_service, self.log_aggregator)
        self.path_checker = PathChecker(self.platform_config)
        self.lsblk = Lsblk(self.platform_config, self.path_checker)
        self.hardware = Hardware(self.platform_config, self.event_trigger,
                                 self.lsblk, self.path_checker, self.systemctl)
        self.network = Network()
        self.public = Public(self.platform_config, self.user_platform_config, self.device, self.device_info, self.snap,
                             self.hardware, self.redirect_service, self.log_aggregator, self.certbot_genetator,
                             self.port_mapper_factory, self.network, self.port_config) 
开发者ID:syncloud,项目名称:platform,代码行数:50,代码来源:injector.py


注:本文中的miniupnpc.UPnP方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。