python类resolve()的实例源码

ClientRequest.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def resolveHost(self, host):
        address = self.dnsCache.getCachedAddress(host)

        if address != None:
            logging.debug("Host cached.")
            return defer.succeed(address)
        else:
            logging.debug("Host not cached.")
            return reactor.resolve(host)
ipdiscover.py 文件源码 项目:p2pool-ltc 作者: ilsawa 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_local_ip():
    """
    Returns a deferred which will be called with a
    2-uple (lan_flag, ip_address) :
        - lan_flag:
            - True if it's a local network (RFC1918)
            - False if it's a WAN address

        - ip_address is the actual ip address

    @return: A deferred called with the above defined tuple
    @rtype: L{twisted.internet.defer.Deferred}
    """
    # first we try a connected udp socket, then via multicast
    logging.debug("Resolving dns to get udp ip")
    try:
        ipaddr = yield reactor.resolve('A.ROOT-SERVERS.NET')
    except:
        pass
    else:
        udpprot = DatagramProtocol()
        port = reactor.listenUDP(0, udpprot)
        udpprot.transport.connect(ipaddr, 7)
        localip = udpprot.transport.getHost().host
        port.stopListening()

        if is_bogus_ip(localip):
            raise RuntimeError, "Invalid IP address returned"
        else:
            defer.returnValue((is_rfc1918_ip(localip), localip))

    logging.debug("Multicast ping to retrieve local IP")
    ipaddr = yield _discover_multicast()
    defer.returnValue((is_rfc1918_ip(ipaddr), ipaddr))
ipdiscover.py 文件源码 项目:p2pool-bsty 作者: amarian12 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_local_ip():
    """
    Returns a deferred which will be called with a
    2-uple (lan_flag, ip_address) :
        - lan_flag:
            - True if it's a local network (RFC1918)
            - False if it's a WAN address

        - ip_address is the actual ip address

    @return: A deferred called with the above defined tuple
    @rtype: L{twisted.internet.defer.Deferred}
    """
    # first we try a connected udp socket, then via multicast
    logging.debug("Resolving dns to get udp ip")
    try:
        ipaddr = yield reactor.resolve('A.ROOT-SERVERS.NET')
    except:
        pass
    else:
        udpprot = DatagramProtocol()
        port = reactor.listenUDP(0, udpprot)
        udpprot.transport.connect(ipaddr, 7)
        localip = udpprot.transport.getHost().host
        port.stopListening()

        if is_bogus_ip(localip):
            raise RuntimeError, "Invalid IP address returned"
        else:
            defer.returnValue((is_rfc1918_ip(localip), localip))

    logging.debug("Multicast ping to retrieve local IP")
    ipaddr = yield _discover_multicast()
    defer.returnValue((is_rfc1918_ip(ipaddr), ipaddr))
ipdiscover.py 文件源码 项目:p2pool-cann 作者: ilsawa 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_local_ip():
    """
    Returns a deferred which will be called with a
    2-uple (lan_flag, ip_address) :
        - lan_flag:
            - True if it's a local network (RFC1918)
            - False if it's a WAN address

        - ip_address is the actual ip address

    @return: A deferred called with the above defined tuple
    @rtype: L{twisted.internet.defer.Deferred}
    """
    # first we try a connected udp socket, then via multicast
    logging.debug("Resolving dns to get udp ip")
    try:
        ipaddr = yield reactor.resolve('A.ROOT-SERVERS.NET')
    except:
        pass
    else:
        udpprot = DatagramProtocol()
        port = reactor.listenUDP(0, udpprot)
        udpprot.transport.connect(ipaddr, 7)
        localip = udpprot.transport.getHost().host
        port.stopListening()

        if is_bogus_ip(localip):
            raise RuntimeError, "Invalid IP address returned"
        else:
            defer.returnValue((is_rfc1918_ip(localip), localip))

    logging.debug("Multicast ping to retrieve local IP")
    ipaddr = yield _discover_multicast()
    defer.returnValue((is_rfc1918_ip(ipaddr), ipaddr))
