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

Fix python3 compatibility #340

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
22 changes: 11 additions & 11 deletions dnsrecon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def process_spf_data(res, data):

# Create a list of IPNetwork objects.
for ip in ipv4:
for i in IPNetwork(ip):
for i in netaddr.IPNetwork(ip):
ip_list.append(i)

for ip in ipv6:
for i in IPNetwork(ip):
for i in netaddr.IPNetwork(ip):
ip_list.append(i)

# Extract and process include values.
Expand All @@ -138,22 +138,22 @@ def expand_cidr(cidr_to_expand):
Function to expand a given CIDR and return an Array of IP Addresses that
form the range covered by the CIDR.
"""
return IPNetwork(cidr_to_expand)
return netaddr.IPNetwork(cidr_to_expand)


def expand_range(startip, endip):
"""
Function to expand a given range and return an Array of IP Addresses that
form the range.
"""
return IPRange(startip, endip)
return netaddr.IPRange(startip, endip)


def range2cidr(ip1, ip2):
"""
Function to return the maximum CIDR given a range of IP's
"""
r1 = IPRange(ip1, ip2)
r1 = netaddr.IPRange(ip1, ip2)
return str(r1.cidrs()[-1])


Expand Down Expand Up @@ -385,8 +385,8 @@ def brute_srv(res, domain, verbose=False, thread_num=None):
future_results = {executor.submit(res.get_srv, srvtype + domain): srvtype for srvtype in srvrcd}
# Display logs as soon as a thread is finished
for future in futures.as_completed(future_results):
res = future.result()
for type_, name_, target_, addr_, port_, priority_ in res:
result = future.result()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the code correctly, this was variable shadowing and not intentional.

for type_, name_, target_, addr_, port_, priority_ in result:
returned_records.append(
{
'type': type_,
Expand Down Expand Up @@ -496,8 +496,8 @@ def brute_domain(
future_results = {executor.submit(res.get_ip, target): target for target in targets}
# Display logs as soon as a thread is finished
for future in futures.as_completed(future_results):
res = future.result()
for type_, name_, address_or_target_ in res:
result = future.result()
for type_, name_, address_or_target_ in result:
print_and_append = False
found_dict = {'type': type_, 'name': name_}
if type_ in ['A', 'AAAA']:
Expand Down Expand Up @@ -1707,7 +1707,7 @@ def main():

# if user requests tool version, we print it and exit
if arguments.version:
print(f'DNSRecon version {__version__} https://www.darkoperator.com')
logger.info(f'DNSRecon version {__version__} https://www.darkoperator.com')
sys.exit(0)

# validating type param which is in the form: type1,type2,...,typeN
Expand Down Expand Up @@ -1937,7 +1937,7 @@ def main():
if crt_enum_records is not None and do_output:
all_returned_records.extend(crt_enum_records)
else:
print('[-] No records returned from crt.sh enumeration')
logger.info('[-] No records returned from crt.sh enumeration')

elif type_ == 'snoop':
if not (dictionary and ns_server):
Expand Down
25 changes: 12 additions & 13 deletions dnsrecon/lib/whois.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import re
import socket

from netaddr import *
import ipaddress

__name__ = 'whois.py'

Expand All @@ -27,19 +27,16 @@
def get_whois(ip_addrs):
"""
Function that returns what whois server is the one to be queried for
registration information, returns whois.arin.net is not in database, returns
registration information, returns whois.arin.net if not in database, returns
None if private.
"""
whois_server = None
ip = IPAddress(ip_addrs)
info_of_ip = ip.info
if ip.version == 4 and ip.is_private() is False:
for i in info_of_ip['IPv4']:
whois_server = i['whois']
if len(whois_server) == 0 and i['status'] != 'Reserved':
whois_server = 'whois.arin.net'
elif len(whois_server) == 0:
whois_server = None
try:
ip = ipaddress.ip_address(ip_addrs)
if isinstance(ip, ipaddress.IPv4Address) and not ip.is_private:
whois_server = 'whois.arin.net'
except ValueError:
whois_server = None

return whois_server

Expand All @@ -61,9 +58,11 @@ def whois(target, whois_srv):
response = ''
while True:
d = s.recv(WHOIS_RECEIVE_BUFFER_SIZE)
response += str(d)
if not d:
break
response += d.decode('utf-8')
counter += 1
if str(d) == '' or counter == 5:
if counter == 5:
break
s.close()
except Exception as e:
Expand Down
Loading