python类gethostbyname_ex()的实例源码

utils.py 文件源码 项目:cerberus-core 作者: ovh 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def get_ips_from_url(url):
    """
        Retrieve IPs from url

        :param str url: The url to resolve
        :rtype: list
        :return: the list of resolved IP address for given url
    """
    try:
        parsed = urlparse(url)
        if parsed.hostname:
            socket.setdefaulttimeout(5)
            ips = socket.gethostbyname_ex(parsed.hostname)[2]
            return ips
    except (ValueError, socket.error, socket.gaierror, socket.herror, socket.timeout):
        pass
proxylib.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def gethostbyname2(self, hostname):
        try:
            iplist = self.dns_cache[hostname]
        except KeyError:
            if re.match(r'^\d+\.\d+\.\d+\.\d+$', hostname) or ':' in hostname:
                iplist = [hostname]
            elif self.dns_servers:
                try:
                    record = dnslib_resolve_over_udp(hostname, self.dns_servers, timeout=2, blacklist=self.dns_blacklist)
                except socket.gaierror:
                    record = dnslib_resolve_over_tcp(hostname, self.dns_servers, timeout=2, blacklist=self.dns_blacklist)
                iplist = dnslib_record2iplist(record)
            else:
                iplist = socket.gethostbyname_ex(hostname)[-1]
            self.dns_cache[hostname] = iplist
        return iplist
sflib.py 文件源码 项目:llk 作者: Tycx2ry 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def checkDnsWildcard(self, target):
        randpool = 'bcdfghjklmnpqrstvwxyz3456789'
        randhost = ''.join([random.choice(randpool) for x in range(10)])

        # An exception will be raised if the resolution fails
        try:
            addrs = socket.gethostbyname_ex(randhost + "." + target)
            self.debug(target + " has wildcard DNS.")
            return True
        except BaseException as e:
            self.debug(target + " does not have wildcard DNS.")
            return False

    # Scrape Google for content, starting at startUrl and iterating through
    # results based on options supplied. Will return a dictionary of all pages
    # fetched and their contents {page => content}.
    # Options accepted:
    # limit: number of search result pages before returning, default is 10
    # nopause: don't randomly pause between fetches
    # useragent: User-Agent string to use
    # timeout: Fetch timeout
sfp_dns.py 文件源码 项目:spiderfoot 作者: wi-fi-analyzer 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def resolveHost(self, hostname):
        if hostname in self.resolveCache:
            self.sf.debug("Returning cached result for " + hostname + " (" +
                          str(self.resolveCache[hostname]) + ")")
            return self.resolveCache[hostname]

        try:
            addrs = self.sf.normalizeDNS(socket.gethostbyname_ex(hostname))
            self.resolveCache[hostname] = addrs
            self.sf.debug("Resolved " + hostname + " to: " + str(addrs))
            return addrs
        except BaseException as e:
            self.sf.debug("Unable to resolve " + hostname + " (" + str(e) + ")")
            return list()

    # Resolve a host to IPv6
sfp_sharedip.py 文件源码 项目:spiderfoot 作者: wi-fi-analyzer 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def validateIP(self, host, ip):
        try:
            addrs = socket.gethostbyname_ex(host)
        except BaseException as e:
            self.sf.debug("Unable to resolve " + host + ": " + str(e))
            return False

        for addr in addrs:
            if type(addr) == list:
                for a in addr:
                    if str(a) == ip:
                        return True
            else:
                if str(addr) == ip:
                    return True
        return False

    # Handle events sent to this module
resolver.py 文件源码 项目:spiderfoot 作者: wi-fi-analyzer 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
models.py 文件源码 项目:bedrock-core 作者: Bedrock-py 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, name, rootdir, src_id, src_type, time,
                 ingest_id, group_name, matrices=None,
                 status=None, count=0, stash=None, filepath=None):
        self.name = name
        self.host = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
                     if not ip.startswith("127.")][-1]
        self.rootdir = rootdir
        self.src_id = src_id
        self.src_type = src_type
        self.created = time
        self.ingest_id = ingest_id
        self.matrices = none2empty(matrices)
        self.status = none2empty(status)
        self.count = count
        self.stash = none2empty(stash)
        self.group_name = group_name
        self.filepath = filepath
proxylib.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def get_country_code(self, hostname, dnsservers):
        """http://dev.maxmind.com/geoip/legacy/codes/iso3166/"""
        try:
            return self.region_cache[hostname]
        except KeyError:
            pass
        try:
            if re.match(r'^\d+\.\d+\.\d+\.\d+$', hostname) or ':' in hostname:
                iplist = [hostname]
            elif dnsservers:
                iplist = dnslib_record2iplist(dnslib_resolve_over_udp(hostname, dnsservers, timeout=2))
            else:
                iplist = socket.gethostbyname_ex(hostname)[-1]
            if iplist[0].startswith(('127.', '192.168.', '10.')):
                country_code = 'LOCAL'
            else:
                country_code = self.geoip.country_code_by_addr(iplist[0])
        except StandardError as e:
            logging.warning('DirectRegionFilter cannot determine region for hostname=%r %r', hostname, e)
            country_code = ''
        self.region_cache[hostname] = country_code
        return country_code
proxy_handler.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def is_local(self, hosts):
        if 0 == len(self.local_names):
            self.local_names.append('localhost')
            self.local_names.append(socket.gethostname().lower());
            try:
                self.local_names.append(socket.gethostbyname_ex(socket.gethostname())[-1])
            except socket.gaierror:
                # TODO Append local IP address to local_names
                pass

        for s in hosts:
            s = s.lower()
            if s.startswith('127.') \
                    or s.startswith('192.168.') \
                    or s.startswith('10.') \
                    or s.startswith('169.254.') \
                    or s in self.local_names:
                print s
                return True
        return False
resolver.py 文件源码 项目:hakkuframework 作者: 4shadoww 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
utils.py 文件源码 项目:bigquery-bokeh-dashboard 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _resync(self):
        """
        Check if the list of available nodes has changed. If any change is
        detected, a new HashClient pointing to all currently available
        nodes is returned, otherwise the current client is returned.
        """
        # Collect the all Memcached pods' IP addresses
        try:
            _, _, ips = socket.gethostbyname_ex(self.host)
        except socket.gaierror:
            # The host could not be found. This mean that either the service is
            # down or that no pods are running
            ips = []
        if set(ips) != set(self._ips):
            # A different list of ips has been detected, so we generate
            # a new client
            self._ips = ips
            if self._ips:
                servers = [(ip, self.port) for ip in self._ips]
                self._client = HashClient(servers, use_pooling=True)
            else:
                self._client = None
resolver.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
socks.py 文件源码 项目:OpenDoor 作者: stanislav-web 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_ips_addresses(host):
        """
        Get remote ip addresses
        :param str host: target host
        :return: list
        """

        try:
            _, _, ips_list = socket.gethostbyname_ex(host)
            if not ips_list:
                ips = ''
            else:
                ips = '['+', '.join(ips_list) +']'
        except socket.gaierror:
            ips = ''
        return ips
resolver.py 文件源码 项目:cheapstream 作者: miltador 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
ngamsServer.py 文件源码 项目:ngas 作者: ICRAR 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def is_it_us(self, host, port):
        """
        True if the host/port combination corresponds to an address exposed by
        this server
        """
        if port != self.portNo:
            return False

        our_ip = self.ipAddress
        if our_ip != '0.0.0.0' and our_ip == host:
            return True

        # We are exposed to all interfaces and `host` might be one of them
        # gethostbyname_ex[2] is a list of addresses
        for h in socket.gethostbyname_ex(host)[2]:
            if h in self.all_ip_addresses:
                return True
        return False
my_bing_domains_v1_alone.py 文件源码 项目:MyToolKit 作者: 3xp10it 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def main():    
    if len(sys.argv)!=2:
        usage()
        sys.exit(0)

    try:
        file=open(sys.argv[1],"r+")
        target_list=file.readlines()
        file.close()
        true_target_list=[]
        true_target_list=get_pure_list(target_list)
        for each in true_target_list:
            try:
                get_the_one_target_domains(each)
            except:
                print "getip or socket.gethostbyname_ex wrong,the site may break down,you can check it."
    except:
        sharedHost=sys.argv[1]
        get_the_one_target_domains(sharedHost)
        print "open file wrong coz this input is not a file but a domain or when you do put a file,then the script open file wrong"
resolver.py 文件源码 项目:Infrax-as-Code-1000-webservers-in-40-minutes 作者: ezeeetm 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
proxylib.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def get_country_code(self, hostname, dnsservers):
        """http://dev.maxmind.com/geoip/legacy/codes/iso3166/"""
        try:
            return self.region_cache[hostname]
        except KeyError:
            pass
        try:
            if re.match(r'^\d+\.\d+\.\d+\.\d+$', hostname) or ':' in hostname:
                iplist = [hostname]
            elif dnsservers:
                iplist = dnslib_record2iplist(dnslib_resolve_over_udp(hostname, dnsservers, timeout=2))
            else:
                iplist = socket.gethostbyname_ex(hostname)[-1]
            if iplist[0].startswith(('127.', '192.168.', '10.')):
                country_code = 'LOCAL'
            else:
                country_code = self.geoip.country_code_by_addr(iplist[0])
        except StandardError as e:
            logging.warning('DirectRegionFilter cannot determine region for hostname=%r %r', hostname, e)
            country_code = ''
        self.region_cache[hostname] = country_code
        return country_code
proxylib.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def gethostbyname2(self, hostname):
        try:
            iplist = self.dns_cache[hostname]
        except KeyError:
            if re.match(r'^\d+\.\d+\.\d+\.\d+$', hostname) or ':' in hostname:
                iplist = [hostname]
            elif self.dns_servers:
                try:
                    record = dnslib_resolve_over_udp(hostname, self.dns_servers, timeout=2, blacklist=self.dns_blacklist)
                except socket.gaierror:
                    record = dnslib_resolve_over_tcp(hostname, self.dns_servers, timeout=2, blacklist=self.dns_blacklist)
                iplist = dnslib_record2iplist(record)
            else:
                iplist = socket.gethostbyname_ex(hostname)[-1]
            self.dns_cache[hostname] = iplist
        return iplist
__init__.py 文件源码 项目:pycam 作者: SebKuzminsky 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_all_ips():
    """ try to get all IPs of this machine

    The resulting list of IPs contains non-local IPs first, followed by
    local IPs (starting with "127....").
    """
    def get_ips_of_name(name):
        try:
            ips = socket.gethostbyname_ex(name)
            if len(ips) == 3:
                return ips[2]
        except socket.gaierror:
            return []
    result = []
    result.extend(get_ips_of_name(socket.gethostname()))
    result.extend(get_ips_of_name("localhost"))
    filtered_result = []
    for one_ip in result:
        if one_ip not in filtered_result:
            filtered_result.append(one_ip)
    # non-local IPs first
    filtered_result.sort(key=lambda ip: ((1 if ip.startswith("127.") else 0), ip))
    return filtered_result
__init__.py 文件源码 项目:djangocon-2016-demo 作者: hadjango 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def ip():
    """The ip where the addons site can be accessed"""
    docker_host = os.environ.get("DOCKER_HOST") or ""
    if not docker_host:
        with quiet():
            docker_env = local("docker-machine env addons", capture=True)
        if docker_env:
            match = re.search(r'DOCKER_HOST="(tcp://[^"]+?)"', docker_env)
            if match:
                docker_host = match.group(1)

    match = re.search(r'tcp://([^:]+):', docker_host)
    if match:
        print(match.group(1))
    else:
        try:
            # host used by dlite
            _, _, ips = socket.gethostbyname_ex("local.docker")
        except:
            abort("Could not determine docker-machine host; perhaps localhost?")
        else:
            print(ips[0])
resolver.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
resolver.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
index.py 文件源码 项目:dymo-m10-python 作者: pbrf 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def mirrors(self):
        """
        Return the list of hostnames which are mirrors for this index.
        :return: A (possibly empty) list of hostnames of mirrors.
        """
        result = []
        try:
            host = socket.gethostbyname_ex(self.mirror_host)[0]
        except socket.gaierror: # pragma: no cover
            host = None
        if host:
            last, rest = host.split('.', 1)
            n = len(last)
            host_list = (''.join(w) for w in itertools.chain.from_iterable(
                        itertools.product(ascii_lowercase, repeat=i)
                        for i in range(1, n + 1)))
            for s in host_list:
                result.append('.'.join((s, rest)))
                if s == last:
                    break
        return result
mirrorlib.py 文件源码 项目:pypi-legacy 作者: pypa 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _mirror_list(first):
    '''Generator producing all mirror names'''
    ord_a = ord('a')
    last = socket.gethostbyname_ex('last.pypi.python.org')
    cur_index = ord(first)-ord_a
    cur = first+'.pypi.python.org'
    while True:
        for family, _, _, _, sockaddr in socket.getaddrinfo(cur, 0, 0, socket.SOCK_STREAM):
            yield cur, family, sockaddr
        if last[0] == cur:
            break
        cur_index += 1
        if cur_index < 26:
            # a..z
            cur = chr(ord_a+cur_index)
        elif cur_index > 701:
            raise ValueError, 'too many mirrors'
        else:
            # aa, ab, ... zz
            cur = divmod(cur_index, 26)
            cur = chr(ord_a-1+cur[0])+chr(ord_a+cur[1])
        cur += '.pypi.python.org'
ip_and_socket.py 文件源码 项目:matlab_ctp_md_td 作者: xunquant 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_local_ip(platform_category):
    '''
    ????IP??
    '''

    nic_dict=get_active_nic_name()

    major_nic_name=nic_dict.keys()[0]

    if platform_category.__contains__('windows'):#???windows????
        host_name=socket.gethostname()
        my_host_name=socket.getfqdn()
        #????ip
        ip_list=socket.gethostbyname_ex(my_host_name)
        my_local_ip=socket.gethostbyname(my_host_name)
    else:#linux??
        try:
            my_local_ip=get_ip_of_a_net_adapter_in_linux(major_nic_name)#????????????,????eth0
        except:
            my_local_ip='??????????????????????'
            print my_local_ip
        pass
    return my_local_ip
    pass
resolver.py 文件源码 项目:minihydra 作者: VillanCh 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
net.py 文件源码 项目:probesc 作者: bstaint 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def valid_ip(host):
    ''' lookup address with gethostbyname '''
    ipaddr = None
    fake_domain = 'notexistsfuckispsbbaidu.com'

    try:
        # ??ISP??
        if not hasattr(valid_ip, 'fake_ip'):
            try: valid_ip.fake_ip = socket.gethostbyname(fake_domain)
            except socket.error: valid_ip.fake_ip = None

        _,_,ipaddrs = socket.gethostbyname_ex(host)

        if ipaddrs[0] != valid_ip.fake_ip:
            ipaddr = ipaddrs[0]
    except socket.error:
        pass
    return ipaddr
resolver.py 文件源码 项目:00scanner 作者: xiaoqin00 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr
wechat-sendall.py 文件源码 项目:wechat-sendall 作者: vonnyfly 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def getQRImage():
  path = os.path.join(os.getcwd(), "qrcode.jpg")
  url = "https://login.weixin.qq.com/qrcode/" + uuid
  r = s.get(url, stream=True)
  # debugReq(r)
  if r.status_code == 200:
    with open(path, 'wb') as f:
      r.raw.decode_content = True
      shutil.copyfileobj(r.raw, f)
  import socket
  ip = [l
        for l in
        ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
          if not ip.startswith("127.")][:1],
         [[(sc.connect(('8.8.8.8', 80)), sc.getsockname()[0], sc.close())
           for sc in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]])
        if l][0][0]
  print "[+] Please open http://" + ip + ":" + str(http_port) + "/qrcode.jpg or open " + path

  time.sleep(1)


问题


面经


文章

微信
公众号

扫码关注公众号