ClientRequest.py 文件源码 项目:mitmf 作者: ParrotSec 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def resolveHost(self, host):
        address = self.dnsCache.getCachedAddress(host)

        if address != None:
            log.debug("[ClientRequest] Host cached: {} {}".format(host, address))
            return defer.succeed(address)
        else:
            return reactor.resolve(host)
ClientRequest.py 文件源码 项目:mitmf 作者: ParrotSec 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, channel, queued, reactor=reactor):
        Request.__init__(self, channel, queued)
        self.reactor       = reactor
        self.urlMonitor    = URLMonitor.getInstance()
        self.hsts          = URLMonitor.getInstance().hsts
        self.cookieCleaner = CookieCleaner.getInstance()
        self.dnsCache      = DnsCache.getInstance()
        #self.uniqueId      = random.randint(0, 10000)

        #Use are own DNS server instead of reactor.resolve()
        self.customResolver = dns.resolver.Resolver()    
        self.customResolver.nameservers  = ['127.0.0.1']
ClientRequest.py 文件源码 项目:SEF 作者: ahmadnourallah 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def resolveHost(self, host):
        address = self.dnsCache.getCachedAddress(host)

        if address != None:
            log.debug("[ClientRequest] Host cached: {} {}".format(host, address))
            return defer.succeed(address)
        else:
            return reactor.resolve(host)
ClientRequest.py 文件源码 项目:SEF 作者: ahmadnourallah 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, channel, queued, reactor=reactor):
        Request.__init__(self, channel, queued)
        self.reactor       = reactor
        self.urlMonitor    = URLMonitor.getInstance()
        self.hsts          = URLMonitor.getInstance().hsts
        self.cookieCleaner = CookieCleaner.getInstance()
        self.dnsCache      = DnsCache.getInstance()
        #self.uniqueId      = random.randint(0, 10000)

        #Use are own DNS server instead of reactor.resolve()
        self.customResolver = dns.resolver.Resolver()    
        self.customResolver.nameservers  = ['127.0.0.1']
ClientRequest.py 文件源码 项目:SEF 作者: ahmadnourallah 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def resolveHost(self, host):
        address = self.dnsCache.getCachedAddress(host)

        if address != None:
            logging.debug("Host cached.")
            return defer.succeed(address)
        else:
            logging.debug("Host not cached.")
            return reactor.resolve(host)
test_internet.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def testChildResolve(self):
        # I've seen problems with reactor.run under gtk2reactor. Spawn a
        # child which just does reactor.resolve after the reactor has
        # started, fail if it does not complete in a timely fashion.
        helperPath = os.path.abspath(self.mktemp())
        with open(helperPath, 'w') as helperFile:

            # Eeueuuggg
            reactorName = reactor.__module__

            helperFile.write(resolve_helper % {'reactor': reactorName})

        env = os.environ.copy()
        env['PYTHONPATH'] = os.pathsep.join(sys.path)

        helperDeferred = Deferred()
        helperProto = ChildResolveProtocol(helperDeferred)

        reactor.spawnProcess(helperProto, sys.executable, ("python", "-u", helperPath), env)

        def cbFinished(result):
            (reason, output, error) = result
            # If the output is "done 127.0.0.1\n" we don't really care what
            # else happened.
            output = b''.join(output)
            if _PY3:
                expected_output = (b'done 127.0.0.1' +
                                   os.linesep.encode("ascii"))
            else:
                expected_output = b'done 127.0.0.1\n'
            if output != expected_output:
                self.fail((
                    "The child process failed to produce the desired results:\n"
                    "   Reason for termination was: %r\n"
                    "   Output stream was: %r\n"
                    "   Error stream was: %r\n") % (reason.getErrorMessage(), output, b''.join(error)))

        helperDeferred.addCallback(cbFinished)
        return helperDeferred
riemann.py 文件源码 项目:duct 作者: ducted 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def createClient(self):
        """Create a UDP connection to Riemann"""
        server = self.config.get('server', '127.0.0.1')
        port = self.config.get('port', 5555)

        def connect(ip):
            """Connect to the IP address
            """
            self.protocol = riemann.RiemannUDP(ip, port)
            self.endpoint = reactor.listenUDP(0, self.protocol)

        de = reactor.resolve(server)
        de.addCallback(connect)
        return de
ClientRequest.py 文件源码 项目:SEF 作者: hossamhasanin 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def resolveHost(self, host):
        address = self.dnsCache.getCachedAddress(host)

        if address != None:
            log.debug("[ClientRequest] Host cached: {} {}".format(host, address))
            return defer.succeed(address)
        else:
            return reactor.resolve(host)
ClientRequest.py 文件源码 项目:SEF 作者: hossamhasanin 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, channel, queued, reactor=reactor):
        Request.__init__(self, channel, queued)
        self.reactor       = reactor
        self.urlMonitor    = URLMonitor.getInstance()
        self.hsts          = URLMonitor.getInstance().hsts
        self.cookieCleaner = CookieCleaner.getInstance()
        self.dnsCache      = DnsCache.getInstance()
        #self.uniqueId      = random.randint(0, 10000)

        #Use are own DNS server instead of reactor.resolve()
        self.customResolver = dns.resolver.Resolver()    
        self.customResolver.nameservers  = ['127.0.0.1']
ClientRequest.py 文件源码 项目:SEF 作者: hossamhasanin 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def resolveHost(self, host):
        address = self.dnsCache.getCachedAddress(host)

        if address != None:
            logging.debug("Host cached.")
            return defer.succeed(address)
        else:
            logging.debug("Host not cached.")
            return reactor.resolve(host)
Syslog.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def startProtocol(self):
        reactor.resolve(self.host.address.value).addCallback(self.gotIP).addErrback(self.noIP)
GrowlTalk.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def startProtocol(self):
        reactor.resolve(self.host.address.value).addCallback(self.gotIP).addErrback(self.noIP)
SNP.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, host):
        self.clientFactory = SnarlNetworkProtocolClientFactory()
        self.serverFactory = SnarlNetworkProtocolServerFactory()

        if host.enable_outgoing.value:
            reactor.resolve(host.address.value).addCallback(self.gotIP).addErrback(self.noIP)

        if host.enable_incoming.value:
            self.serverPort = reactor.listenTCP(SNP_TCP_PORT, self.serverFactory)
            self.pending += 1
GNTP.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, host):
        self.clientFactory = GNTPClientFactory(host)
        self.serverFactory = GNTPServerFactory()

        if host.enable_outgoing.value:
            reactor.resolve(host.address.value).addCallback(self.gotIP).addErrback(self.noIP)

        if host.enable_incoming.value:
            self.serverPort = reactor.listenTCP(GNTP_TCP_PORT, self.serverFactory)
            self.pending += 1
ClientRequest.py 文件源码 项目:MITMf 作者: wi-fi-analyzer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def resolveHost(self, host):
        address = self.dnsCache.getCachedAddress(host)

        if address != None:
            log.debug("[ClientRequest] Host cached: {} {}".format(host, address))
            return defer.succeed(address)
        else:
            return reactor.resolve(host)
ClientRequest.py 文件源码 项目:MITMf 作者: wi-fi-analyzer 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, channel, queued, reactor=reactor):
        Request.__init__(self, channel, queued)
        self.reactor       = reactor
        self.urlMonitor    = URLMonitor.getInstance()
        self.hsts          = URLMonitor.getInstance().hsts
        self.cookieCleaner = CookieCleaner.getInstance()
        self.dnsCache      = DnsCache.getInstance()
        #self.uniqueId      = random.randint(0, 10000)

        #Use are own DNS server instead of reactor.resolve()
        self.customResolver = dns.resolver.Resolver()    
        self.customResolver.nameservers  = ['127.0.0.1']


问题


面经


文章

微信
公众号

扫码关注公众号