Last active
April 24, 2024 11:55
-
-
Save 0xAungkon/86c1a8caa64aff35f74a539cfcfa88ea to your computer and use it in GitHub Desktop.
Cpanel Port Scanner
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 | |
| def scan_ports(host, start_port, end_port, ssh_ports): | |
| open_ports = [] | |
| for port in range(start_port, end_port + 1): | |
| try: | |
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
| s.settimeout(0.1) # Set a timeout to speed up scanning | |
| result = s.connect_ex((host, port)) | |
| if result == 0: | |
| open_ports.append(port) | |
| if port in ssh_ports: | |
| print(f"SSH port found: {port}") | |
| except KeyboardInterrupt: | |
| print("\nScan interrupted by user.") | |
| break | |
| except socket.gaierror: | |
| print("Hostname could not be resolved.") | |
| break | |
| except socket.error: | |
| print("Couldn't connect to server.") | |
| break | |
| return open_ports | |
| if __name__ == "__main__": | |
| host = "127.0.0.1" # Change this to your Linux PC's IP address | |
| start_port = 1 | |
| end_port = 65535 # Maximum port number | |
| ssh_ports = [2222, 22222] # Example list of possible SSH ports | |
| open_ports = scan_ports(host, start_port, end_port, ssh_ports) | |
| print("Open ports:", open_ports) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment