-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
171 lines (131 loc) · 5.24 KB
/
functions.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from scapy.all import IP, sr, Scapy_Exception, UDP, TCP, ICMP
import dns.resolver
import requests
import whois
import ipaddress
def geotrack_ip(ip):
try:
# Validate the IP address
ipaddress.IPv4Address(ip)
# Make a request to ipinfo.io
response = requests.get(f'https://ipinfo.io/{ip}/json')
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
data = response.json()
# Extract
location_info = {
'IP': data.get('ip', ''),
'City': data.get('city', ''),
'Region': data.get('region', ''),
'Country': data.get('country', ''),
'Location': data.get('loc', ''),
'ISP': data.get('org', ''),
'AS': data.get('asn', '')
}
return location_info
else:
return f"🐼 failed to get geolocation data. Status code: {response.status_code}"
except ipaddress.AddressValueError:
return "Invalid IP address entered. Please enter a valid IPv4 address."
except Exception as e:
return f"🐼 encountered an error occurred: {str(e)}"
def icmp_scan(target_ip):
try:
# Create an IP layer:
ip_layer = IP(dst=target_ip)
# Create an ICMP layer (Ping request):
icmp_layer = ICMP()
# Create the packet:
packet = ip_layer / icmp_layer
# Send the packet and wait for a response:
response = sr1(packet, timeout=2, verbose=False)
if response and response.haslayer(ICMP):
return f"🐼 detected that {target_ip} is reachable (ICMP Reply received)🎉."
else:
return f"🐼 detected that {target_ip} is unreachable or not responding to ICMP😵."
except Exception as e:
return f"An error occurred: {str(e)}"
def tcp_scan(target_ip, port=80, scan_type="S"):
try:
# Validate target IP
ipaddress.IPv4Address(target_ip)
# Create an IP layer:
ip_layer = IP(dst=target_ip)
# Create a TCP layer:
tcp_layer = TCP(dport=port, flags=scan_type)
# Creating the packet:
packet = ip_layer / tcp_layer
# Get response
response = sr(packet, iface="Wi-Fi", timeout=2, verbose=False)[0]
if response:
return response
if scan_type == "A":
return "🐼 detected that the port is likely to be filtered"
else:
return "Host may be protected or unreachable, 🐼 unable to fetch response"
except ValueError:
return "Invalid IP address entered. Please enter a valid IPv4 address."
except Scapy_Exception as e:
return f"An error occurred: {str(e)}"
def udp_scan(target_ip, port=80):
try:
# Validate target IP
ipaddress.IPv4Address(target_ip)
# Create an IP layer:
ip_layer = IP(dst=target_ip)
# Create a UDP layer:
udp_layer = UDP(dport=port)
# Creating the packet:
packet = ip_layer / udp_layer
# Get response
response = sr(packet, iface="Wi-Fi", timeout=2, verbose=False)[0]
if response:
return response
else:
return "🐼 did not receive a response. The port may be closed or filtered 📪"
except ValueError:
return "Invalid IP address entered. Please enter a valid IPv4 address for 🐼 to function."
except Scapy_Exception as e:
return f"An error occurred: {str(e)}"
def dns_enum(domain):
try:
# Perform DNS A record query to get IP addresses associated with the domain
a_records = dns.resolver.resolve(domain, 'A')
ips = [record.address for record in a_records]
# Perform DNS MX record query to get mail servers associated with the domain
mx_records = dns.resolver.resolve(domain, 'MX')
mail_servers = [(record.preference, str(record.exchange)) for record in mx_records]
# Perform DNS NS record query to get name servers associated with the domain
ns_records = dns.resolver.resolve(domain, 'NS')
name_servers = [str(record) for record in ns_records]
# Return the gathered information
return {
'IP Addresses': ips,
'Mail Servers': mail_servers,
'Name Servers': name_servers
}
except dns.resolver.NXDOMAIN:
return f"🐼 was unable to find Domain: '{domain}'."
except Exception as e:
return f"🐼encountered an error: {str(e)}"
def whois_lookup(domain):
try:
result = whois.whois(domain)
# Extract
domain_info = {
'Domain Name': result.domain_name,
'Registrar': result.registrar,
'Creation Date': result.creation_date,
'Expiration Date': result.expiration_date,
'Updated Date': result.updated_date,
'Name Servers': result.name_servers,
'Status': result.status,
'WHOIS Server': result.whois_server,
'Registrant': result.registrant,
'Admin': result.admin,
'Tech': result.tech
}
return domain_info
except Exception as e:
return f"🐼 encountered an error during WHOIS lookup: {str(e)}"