mirror of
https://github.com/laramies/theHarvester.git
synced 2025-02-26 07:23:17 +08:00
List the ips in any range, not just '/24'
This commit is contained in:
parent
d461316625
commit
80fa09d8d8
1 changed files with 26 additions and 20 deletions
|
@ -2,6 +2,7 @@
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
import dns.reversename
|
import dns.reversename
|
||||||
|
|
||||||
|
from ipaddress import IPv4Address, IPv4Network
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# 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.
|
||||||
|
@ -44,6 +45,28 @@ def process(self):
|
||||||
results.append(host)
|
results.append(host)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
# DNS REVERSE
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
def list_ips_in_network_range(
|
||||||
|
iprange: str) -> List[str]:
|
||||||
|
"""
|
||||||
|
List all the IPs in the range.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
iprange: str.
|
||||||
|
A serialized ip range, like '1.2.3.0/24'.
|
||||||
|
The last digit can be set to anything, it will be ignored.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
out: list.
|
||||||
|
The list of IPs in the range.
|
||||||
|
"""
|
||||||
|
__network = IPv4Network(iprange, strict=False)
|
||||||
|
return [__address.exploded for __address in __network.hosts()]
|
||||||
|
|
||||||
class DnsReverse:
|
class DnsReverse:
|
||||||
"""
|
"""
|
||||||
|
@ -60,7 +83,8 @@ def __init__(
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
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.
|
||||||
verbose: bool.
|
verbose: bool.
|
||||||
Print the progress or not.
|
Print the progress or not.
|
||||||
|
|
||||||
|
@ -71,23 +95,6 @@ def __init__(
|
||||||
self.iprange = iprange
|
self.iprange = iprange
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
|
||||||
def _list_ips_in_range(
|
|
||||||
self) -> List[str]:
|
|
||||||
"""
|
|
||||||
List all the IPs in the range.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
out: list.
|
|
||||||
The list of IPs in the range.
|
|
||||||
"""
|
|
||||||
prefix = '.'.join(
|
|
||||||
self.iprange.split('.')[:-1])
|
|
||||||
return [prefix + '.' + str(i) for i in range(256)]
|
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
self,
|
self,
|
||||||
ip: str) -> str:
|
ip: str) -> str:
|
||||||
|
@ -115,7 +122,6 @@ def run(
|
||||||
a_record_answer = dns.resolver.query(ptr_record_answer[0].to_text(), 'A')
|
a_record_answer = dns.resolver.query(ptr_record_answer[0].to_text(), 'A')
|
||||||
print(a_record_answer.canonical_name)
|
print(a_record_answer.canonical_name)
|
||||||
return str(a_record_answer.canonical_name)
|
return str(a_record_answer.canonical_name)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@ -133,7 +139,7 @@ def process(
|
||||||
The list of all the found CNAME records.
|
The list of all the found CNAME records.
|
||||||
"""
|
"""
|
||||||
results = []
|
results = []
|
||||||
for entry in self._list_ips_in_range():
|
for entry in list_ips_in_network_range(self.iprange):
|
||||||
host = self.run(entry)
|
host = self.run(entry)
|
||||||
if host is not None and host:
|
if host is not None and host:
|
||||||
# print(' : ' + host.split(':')[1])
|
# print(' : ' + host.split(':')[1])
|
||||||
|
|
Loading…
Reference in a new issue