def __init__(self, username, password, database, host): self.exit = Exit() self.geoip = GeoIP() try: self.con = pymysql.connect(user=username, passwd=password, db=database, host=host) self.cur = self.con.cursor() except: self.exit.database_connection_error()
class DBHandler: def __init__(self, username, password, database, host): self.exit = Exit() self.geoip = GeoIP() try: self.con = pymysql.connect(user=username, passwd=password, db=database, host=host) self.cur = self.con.cursor() except: self.exit.database_connection_error() def execute_commit(self, query): self.cur.execute(query) self.con.commit() def create_table_hosts(self): query = """ CREATE TABLE IF NOT EXISTS `hosts`( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `ip` VARCHAR(15) COLLATE utf8_general_ci, `lng` DECIMAL(11,8), `lat` DECIMAL(10,8), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ; """ self.execute_commit(query) def ip_in_db(self, ip): query = "SELECT 1 FROM hosts WHERE ip='%s'" % ip self.cur.execute(query) if self.cur.fetchone() == 1: return True else: return False def create_new_host_entry(self, ip): query = "INSERT INTO hosts(ip, lng, lat) VALUES ('%s', '%f', '%f')" % (ip, self.geoip.get_longitude(ip), self.geoip.get_latitude(ip)) self.execute_commit(query)
def __init__(self, args): self.exit = Exit() self.check_arguments(args)
class ArgumentChecker: def __init__(self, args): self.exit = Exit() self.check_arguments(args) def check_arguments(self, args): if args.target is None and args.range is None and args.random is None: self.exit.no_targets() if args.random is None and (args.amount is None or args.amount == 1): self.exit.no_random() if args.all is None: if args.ftp is None and args.ssh is None and args.telnet is None and args.mail is None and args.ms is None: if args.ports is None: self.exit.no_ports() elif ',' in args.ports: args.ports = split(args.ports, ',') elif ';' in args.ports: args.ports = split(args.ports, ';') for port in args.ports: if port < 0 or port > 65535: self.exit.port_out_of_range() if args.db is None: self.exit.no_database() if args.range is not None: if args.target is not None: sys.exit("[-] You can't use Range and Target Argument. Choose one.") elif args.shodan: sys.exit("[-] You can't use Range and Shodan Arguemnt. Choose one.") elif args.query is not None: sys.exit("[-] You can't use Range and Query Argument. Choose one.") elif args.random is not None: sys.exit("[-] You can't use Range and Random Argument. Choose one.") elif args.target is not None: if args.range is not None: sys.exit("[-] You can't use Target and Range Argument. Choose one.") elif args.shodan: sys.exit("[-] You can't use Target and Shodan Argument. Choose one.") elif args.query is not None: sys.exit("[-] You can't use Target and Query Argument. Choose one.") elif args.random is not None: sys.exit("[-] You can't use Target and Random Argument. Choose one.") elif args.random is not None: if args.range is not None: sys.exit("[-] You can't use Random and Range Argument. Choose one.") elif args.shodan: sys.exit("[-] You can't use Random and Shodan Argument. Choose one.") elif args.query is not None: sys.exit("[-] You can't use Random and Query Argument. Choose one.") elif args.target is not None: sys.exit("[-] You can't use Random and Target Argument. Choose one.") elif args.shodan: if args.range is not None: sys.exit("[-] You can't use Shodan and Range Argument. Choose one.") elif args.random is not None: sys.exit("[-] You can't use Shodan and Random Argument. Choose one.") elif args.target is not None: sys.exit("[-] You can't use Shodan and Target Argument. Choose one.") elif args.query is None: sys.exit("[-] You need to provide a Query.") elif args.apikey is None: sys.exit("[-] You need to provide a Shodan API Key.")