<s> """<STR_LIT>""" <EOL> import sys <EOL> import logging <EOL> import dns <EOL> from cliff . lister import Lister <EOL> from IPy import IP <EOL> import requests <EOL> from . dnsbl import Base <EOL> from . netdns import get_mx_hosts , ips_from_domains , get_txt , build_query , net_calc , verify_domain <EOL> requests_log = logging . getLogger ( "<STR_LIT>" ) <EOL> requests_log . setLevel ( logging . WARNING ) <EOL> DNSBL_LIST = '<STR_LIT>' <EOL> req = requests . get ( DNSBL_LIST ) <EOL> if req . status_code == <NUM_LIT:200> : <EOL> BASE_DNSBLS = req . text . split ( ) <EOL> else : <EOL> from . dnsbllist import BASE_DNSBLS <EOL> class Scan ( Lister ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( Scan , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:?>' , default = None ) <EOL> return parser <EOL> def dnsbl_check ( self , ip ) : <EOL> backend = Base ( ip = ip , dnsbls = BASE_DNSBLS ) <EOL> return backend . check ( ) <EOL> def dnsbl_scanner ( self , rdata , ip ) : <EOL> for dnsbl , blacklisted in self . dnsbl_check ( ip ) : <EOL> if blacklisted : <EOL> Scan . log . debug ( '<STR_LIT>' % dnsbl ) <EOL> try : <EOL> query = build_query ( ip , dnsbl ) <EOL> txt = get_txt ( query ) [ <NUM_LIT:0> ] <EOL> except dns . resolver . NoAnswer : <EOL> Scan . log . debug ( "<STR_LIT>" % query ) <EOL> rdata . append ( <EOL> ( ip , <EOL> dnsbl , <EOL> blacklisted , <EOL> txt , ) <EOL> ) <EOL> return rdata <EOL> def take_action ( self , parsed_args ) : <EOL> """<STR_LIT>""" <EOL> arg = parsed_args . scan <EOL> rdata = [ ] <EOL> if "<STR_LIT:/>" in arg : <EOL> ips = net_calc ( arg ) <EOL> else : <EOL> try : <EOL> ip = IP ( arg ) <EOL> ips = [ ip ] <EOL> except ValueError : <EOL> if verify_domain ( arg ) : <EOL> hosts = get_mx_hosts ( arg ) <EOL> ips = ips_from_domains ( hosts ) <EOL> else : <EOL> raise RuntimeError ( '<STR_LIT>' % arg ) <EOL> for ip in ips : <EOL> ip = str ( ip ) <EOL> rdata = self . dnsbl_scanner ( rdata , ip ) <EOL> if not len ( rdata ) : <EOL> Scan . log . debug ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> Scan . log . debug ( rdata ) <EOL> return ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , rdata ) </s>
