import socket
import re
ip_add_pattern = re.compile("^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$")
port_range_pattern = re.compile("([0-9]+)-([0-9]+)")
port_min = 0
port_max = 65535
print(
""" _ _____ _ ___ _______ _____ _ _ _____
| | |_ _| | / / | | | ___ \ __ \ | | / ___|
| | | | | |/ /| | | | |_/ / | \/ | | \ `--.
| | | | | \| | | | /| | __| | | |`--. \.
| |_____| |_| |\ \ |_| | |\ \| |_\ \ |_| /\__/ /
\_____/\___/\_| \_/\___/\_| \_|\____/\___/\____/ """)
print("\n****************************************************************")
open_ports = []
while True:
ip_add_entered = input("\nTarama yapmak istediğiniz IP adresini giriniz: ")
if ip_add_pattern.search(ip_add_entered):
print(f"{ip_add_entered} geçerli IP adresi")
break
while True:
print("Taramak istediğiniz Port aralığını yazınız: <int>-<int> (örnek olarak 60-120)")
port_range = input("Port Aralığını Girin: ")
port_range_valid = port_range_pattern.search(port_range.replace(" ",""))
if port_range_valid:
port_min = int(port_range_valid.group(1))
port_max = int(port_range_valid.group(2))
break
for port in range(port_min, port_max + 1):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(0.5)
s.connect((ip_add_entered, port))
open_ports.append(port)
except:
pass
for port in open_ports:
print(f"Port {port} açık.")