Comment & lint

This commit is contained in:
David Mougeolle 2020-03-18 15:40:07 +01:00
parent f57353cef5
commit 59afb7f609

View file

@ -1,3 +1,15 @@
# -*- coding: utf-8 -*-
"""
============
DNS Browsing
============
Explore the space around known hosts & ips for extra catches.
"""
from __future__ import absolute_import, division, print_function
import asyncio import asyncio
import re import re
import sys import sys
@ -8,6 +20,9 @@
# TODO: need big focus on performance and results parsing, now does the basic. # TODO: need big focus on performance and results parsing, now does the basic.
#####################################################################
# DNS FORCE
#####################################################################
class DnsForce: class DnsForce:
@ -113,8 +128,7 @@ def list_ips_in_network_range(
async def reverse_single_ip( async def reverse_single_ip(
ip: str, ip: str,
resolver: DNSResolver, resolver: DNSResolver) -> Awaitable[str]:
verbose: bool = False) -> Awaitable[str]:
""" """
Reverse a single IP and output the linked CNAME, if it exists. Reverse a single IP and output the linked CNAME, if it exists.
@ -122,31 +136,21 @@ async def reverse_single_ip(
---------- ----------
ip: str. ip: str.
The IP to reverse. The IP to reverse.
verbose: bool.
Print the progress or not.
Returns Returns
------- -------
out: str. out: str.
The corresponding CNAME or None. The corresponding CNAME or None.
""" """
if verbose:
sys.stdout.write(chr(27) + '[2K' + chr(27) + '[G')
sys.stdout.write('\r' + ip + ' - ')
sys.stdout.flush()
try: try:
__host = await resolver.gethostbyaddr(ip) __host = await resolver.gethostbyaddr(ip)
if __host: return __host.name if __host else ''
print(__host.name)
return __host.name
else:
return ''
except Exception: except Exception:
return '' return ''
async def reverse_ip_range( async def reverse_all_ips_in_range(
iprange: str, iprange: str,
verbose: bool = False) -> AsyncGenerator[str]: verbose: bool = False) -> AsyncGenerator[str, None]:
""" """
Reverse all the IPs stored in a network range. Reverse all the IPs stored in a network range.
@ -154,7 +158,8 @@ async def reverse_ip_range(
---------- ----------
iprange: str. iprange: str.
An IPv4 range formated as 'x.x.x.x/y'. An IPv4 range formated as 'x.x.x.x/y'.
The last digit can be set to anything, it will be ignored. The last 2 digits of the ip can be set to anything,
they will be ignored.
verbose: bool. verbose: bool.
Print the progress or not. Print the progress or not.
@ -165,7 +170,16 @@ async def reverse_ip_range(
""" """
__resolver = DNSResolver(timeout=4) __resolver = DNSResolver(timeout=4)
for ip in list_ips_in_network_range(iprange): for ip in list_ips_in_network_range(iprange):
__host = await reverse_single_ip(ip=ip, resolver=__resolver, verbose=verbose) # Display the current query
if verbose:
sys.stdout.write(chr(27) + '[2K' + chr(27) + '[G')
sys.stdout.write('\r' + ip + ' - ')
sys.stdout.flush()
# Reverse the ip
__host = await reverse_single_ip(ip=ip, resolver=__resolver)
# Output the results
if __host is not None and __host: if __host is not None and __host:
# print(' : ' + host.split(':')[1]) print(__host)
yield __host yield __host