Last active
November 10, 2022 10:12
-
-
Save retr00exe/1c591144c6b809da5738e06b5755f5c3 to your computer and use it in GitHub Desktop.
Simple port scanner using Python socket library
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 socket | |
import threading | |
import concurrent.futures | |
import colorama | |
from colorama import Fore | |
colorama.init() | |
print_lock = threading.Lock() | |
def title(): | |
title = """ | |
██████╗ ██████╗ ██████╗ ████████╗ ███████╗ ██████╗ █████╗ ███╗ ██╗███╗ ██╗███████╗██████╗ | |
██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝ ██╔════╝██╔════╝██╔══██╗████╗ ██║████╗ ██║██╔════╝██╔══██╗ | |
██████╔╝██║ ██║██████╔╝ ██║ ███████╗██║ ███████║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ | |
██╔═══╝ ██║ ██║██╔══██╗ ██║ ╚════██║██║ ██╔══██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ | |
██║ ╚██████╔╝██║ ██║ ██║ ███████║╚██████╗██║ ██║██║ ╚████║██║ ╚████║███████╗██║ ██║ | |
╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ | |
v1.0.0 | |
by retr00exe | |
""" | |
print(title) | |
def scan(ip, port): | |
scanner = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
scanner.settimeout(100) | |
try: | |
scanner.connect((ip, port)) | |
scanner.close() | |
with print_lock: | |
print(Fore.WHITE + f"[{port}]" + Fore.GREEN + " Opened") | |
except: | |
pass | |
def main(): | |
title() | |
ip = input("Enter the IP to scan : ") | |
print("[*] Checking from port 1 to port 65535") | |
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: | |
for port in range(0xFFFF): | |
executor.submit(scan, ip, port + 1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey just reaching out in line 38, what does that function do?
also in line 39: why did you use a hex value instead?
cheers