Created
October 2, 2023 11:53
-
-
Save voidbert/66d0b69e5a317b961aa3d2a23382bcdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 | |
20 | |
21 | |
22 | |
23 | |
43 | |
80 | |
81 | |
110 | |
143 | |
443 | |
465 | |
554 | |
563 | |
587 | |
993 | |
995 | |
1194 | |
1521 | |
1723 | |
1863 | |
1935 | |
2083 | |
2087 | |
2096 | |
2187 | |
2401 | |
3306 | |
3389 | |
3690 | |
4000 | |
4244 | |
5004 | |
5060 | |
5061 | |
5190 | |
5222 | |
5223 | |
5228 | |
5242 | |
5900 | |
5901 | |
6667 | |
8080 | |
8443 | |
9418 | |
10000 | |
11371 | |
30333 | |
30334 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
# Prints open ports in the pickle database generated by testports.py | |
with open('ports.pickle', 'rb') as file: | |
available_ports = pickle.load(file) | |
for port, code in available_ports.items(): | |
if code is not None: | |
print(port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pickle | |
import requests | |
import sys | |
import time | |
# Use openports.py afterwards, to list open ports | |
ports = range(0, 2 ** 16 - 1) | |
if os.getuid() != 0 and any(map(lambda p: p < 1024, ports)): | |
print("You aren't root and your ports require it. Leaving ...") | |
sys.exit(1) | |
if os.path.isfile('ports.pickle'): | |
with open('ports.pickle', 'rb') as file: | |
available_ports = pickle.load(file) | |
else: | |
available_ports = {} | |
try: | |
for port in filter(lambda p: p not in available_ports, ports): | |
try: | |
res = requests.get(f'http://portquiz.net:{port}') | |
except Exception: | |
print(f'{str(port).zfill(len(str(ports.stop)))}: fail') | |
available_ports[port] = None | |
continue | |
print(f'{str(port).zfill(len(str(ports.stop)))}: {res.status_code}') | |
available_ports[port] = res.status_code | |
if res.status_code == 200: # Don't sleep if request is blocked by network | |
time.sleep(1) | |
except KeyboardInterrupt: | |
with open('ports.pickle', 'wb') as file: | |
pickle.dump(available_ports, file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment