import random
import socket
import time

# Türkiye'ye ait IP aralıkları (ilk ve son adresler)
turkey_ip_ranges = [
    (31, 145, 0, 0, 31, 145, 255, 255),
    (78, 160, 0, 0, 78, 169, 255, 255),
    (85, 96, 0, 0, 85, 103, 255, 255),
    (88, 224, 0, 0, 88, 255, 255, 255),
    (176, 32, 0, 0, 176, 32, 255, 255),
    (188, 3, 0, 0, 188, 3, 255, 255),
    (195, 174, 0, 0, 195, 174, 255, 255)
]

def generate_turkish_ip():
    # Rastgele bir aralık seç
    ip_range = random.choice(turkey_ip_ranges)
    
    # Her oktet için rastgele bir sayı üret
    first = random.randint(ip_range[0], ip_range[4])
    second = random.randint(ip_range[1], ip_range[5])
    third = random.randint(ip_range[2], ip_range[6])
    fourth = random.randint(ip_range[3], ip_range[7])
    
    return f"{first}.{second}.{third}.{fourth}"

def is_port_open(ip, port):
    # Bir soket oluştur
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)  # Bağlantı için 1 saniye bekle
    try:
        # IP ve port üzerinden bağlantı kurmaya çalış
        result = sock.connect_ex((ip, port))
        sock.close()
        return result == 0  # Bağlantı başarılıysa 0 döner
    except socket.error:
        return False

# Sürekli rastgele IP üretip 80. portu kontrol eder
while True:
    ip = generate_turkish_ip()
    
    if is_port_open(ip, 80):
        # Yeşil renkte başarı mesajı göster
        print(f"\033[92m80. portu açık olan IP adresi bulundu: {ip}\033[0m")
    
    # Çok sık kontrol yapmayı engellemek için küçük bir gecikme ekliyoruz
    time.sleep(0.5)
