<s> import random <EOL> import socket <EOL> import threading <EOL> class DNSSeeder ( object ) : <EOL> def __init__ ( self , dns_seeds ) : <EOL> self . _dns_seeds = dns_seeds <EOL> self . _lock = threading . Lock ( ) <EOL> self . _found = [ ] <EOL> self . _start ( ) <EOL> def __len__ ( self ) : <EOL> with self . _lock : <EOL> return len ( self . _found ) <EOL> def pop ( self ) : <EOL> with self . _lock : <EOL> address = random . choice ( self . _found ) <EOL> self . _found . remove ( address ) <EOL> return address <EOL> def _start ( self ) : <EOL> def try_address ( address ) : <EOL> try : <EOL> ( ip_address , port ) = address <EOL> index = <NUM_LIT:0> <EOL> for info in socket . getaddrinfo ( ip_address , port , socket . AF_INET , socket . SOCK_STREAM , socket . IPPROTO_TCP ) : <EOL> try : <EOL> with self . _lock : <EOL> self . _found . append ( ( info [ <NUM_LIT:4> ] [ <NUM_LIT:0> ] , info [ <NUM_LIT:4> ] [ <NUM_LIT:1> ] ) ) <EOL> except Exception , e : <EOL> pass <EOL> except Exception , e : <EOL> pass <EOL> for address in self . _dns_seeds : <EOL> thread = threading . Thread ( target = try_address , args = ( address , ) ) <EOL> thread . daemon = True <EOL> thread . start ( ) </s>
