當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。