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


Python common.is_ip方法代码示例

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


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

示例1: _parse_resolv

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def _parse_resolv(self):
        self._servers = []
        try:
            with open('/etc/resolv.conf', 'rb') as f:
                content = f.readlines()
                for line in content:
                    line = line.strip()
                    if line:
                        if line.startswith(b'nameserver'):
                            parts = line.split()
                            if len(parts) >= 2:
                                server = parts[1]
                                if common.is_ip(server) == socket.AF_INET:
                                    if type(server) != str:
                                        server = server.decode('utf8')
                                    self._servers.append(server)
        except IOError:
            pass
        if not self._servers:
            self._servers = ['8.8.4.4', '8.8.8.8'] 
开发者ID:ntfreedom,项目名称:neverendshadowsocks,代码行数:22,代码来源:asyncdns.py

示例2: _parse_hosts

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def _parse_hosts(self):
        etc_path = '/etc/hosts'
        if 'WINDIR' in os.environ:
            etc_path = os.environ['WINDIR'] + '/system32/drivers/etc/hosts'
        try:
            with open(etc_path, 'rb') as f:
                for line in f.readlines():
                    line = line.strip()
                    parts = line.split()
                    if len(parts) >= 2:
                        ip = parts[0]
                        if common.is_ip(ip):
                            for i in range(1, len(parts)):
                                hostname = parts[i]
                                if hostname:
                                    self._hosts[hostname] = ip
        except IOError:
            self._hosts['localhost'] = '127.0.0.1' 
开发者ID:ntfreedom,项目名称:neverendshadowsocks,代码行数:20,代码来源:asyncdns.py

示例3: _parse_hosts

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def _parse_hosts(self):
        etc_path = '/etc/hosts'
        if 'WINDIR' in os.environ:
            etc_path = os.environ['WINDIR'] + '/system32/drivers/etc/hosts'
        try:
            with open(etc_path, 'rb') as f:
                for line in f.readlines():
                    line = line.strip()
                    if b"#" in line:
                        line = line[:line.find(b'#')]
                    parts = line.split()
                    if len(parts) >= 2:
                        ip = parts[0]
                        if common.is_ip(ip):
                            for i in range(1, len(parts)):
                                hostname = parts[i]
                                if hostname:
                                    self._hosts[hostname] = ip
        except IOError:
            self._hosts['localhost'] = '127.0.0.1' 
开发者ID:hao35954514,项目名称:shadowsocksR-b,代码行数:22,代码来源:asyncdns.py

示例4: _parse_resolv

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def _parse_resolv(self):
        """
        读取系统默认DNS服务器地址
        :return:
        """
        self._servers = []
        try:
            with open('/etc/resolv.conf', 'rb') as f:
                content = f.readlines()
                for line in content:
                    line = line.strip()
                    if line:
                        if line.startswith(b'nameserver'):
                            parts = line.split()
                            if len(parts) >= 2:
                                server = parts[1]
                                if common.is_ip(server) == socket.AF_INET:
                                    if type(server) != str:
                                        server = server.decode('utf8')
                                    self._servers.append(server)
        except IOError:
            pass
        if not self._servers:
            self._servers = ['8.8.4.4', '8.8.8.8'] 
开发者ID:youkochan,项目名称:shadowsocks-analysis,代码行数:26,代码来源:asyncdns.py

示例5: _parse_hosts

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def _parse_hosts(self):
        """
        读取系统HOST文件
        :return:
        """
        etc_path = '/etc/hosts'
        if 'WINDIR' in os.environ:
            etc_path = os.environ['WINDIR'] + '/system32/drivers/etc/hosts'
        try:
            with open(etc_path, 'rb') as f:
                for line in f.readlines():
                    line = line.strip()
                    parts = line.split()
                    if len(parts) >= 2:
                        ip = parts[0]
                        if common.is_ip(ip):
                            for i in range(1, len(parts)):
                                hostname = parts[i]
                                if hostname:
                                    self._hosts[hostname] = ip
        except IOError:
            self._hosts['localhost'] = '127.0.0.1' 
开发者ID:youkochan,项目名称:shadowsocks-analysis,代码行数:24,代码来源:asyncdns.py

示例6: resolve

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def resolve(self, hostname, callback):
        if type(hostname) != bytes:
            hostname = hostname.encode('utf8')
        if not hostname:
            callback(None, Exception('empty hostname'))
        elif common.is_ip(hostname):
            callback((hostname, hostname), None)
        elif hostname in self._hosts:
            logging.debug('hit hosts: %s', hostname)
            ip = self._hosts[hostname]
            callback((hostname, ip), None)
        elif hostname in self._cache:
            logging.debug('hit cache: %s', hostname)
            ip = self._cache[hostname]
            callback((hostname, ip), None)
        else:
            if not is_valid_hostname(hostname):
                callback(None, Exception('invalid hostname: %s' % hostname))
                return
            arr = self._hostname_to_cb.get(hostname, None)
            if not arr:
                self._hostname_status[hostname] = STATUS_IPV4
                self._send_req(hostname, QTYPE_A)
                self._hostname_to_cb[hostname] = [callback]
                self._cb_to_hostname[callback] = hostname
            else:
                arr.append(callback)
                # TODO send again only if waited too long
                self._send_req(hostname, QTYPE_A) 
开发者ID:ntfreedom,项目名称:neverendshadowsocks,代码行数:31,代码来源:asyncdns.py

示例7: resolve

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def resolve(self, hostname, callback):
        if type(hostname) != bytes:
            hostname = hostname.encode('utf8')
        if not hostname:
            callback(None, Exception('empty hostname'))
        elif common.is_ip(hostname):
            callback((hostname, hostname), None)
        elif hostname in self._hosts:
            logging.debug('hit hosts: %s', hostname)
            ip = self._hosts[hostname]
            callback((hostname, ip), None)
        elif hostname in self._cache:
            logging.debug('hit cache: %s', hostname)
            ip = self._cache[hostname]
            callback((hostname, ip), None)
        else:
            if not is_valid_hostname(hostname):
                callback(None, Exception('invalid hostname: %s' % hostname))
                return
            arr = self._hostname_to_cb.get(hostname, None)
            if not arr:
                if IPV6_CONNECTION_SUPPORT:
                    self._hostname_status[hostname] = STATUS_IPV6
                    self._send_req(hostname, QTYPE_AAAA)
                else:
                    self._hostname_status[hostname] = STATUS_IPV4
                    self._send_req(hostname, QTYPE_A)
                self._hostname_to_cb[hostname] = [callback]
                self._cb_to_hostname[callback] = hostname
            else:
                arr.append(callback)
                # TODO send again only if waited too long
                if IPV6_CONNECTION_SUPPORT:
                    self._send_req(hostname, QTYPE_AAAA)
                else:
                    self._send_req(hostname, QTYPE_A) 
开发者ID:shadowsocksr-backup,项目名称:shadowsocksr,代码行数:38,代码来源:asyncdns.py

示例8: _parse_resolv

# 需要导入模块: from shadowsocks import common [as 别名]
# 或者: from shadowsocks.common import is_ip [as 别名]
def _parse_resolv(self):
        self._servers = []
        try:
            with open('dns.conf', 'rb') as f:
                content = f.readlines()
                for line in content:
                    line = line.strip()
                    if line:
                        parts = line.split(b' ', 1)
                        if len(parts) >= 2:
                            server = parts[0]
                            port = int(parts[1])
                        else:
                            server = parts[0]
                            port = 53
                        if common.is_ip(server) == socket.AF_INET:
                            if type(server) != str:
                                server = server.decode('utf8')
                            self._servers.append((server, port))
        except IOError:
            pass
        if not self._servers:
            try:
                with open('/etc/resolv.conf', 'rb') as f:
                    content = f.readlines()
                    for line in content:
                        line = line.strip()
                        if line:
                            if line.startswith(b'nameserver'):
                                parts = line.split()
                                if len(parts) >= 2:
                                    server = parts[1]
                                    if common.is_ip(server) == socket.AF_INET:
                                        if type(server) != str:
                                            server = server.decode('utf8')
                                        self._servers.append((server, 53))
            except IOError:
                pass
        if not self._servers:
            self._servers = [('8.8.4.4', 53), ('8.8.8.8', 53)]
        logging.info('dns server: %s' % (self._servers,)) 
开发者ID:hao35954514,项目名称:shadowsocksR-b,代码行数:43,代码来源:asyncdns.py


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