Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove xreadline for python 3.4 support #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions subDomainsBrute.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
"""
subDomainsBrute 1.0.6
Expand All @@ -17,8 +17,7 @@
import time
import optparse
import os
from lib.consle_width import getTerminalSize

#from lib.consle_width import getTerminalSize replace by shutil in python3+

class SubNameBrute:
def __init__(self, target, options):
Expand All @@ -27,7 +26,8 @@ def __init__(self, target, options):
self.options = options
self.ignore_intranet = options.i
self.scan_count = self.found_count = 0
self.console_width = getTerminalSize()[0] - 2
#self.console_width = getTerminalSize()[0] - 2
self.console_width = os.get_terminal_size().columns - 2
self.resolvers = [dns.resolver.Resolver(configure=False) for _ in range(options.threads)]
for _ in self.resolvers:
_.lifetime = _.timeout = 10.0
Expand All @@ -52,20 +52,20 @@ def __init__(self, target, options):
self.ex_resolver.nameservers = self.dns_servers

def _load_dns_servers(self):
print '[+] Validate DNS servers ...'
print('[+] Validate DNS servers ...')
self.dns_servers = []
pool = Pool(30)
for server in open('dict/dns_servers.txt').xreadlines():
for server in open('dict/dns_servers.txt'):
server = server.strip()
if server:
pool.apply_async(self._test_server, (server,))
pool.join()

self.dns_count = len(self.dns_servers)
sys.stdout.write('\n')
print '[+] Found %s available DNS Servers in total' % self.dns_count
print('[+] Found %s available DNS Servers in total' % self.dns_count)
if self.dns_count == 0:
print '[ERROR] No DNS Servers available.'
print('[ERROR] No DNS Servers available.')
sys.exit(-1)

def _test_server(self, server):
Expand Down Expand Up @@ -106,7 +106,7 @@ def _load_sub_names(self):
regex_list = []
lines = set()
with open(_file) as f:
for line in f.xreadlines():
for line in f:
sub = line.strip()
if not sub or sub in lines:
continue
Expand Down Expand Up @@ -238,7 +238,7 @@ def _scan(self, j):
_sub = sub.split('.')[-1]
try:
answers = self.resolvers[j].query(cur_sub_domain)
except dns.resolver.NoAnswer, e:
except dns.resolver.NoAnswer as e:
answers = self.ex_resolver.query(cur_sub_domain)

if answers:
Expand Down Expand Up @@ -304,7 +304,7 @@ def run(self):

try:
gevent.joinall(threads)
except KeyboardInterrupt, e:
except KeyboardInterrupt as e:
msg = '[WARNING] User aborted.'
sys.stdout.write('\r' + msg + ' ' * (self.console_width - len(msg)) + '\n\r')
sys.stdout.flush()
Expand All @@ -331,4 +331,4 @@ def run(self):
d = SubNameBrute(target=args[0], options=options)
d.run()
d.outfile.flush()
d.outfile.close()
d.outfile.close()