Skip to content

Instantly share code, notes, and snippets.

@jajeffries
Created December 10, 2025 21:09
Show Gist options
  • Select an option

  • Save jajeffries/e15b9a719e087302c564cee13bd42541 to your computer and use it in GitHub Desktop.

Select an option

Save jajeffries/e15b9a719e087302c564cee13bd42541 to your computer and use it in GitHub Desktop.
import socket
from dataclasses import dataclass, field
from typing import List, Iterable
@dataclass
class Host:
host: str
ports: List[int]
timeout: float = 1.0
def scan(self) -> Iterable[int]:
open_ports = []
for port in self.ports:
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(self.timeout)
result = s.connect_ex((self.host, port))
if result == 0:
yield port
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment