Created
December 10, 2025 21:09
-
-
Save jajeffries/e15b9a719e087302c564cee13bd42541 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| 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