-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip2.py
More file actions
55 lines (48 loc) · 1.52 KB
/
ip2.py
File metadata and controls
55 lines (48 loc) · 1.52 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
import random
import subprocess
import requests
def generate_ip_prefix():
while True:
ip = ".".join(str(random.randint(0, 255)) for _ in range(3)) + "."
first, second = map(int, ip.split(".")[:2])
if (first == 10 or
(first == 172 and 16 <= second <= 31) or
(first == 192 and second == 168) or
first == 127 or
first == 0 or
first >= 224):
continue
return ip
# Generate one random public prefix
prefix = generate_ip_prefix()
print(f"🔎 Scanning /24 block: {prefix}0/24\n")
ports = "80,81,443,8080,8443"
# Run RustScan
result = subprocess.run(
["rustscan", "-a", prefix + "0/24", "-p", ports, "-b", "200", "-t", "2000", "--ulimit", "5000"],
capture_output=True, text=True
)
# Deduplicate and clean results
open_hosts = set()
for line in result.stdout.splitlines():
if "Open" in line:
open_hosts.add(line.strip())
elif "Discovered open port" in line:
parts = line.split()
port = parts[3].split("/")[0]
host = parts[-1]
open_hosts.add(f"{host}:{port}")
# Check HTTP response codes
valid_hosts = []
for entry in sorted(open_hosts):
try:
host, port = entry.split(":")
url = f"http://{host}:{port}"
r = requests.get(url, timeout=3, allow_redirects=False)
if r.status_code in [200, 301, 302, 307, 308]:
valid_hosts.append(f"{entry} [{r.status_code}]")
except Exception:
pass
# Print filtered results
for vh in valid_hosts:
print(vh)