-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_visualizer.py
More file actions
167 lines (144 loc) · 5.63 KB
/
data_visualizer.py
File metadata and controls
167 lines (144 loc) · 5.63 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
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
#!/usr/bin/env python3
import socket
import random
import time
import ipaddress
import struct
import threading
from collections import namedtuple
from urllib.parse import urlparse
class NetworkScanner:
def __init__(self):
self.hosts = []
self.ports = [21, 22, 23, 25, 53, 80, 110, 143, 443, 993, 995, 3306, 3389, 5432, 6379, 8080, 8443]
self.services = {}
self.latency = []
self.results = []
self.lock = threading.Lock()
def generate_ip_pool(self, count=100):
pool = []
for _ in range(count):
ip = f"{random.randint(1, 254)}.{random.randint(0, 254)}.{random.randint(0, 254)}.{random.randint(1, 254)}"
pool.append(ip)
return pool
def is_valid_ip(self, ip):
try:
ipaddress.ip_address(ip)
return True
except:
return False
def simulate_dns_lookup(self, domain):
fake_domains = [
'api.github.com', 'google.com', 'cloudflare.com',
'amazonaws.com', 'azure.microsoft.com', 'digitalocean.com'
]
domain = random.choice(fake_domains)
try:
return socket.gethostbyname(domain)
except:
return None
def mock_port_check(self, ip, port):
time.sleep(random.uniform(0.001, 0.01))
is_open = random.random() > 0.7
if is_open:
service = self.guess_service(port)
return {
'ip': ip,
'port': port,
'open': True,
'service': service,
'banner': self.generate_banner(service)
}
return {'ip': ip, 'port': port, 'open': False}
def guess_service(self, port):
common_services = {
21: 'FTP', 22: 'SSH', 23: 'Telnet', 25: 'SMTP',
53: 'DNS', 80: 'HTTP', 110: 'POP3', 143: 'IMAP',
443: 'HTTPS', 993: 'IMAPS', 995: 'POP3S',
3306: 'MySQL', 5432: 'PostgreSQL', 6379: 'Redis',
8080: 'HTTP-Alt', 8443: 'HTTPS-Alt'
}
return common_services.get(port, 'Unknown')
def generate_banner(self, service):
banners = {
'SSH': 'SSH-2.0-OpenSSH_8.9p1',
'HTTP': 'HTTP/1.1 200 OK\r\nServer: nginx/1.18.0',
'HTTPS': 'HTTP/1.1 200 OK\r\nServer: Apache/2.4.41',
'FTP': '220 (vsFTPd 3.0.3)',
'SMTP': '220 mx.google.com ESMTP'
}
return banners.get(service, f'{service} Server v{random.randint(1,10)}.{random.randint(0,9)}')
def scan_worker(self, ip_list, port):
for ip in ip_list:
result = self.mock_port_check(ip, port)
with self.lock:
self.results.append(result)
def parallel_scan(self, ip_count=50, max_threads=10):
ips = self.generate_ip_pool(ip_count)
threads = []
for port in random.sample(self.ports, 5):
t = threading.Thread(target=self.scan_worker, args=(ips[:20], port))
t.start()
threads.append(t)
for t in threads:
t.join(timeout=2)
def measure_latency(self, host='8.8.8.8'):
for _ in range(10):
start = time.time()
try:
socket.gethostbyname(host)
latency = (time.time() - start) * 1000
self.latency.append(latency)
except:
self.latency.append(random.uniform(10, 50))
time.sleep(0.1)
return {
'min': min(self.latency),
'max': max(self.latency),
'avg': sum(self.latency) / len(self.latency),
'jitter': max(self.latency) - min(self.latency)
}
def traceroute_mock(self, target='google.com'):
hops = []
for i in range(1, random.randint(8, 15)):
hop = {
'hop': i,
'ip': f"{random.randint(1,254)}.{random.randint(0,254)}.{random.randint(0,254)}.{random.randint(1,254)}",
'rtt': random.uniform(5, 100),
'host': f'router-{i}.isp.net'
}
hops.append(hop)
return hops
def dns_enumeration(self, domain='example.com'):
records = []
record_types = ['A', 'AAAA', 'MX', 'TXT', 'NS', 'CNAME']
for rtype in record_types:
if random.random() > 0.3:
records.append({
'type': rtype,
'value': f'{domain}' if rtype == 'A' else f'{rtype.lower()}.{domain}',
'ttl': random.randint(300, 86400)
})
return records
def analyze_ports(self):
open_ports = [r for r in self.results if r.get('open')]
services = {}
for port_info in open_ports:
service = port_info.get('service', 'Unknown')
services[service] = services.get(service, 0) + 1
return {
'total_scanned': len(self.results),
'open_ports': len(open_ports),
'services': services,
'unique_ips': len(set(r['ip'] for r in self.results))
}
def main():
scanner = NetworkScanner()
scanner.parallel_scan(30, 5)
latency = scanner.measure_latency()
routes = scanner.traceroute_mock()
dns = scanner.dns_enumeration()
analysis = scanner.analyze_ports()
print(f"Scan completed: {analysis['total_scanned']} probes, {analysis['open_ports']} open ports")
if __name__ == "__main__":
main()