-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolver.py
More file actions
73 lines (63 loc) · 2.48 KB
/
resolver.py
File metadata and controls
73 lines (63 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import socket
import argparse
from time import sleep
# Colors for terminal output
R = '\033[1;31m'
G = '\033[1;32m'
B = '\x1b[1;34m'
M = '\x1b[38;5;8m'
J = '\x1b[1;33m'
# Function to resolve domain to IP(s)
def resolve_domain(domain):
try:
print(f"{J}Resolving domain: {domain}...")
ip_address = socket.gethostbyname(domain)
ip_list = socket.gethostbyname_ex(domain)
print(f"{G}IP Address(es) for {domain}: {ip_list[2]}")
return ip_list[2] # Return all IP addresses associated with the domain
except socket.gaierror:
print(f"{R}Error: Unable to resolve domain {domain}")
return []
# Function to scan ports
def scan_ports(url, ports):
open_ports = []
for port in ports:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP
sock.settimeout(1)
sock.connect((url, port))
open_ports.append(port)
print(f"{B}�{G}THE PORT {port} IS OPEN")
sock.close()
except:
print(f"{B}�{R}THE PORT {port} IS CLOSED")
return open_ports
# Main function
def main():
# Setting up argument parsing
parser = argparse.ArgumentParser(description='Resolve domain and scan ports')
parser.add_argument('-d', '--domain', type=str, required=True, help='Target domain to resolve and scan')
args = parser.parse_args()
# Resolve domain to IP(s)
domain = args.domain
ip_list = resolve_domain(domain)
if ip_list:
# Ports to scan
ports = [19, 20, 21, 22, 23, 24, 25, 80, 53, 111, 110, 443, 8080, 139, 445, 512, 513, 514, 4444, 2049, 1524, 3306, 5900]
all_open_ports = []
# Scan ports for each IP resolved
for ip in ip_list:
print(f"\n{J}Scanning ports on IP: {ip}...")
open_ports = scan_ports(ip, ports)
if open_ports:
all_open_ports.append((ip, open_ports))
else:
print(f"{R}No open ports found on {ip}")
# Show the final summary
print(f"\n{J}-----------------------------SCAN SUMMARY-----------------------------")
for ip, open_ports in all_open_ports:
print(f"{G}IP: {ip} -> Open Ports: {open_ports}")
print(f"{J}---------------------------------------------------------------------\n")
# Run the script if this is the main module
if __name__ == "__main__":
main()