Skip to content

Instantly share code, notes, and snippets.

@retr00exe
Last active November 10, 2022 10:12
Show Gist options
  • Save retr00exe/1c591144c6b809da5738e06b5755f5c3 to your computer and use it in GitHub Desktop.
Save retr00exe/1c591144c6b809da5738e06b5755f5c3 to your computer and use it in GitHub Desktop.
Simple port scanner using Python socket library
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()
@stringpilot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment