Skip to content

Commit f0edaa8

Browse files
committed
refactor(dns_records): simplify DNS resolution by removing custom nameserver support and unused record types
1 parent 4d254d6 commit f0edaa8

1 file changed

Lines changed: 9 additions & 70 deletions

File tree

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
1-
import os
2-
from typing import List, Optional
3-
41
from dns import resolver as dns_resolver
52
from rich import print
63

7-
from bugscanx.utils.common import get_confirm, get_input
8-
9-
10-
def configure_resolver(custom_nameservers: Optional[List[str]] = None):
11-
dns_obj = dns_resolver.Resolver()
12-
13-
if custom_nameservers and len(custom_nameservers) > 0:
14-
dns_obj.nameservers = custom_nameservers
15-
print(
16-
f"[yellow]Using custom DNS servers: "
17-
f"{', '.join(custom_nameservers)}[/yellow]"
18-
)
19-
return dns_obj
20-
21-
is_termux = "com.termux" in os.environ.get(
22-
"PREFIX", ""
23-
) or os.path.exists("/data/data/com.termux")
4+
from bugscanx.utils.common import get_input
245

25-
if is_termux:
26-
dns_obj.nameservers = ["8.8.8.8", "8.8.4.4", "1.1.1.1"]
276

28-
return dns_obj
7+
def configure_resolver():
8+
return dns_resolver.Resolver()
299

3010

31-
def resolve_and_print(
32-
domain: str, record_type: str, custom_nameservers: Optional[List[str]] = None
33-
):
11+
def resolve_and_print(domain, record_type):
3412
print(f"\n[green] {record_type} Records:[/green]")
3513
try:
36-
dns_obj = configure_resolver(custom_nameservers)
14+
dns_obj = configure_resolver()
3715
answers = dns_obj.resolve(domain, record_type)
3816
found = False
3917
for answer in answers:
@@ -43,20 +21,6 @@ def resolve_and_print(
4321
f"[cyan]- {answer.exchange} "
4422
f"(priority: {answer.preference})[/cyan]"
4523
)
46-
elif record_type == "SOA":
47-
print(f"[cyan]- Primary NS: {answer.mname}")
48-
print(f" Responsible: {answer.rname}")
49-
print(f" Serial: {answer.serial}")
50-
print(f" Refresh: {answer.refresh}")
51-
print(f" Retry: {answer.retry}")
52-
print(f" Expire: {answer.expire}")
53-
print(f" Minimum TTL: {answer.minimum}[/cyan]")
54-
elif record_type == "SRV":
55-
print(
56-
f"[cyan]- Priority: {answer.priority}, "
57-
f"Weight: {answer.weight}"
58-
)
59-
print(f" Port: {answer.port}, Target: {answer.target}[/cyan]")
6024
else:
6125
print(f"[cyan]- {answer.to_text()}[/cyan]")
6226
if not found:
@@ -67,7 +31,7 @@ def resolve_and_print(
6731
print(f"[yellow] Error fetching {record_type} record[/yellow]")
6832

6933

70-
def nslookup(domain: str, custom_nameservers: Optional[List[str]] = None):
34+
def nslookup(domain):
7135
print(f"[cyan]\n Performing NSLOOKUP for: {domain}[/cyan]")
7236

7337
record_types = [
@@ -77,41 +41,16 @@ def nslookup(domain: str, custom_nameservers: Optional[List[str]] = None):
7741
"MX",
7842
"NS",
7943
"TXT",
80-
"SOA",
81-
"PTR",
82-
"SRV",
83-
"CAA",
84-
"DNSKEY",
85-
"TLSA",
8644
]
8745

8846
for record_type in record_types:
89-
resolve_and_print(domain, record_type, custom_nameservers)
47+
resolve_and_print(domain, record_type)
9048

9149

9250
def main():
93-
domain = get_input("Enter the domain to lookup")
94-
if not domain:
95-
print("[red] Please enter a valid domain.[/red]")
96-
return
97-
98-
use_custom_dns = get_confirm(" Want to use custom DNS servers?")
99-
custom_nameservers = None
100-
101-
if use_custom_dns:
102-
nameservers_input = get_input(
103-
"Enter DNS servers separated by commas (e.g., 8.8.8.8,1.1.1.1)"
104-
)
105-
if nameservers_input:
106-
custom_nameservers = [
107-
server.strip() for server in nameservers_input.split(",")
108-
]
109-
print(
110-
f"[cyan] Will use custom DNS servers: "
111-
f"{', '.join(custom_nameservers)}[/cyan]"
112-
)
51+
domain = get_input("Enter target")
11352

11453
try:
115-
nslookup(domain, custom_nameservers)
54+
nslookup(domain)
11655
except Exception as e:
11756
print(f"[red] An error occurred during DNS lookup: {str(e)}[/red]")

0 commit comments

Comments
 (0)