├── requirements.txt ├── HostResolver.png ├── .gitignore ├── setup.py ├── README.md ├── LICENSE └── resolv.py /requirements.txt: -------------------------------------------------------------------------------- 1 | dnspython==2.7.0 2 | rich==14.0.0 3 | setuptools -------------------------------------------------------------------------------- /HostResolver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subfission/HostResolver/HEAD/HostResolver.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | .Python 3 | .idea/ 4 | bin/ 5 | include/ 6 | lib/ 7 | pip-selfcheck.json 8 | .DS_Store -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # setup.py 2 | # 3 | # Copyright (c) 2017-2018, Zach Jetson All rights reserved. 4 | # 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # Author: Zach Jetson 19 | # Date: May 2017-2025 20 | # Name: resolv.py 21 | # 22 | # This file will setup the Host Resolver script. 23 | 24 | from setuptools import find_packages, setup 25 | 26 | """This file will setup the Host Resolver script.""" 27 | 28 | setup( 29 | name='resolv', 30 | description='Host resolver script.', 31 | long_description="Resolve hosts to IP addresses, scan for SPF records, and enumerate ASNs as quickly as possible.", 32 | author='Zach Jetson', 33 | maintainer='Zach Jetson', 34 | packages=find_packages(), 35 | keywords='host resolver enumeration', 36 | 37 | entry_points={ 38 | 'console_scripts': ['resolv = resolv:main'] 39 | }, 40 | 41 | python_requires='>=3.7,<3.13', 42 | setup_requires=[], 43 | install_requires=[ 44 | "setuptools==79.0.1", 45 | "dnspython==2.7.0", 46 | "rich==14.0.0" 47 | ] 48 | ) 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HostResolver 2 | Resolve hosts to IP addresses, scan for SPF records, and enumerate ASNs as quickly as possible; because time is of the essence. 3 | 4 | This script is contained to a single python file for portability. 5 | 6 | ![HostResolver Screenshot](https://raw.githubusercontent.com/subfission/HostResolver/master/HostResolver.png) 7 | 8 | ## Requirements 9 | * **Python 3.11+** 10 | 11 | ## Installation 12 | First make sure you have python 3.4+ and the python package manger (pip). 13 | 14 | python3 --version 15 | which pip3 16 | 17 | Download all the dependencies using the package manager: 18 | 19 | pip3 install -r requirements.txt 20 | 21 | **Thats it!** 22 | 23 | Optionally, you can use virtual_env or other tools to manage your packages. 24 | 25 | 26 | ## Usage 27 | 28 | **Single host lookup** 29 | 30 | python3 resolv.py hostname 31 | 32 | **Lookup list of hostnames from file** 33 | 34 | python3 resolve.py hostnames_file.txt 35 | 36 | **Advanced usage: Resolve all record types From List to JSON** 37 | 38 | python3 resolv.py --asn --org --spf --cname --dkim --aaaa --mx --dmarc --reverse hostname_list.txt 39 | 40 | **Setup script as an executable** 41 | 42 | chmod +x resolv.py && mv resolv.py resolv 43 | ./resolv -h 44 | 45 | ## Updates 46 | 47 | - Updated support for newer Python 3.11+ 48 | - Supports DMARK & DKIM 49 | - Uses async for even faster resolution 50 | - Improved error handling 51 | - Reverse lookups 52 | - Most fields are toggleable 53 | - Support for AAAA, MX, and CNAME host records 54 | - New outputs: JSON, SQLite, CSV 55 | - Verbose debug mode added 56 | 57 | ## Future 58 | 59 | - Flags indicating DNS config issues 60 | - SSL Ciphers per host 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /resolv.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | Copyright (c) 2017-2018, Zach Jetson All rights reserved. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | 18 | Author: Zach Jetson 19 | Date: May 2017 20 | Name: resolv.py 21 | 22 | 23 | Quickly resolve a large host file list to IP addresses and print them into a table. 24 | 25 | Usage: ./resolv.py hostnames.txt [-h] 26 | 27 | Requirements 28 | 29 | * Python 3.11 30 | * Rich 31 | * dnspython 32 | 33 | Sample Output 34 | 35 | $ ./resolv.py hostnames.txt 36 | 37 | Resolving hosts from file [hostnames.txt] 38 | +---------------+----------------+ 39 | | Hostname | IP | 40 | +---------------+----------------+ 41 | | google.com | 216.58.216.14 | 42 | | yahoo.com | 98.138.253.109 | 43 | | outlook.com | 40.97.156.114 | 44 | | askjeeves.com | 66.235.121.240 | 45 | +---------------+----------------+ 46 | 47 | """ 48 | 49 | import argparse 50 | import asyncio 51 | import csv 52 | import re 53 | import sqlite3 54 | import sys 55 | import traceback 56 | from functools import lru_cache 57 | from typing import Any, Dict, List 58 | 59 | try: 60 | import dns.asyncresolver 61 | import dns.exception 62 | import dns.reversename 63 | from rich.console import Console 64 | from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn, TimeElapsedColumn 65 | from rich.table import Table 66 | from rich.json import JSON 67 | except ModuleNotFoundError as e: 68 | print(str(e), file=sys.stderr) 69 | print("Unable to import required module.", file=sys.stderr) 70 | print("Run 'pip3 install requirements.txt' to continue... ", file=sys.stderr) 71 | sys.exit(1) 72 | 73 | console = Console() 74 | resolver = dns.asyncresolver.Resolver(configure=True) 75 | resolver.timeout = 2 76 | resolver.lifetime = 2 77 | 78 | DOMAIN_REGEX = re.compile( 79 | r"^(?=.{1,253}$)(?!-)[A-Za-z0-9-]{1,63}(? List[str]: 90 | try: 91 | answers = await resolver.resolve(domain, rtype) 92 | return [r.to_text() for r in answers] 93 | except (dns.resolver.NoAnswer, dns.resolver.NXDOMAIN, dns.exception.Timeout): 94 | return [] 95 | 96 | async def reverse_lookup(ip: str) -> str: 97 | rev_name = dns.reversename.from_address(ip) 98 | answers = await resolver.resolve(rev_name, "PTR") 99 | return str(answers[0]) if answers else "" 100 | 101 | 102 | @lru_cache(maxsize=512) 103 | def get_asn_info_cached(ip: str): 104 | return ip 105 | 106 | async def get_asn_info(ip: str) -> str: 107 | try: 108 | reversed_ip = ".".join(reversed(ip.split("."))) 109 | query = f"{reversed_ip}.origin.asn.cymru.com" 110 | answer = await resolver.resolve(query, "TXT") 111 | return str(answer[0]).strip('"').split(" | ")[0] if answer else "" 112 | except Exception as e: 113 | return str(e) 114 | 115 | @lru_cache(maxsize=512) 116 | def get_asn_org_cached(asn: str): 117 | return asn 118 | 119 | async def get_asn_org(asn: str) -> str: 120 | try: 121 | query = f"AS{asn}.asn.cymru.com" 122 | answer = await resolver.resolve(query, "TXT") 123 | return str(answer[0]).strip('"').split(" | ")[4] if answer else "" 124 | except Exception as e: 125 | return str(e) 126 | 127 | async def get_spf(domain: str) -> str: 128 | records = await resolve_record(domain, "TXT") 129 | return next((r for r in records if "v=spf" in r.lower()), "") 130 | 131 | async def get_dmarc(domain: str) -> str: 132 | records = await resolve_record(f"_dmarc.{domain}", "TXT") 133 | return next((r for r in records if "v=dmarc" in r.lower()), "") 134 | 135 | async def get_dkim(domain: str) -> str: 136 | selectors = ["default", "selector1", "selector2"] 137 | for selector in selectors: 138 | records = await resolve_record(f"{selector}._domainkey.{domain}", "TXT") 139 | for r in records: 140 | if "v=dkim1" in r.lower(): 141 | return r 142 | return "" 143 | 144 | def validate_domain(domain: str) -> bool: 145 | return DOMAIN_REGEX.fullmatch(domain) is not None 146 | 147 | def load_targets(input_path: str) -> List[str]: 148 | try: 149 | if input_path.endswith(".csv"): 150 | with open(input_path, newline="") as f: 151 | reader = csv.DictReader(f) 152 | return [row[reader.fieldnames[0]] for row in reader if row[reader.fieldnames[0]]] 153 | else: 154 | with open(input_path) as f: 155 | return [line.strip() for line in f if line.strip()] 156 | except Exception as e: 157 | console.print(f"[red]Error loading input:[/red] {e}") 158 | sys.exit(1) 159 | 160 | def save_to_sqlite(results: List[Dict[str, Any]], db_path: str, fields: List[str]): 161 | try: 162 | conn = sqlite3.connect(db_path) 163 | col_str = ", ".join([f"{col} TEXT" for col in fields]) 164 | conn.execute(f"CREATE TABLE IF NOT EXISTS results ({col_str})") 165 | for row in results: 166 | placeholders = ", ".join(["?" for _ in fields]) 167 | conn.execute( 168 | f"INSERT INTO results ({', '.join(fields)}) VALUES ({placeholders})", 169 | [row.get(col, "") for col in fields], 170 | ) 171 | conn.commit() 172 | conn.close() 173 | except Exception as e: 174 | console.print(f"[red]SQLite error:[/red] {e}") 175 | 176 | async def query_target(domain: str, opts: Dict[str, bool], debug: bool = False) -> Dict[str, Any]: 177 | result: Dict[str, Any] = {"TARGET": domain} 178 | errors = [] 179 | if not validate_domain(domain): 180 | errors.append("Invalid domain format") 181 | else: 182 | try: 183 | if debug: console.log(f"Resolving A records for {domain}") 184 | a_records = await resolve_record(domain, "A") 185 | result["A"] = "\n".join(a_records) 186 | 187 | asn_list, org_list, reverse_list = [], [], [] 188 | 189 | for ip in a_records: 190 | if debug: console.log(f"Getting ASN for {ip}") 191 | asn = await get_asn_info(ip) 192 | if asn: 193 | asn_list.append(asn) 194 | if opts.get("org"): 195 | if debug: console.log(f"Getting ORG for ASN {asn}") 196 | org = await get_asn_org(asn) 197 | if org: 198 | org_list.append(org) 199 | else: 200 | errors += ["No response for ASN org."] 201 | 202 | if opts.get("reverse"): 203 | if debug: console.log(f"Getting reverse DNS for {ip}") 204 | try: 205 | rev = await reverse_lookup(ip) 206 | if rev: 207 | reverse_list.append(rev) 208 | except Exception as e: 209 | errors += [str(e)] 210 | if opts.get("asn"): 211 | result["ASN"] = "\n".join(asn_list) 212 | if org_list: result["ORG"] = "\n".join(org_list) 213 | if reverse_list: result["Reverse"] = "\n".join(reverse_list) 214 | 215 | for rtype in ["AAAA", "CNAME", "MX"]: 216 | if opts.get(rtype.lower()): 217 | if debug: console.log(f"Resolving {rtype} for {domain}") 218 | records = await resolve_record(domain, rtype) 219 | if not records: 220 | errors += ["No answer for " + rtype + " request."] 221 | result[rtype] = "\n".join(records) 222 | 223 | if opts.get("spf"): 224 | if debug: console.log(f"Getting SPF for {domain}") 225 | result["SPF"] = await get_spf(domain) 226 | if not result["SPF"]: errors += ["No response for SPF."] 227 | if opts.get("dmarc"): 228 | if debug: console.log(f"Getting DMARC for {domain}") 229 | result["DMARC"] = await get_dmarc(domain) 230 | if not result["DMARC"]: errors += ["No response for DMARC."] 231 | if opts.get("dkim"): 232 | if debug: console.log(f"Getting DKIM for {domain}") 233 | result["DKIM"] = await get_dkim(domain) 234 | if not result["DKIM"]: errors += ["No response for DKIM."] 235 | 236 | except Exception as e: 237 | errors += str(e) 238 | if debug: 239 | result["TRACE"] = traceback.format_exc() 240 | 241 | result["ERROR"] = "\n".join(errors) 242 | return result 243 | 244 | async def main(): 245 | parser = argparse.ArgumentParser(allow_abbrev=False, 246 | description=r"""{} 247 | ) ( 248 | ( /( ) )\ ) ( 249 | )\()) ( /( (()/( ( )\ ) ( ( 250 | ((_)\ ( ( )\()) /(_))))\( ( ((_)(( ))\ )( 251 | _((_) )\ )\(_))/ (_)) /((_)\ )\ _(_))\ /((_|()) 252 | | || |((_|(_) |_ | _ (_))((_)((_) |)((_|_)) ((_) 253 | | __ / _ (_-< _| | / -_|_-< _ \ \ V // -_)| '_| 254 | |_||_\___/__/\__| |_|_\___/__|___/_|\_/ \___||_| v2 255 | {} 256 | This utility script will perform rapid domain resolution at scale. 257 | {} 258 | By: Zach Jetson 259 | Github: https://github.com/subfission 260 | 261 | """.format('\033[91m', '\033[94m', '\033[0m'), formatter_class=argparse.RawTextHelpFormatter) 262 | parser.add_argument("input", help="A hostname, IP, CSV, or path to or return delimited file containing valid hostnames.") 263 | 264 | # Resolver Configuration 265 | parser.add_argument("--timeout", type=int, default=3) 266 | parser.add_argument("--nocolor", action="store_true", help="Disable colored output") 267 | parser.add_argument("--debug", action="store_true", help="Outputs verbose record information") 268 | 269 | # Optionals 270 | parser.add_argument("--asn", action='store_true', help="Retrieve ASN record(s)") 271 | parser.add_argument("--org", action="store_true", help="Retrieve the ASN organization") 272 | 273 | parser.add_argument("--aaaa", action="store_true", help="Retrieve the DNS AAAA record") 274 | parser.add_argument("--cname", action="store_true", help="Retrieve the DNS CNAME record") 275 | parser.add_argument("--mx", action="store_true", help="Retrieve the DNS MX record") 276 | parser.add_argument("--spf", action='store_true', help="Retrieve the DNS SPF record(s)") 277 | parser.add_argument("--dmarc", action='store_true', help="Retrieve DNS DMARC record") 278 | parser.add_argument("--dkim", action="store_true", help="Retrieve the DNS DKIM record") 279 | parser.add_argument("--reverse", action="store_true", help="Retrieve the DNS reverse lookup record") 280 | 281 | # Outputs 282 | parser.add_argument("--json", action='store_true', help="Output as JSON directly") 283 | parser.add_argument("--csv", help="Output CSV path") 284 | parser.add_argument("--sqlite", help="Output SQLite DB path") 285 | parser.add_argument("--error", action="store_true", help="Display record lookup errors in table output") 286 | 287 | args = parser.parse_args() 288 | resolver.timeout = args.timeout 289 | resolver.lifetime = args.timeout 290 | opts = vars(args) 291 | 292 | if validate_domain(args.input) or re.fullmatch(r"\d{1,3}(?:\.\d{1,3}){3}", args.input): 293 | targets = [args.input] 294 | else: 295 | targets = load_targets(args.input) 296 | 297 | results = [] 298 | errors = 0 299 | debug = args.debug 300 | 301 | with Progress(SpinnerColumn(), BarColumn(), TextColumn("{task.description}"), TimeElapsedColumn(), 302 | transient=True, console=console 303 | ) as progress: 304 | task = progress.add_task("Querying...", total=len(targets)) 305 | for t in targets: 306 | res = await query_target(t, opts, debug) 307 | results.append(res) 308 | if "ERROR" in res: errors += 1 309 | progress.advance(task) 310 | 311 | base_fields = ["TARGET", "A"] 312 | extra_fields = [f.upper() for f in ["asn","org", "aaaa", "cname", "mx", "spf", "dmarc", "dkim", "reverse", "error"] if opts.get(f)] 313 | fields = base_fields + extra_fields 314 | 315 | table = Table(show_header=True, expand=True, header_style="bold green" if not args.nocolor else "") 316 | for field in fields: 317 | table.add_column(field) 318 | 319 | for row in results: 320 | table.add_row(*(row.get(f, "") for f in fields)) 321 | 322 | if not args.json: 323 | console.print(table) 324 | console.print(f"\n[green]Completed:[/green] {len(results)} domain | [red]Record With Errors:[/red] {errors}") 325 | 326 | if args.json: 327 | console.print(JSON.from_data(results), highlight=True) 328 | 329 | if args.csv: 330 | with open(args.csv, "w", newline="") as f: 331 | writer = csv.DictWriter(f, fieldnames=fields) 332 | writer.writeheader() 333 | writer.writerows(results) 334 | if args.sqlite: 335 | save_to_sqlite(results, args.sqlite, fields) 336 | 337 | if __name__ == "__main__": 338 | asyncio.run(main()) 339 | --------------------------------------------------------------------------------