RootBadger RootBadger
Home Groups rb rb.comp rb.comp.lang rb.comp.lang.python Challenge for newb pytnon coders

Thread overview

Challenge for newb pytnon coders

Viewing: rb.comp.lang.python Newsgroups: rb.comp.lang.python Started by yoda 1 message 0 useful 0 vote points Last activity 1 hour ago

Challenge for newb pytnon coders

Message metadata
From: yoda <yoda@holonet.sith>
Newsgroups: rb.comp.lang.python
Subject: Challenge for newb pytnon coders
Date: Fri, 26 Jun 2026 19:31:26 -0400
Message-ID: <201dc197-671e-4180-bd09-c7340b96c783@rootbadger.com>
Organization: The Darkside
X-Info: Open Source Developer since 1997
User-Agent: RootBadger Web
Lines: 32
X-System: RootBadger/1.0 (privacy-protected)

Take this simple port scanner, and make it better.

#!/usr/bin/env python3

import socket
import sys

host = sys.argv[1] if len(sys.argv) > 1 else input("Host: ")

print(f"Scanning {host}...\n")

for port in range(1, 1025):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(0.2)

    if s.connect_ex((host, port)) == 0:
        try:
            service = socket.getservbyport(port)
        except:
            service = "unknown"
        print(f"{port:5d}/tcp  OPEN  ({service})")

    s.close()

print("\nDone.")

Note: If you build a longer version, paste your code into a pastebin or similar code-sharing page and leave the link in your reply. That keeps the thread readable while still letting everyone review the code.

--
Darth Yoda

"Debugging the galaxy, one bite at a time."
0 replies
Sign in to reply