# -*- coding: utf-8 -*-
# 6to4 Configuration Script
# Author: github.com/Azumi67
# This is for educational use and my own learning, please provide me with feedback if possible
# This script is designed to simplify the configuration of 6to4 tunnels.
#
# Supported operating systems: Ubuntu 20, Debian 12, Ubuntu 22, Ubuntu 22
#
# Usage:
#   - Run the script with root privileges.
#   - Follow the on-screen prompts to install, configure, or uninstall the tunnel.
#
#
# Disclaimer:
# This script comes with no warranties or guarantees. Use it at your own risk.
import sys
import re
import os
import shutil
import time
import colorama
from colorama import Fore, Style
import subprocess
from time import sleep
import readline
import netifaces
import netifaces as ni
import io
import ipaddress


sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding="utf-8", errors="replace")

if os.geteuid() != 0:
    print("\033[91mThis script must be run as root. Please use sudo -i.\033[0m")
    sys.exit(1)


def logo():
    logo_path = "/etc/logo2.sh"
    try:
        subprocess.run(["bash", "-c", logo_path], check=True)
    except subprocess.CalledProcessError as e:
        return e

    return None


SYSCTL_CONF = "/etc/sysctl.conf"
BACKUP_CONF = "/etc/sysctl.conf.backup"

SETTINGS = {
    "net.ipv4.ip_forward": "1",
    "net.ipv6.conf.all.disable_ipv6": "0",
    "net.ipv6.conf.default.disable_ipv6": "0",
    "net.ipv6.conf.all.forwarding": "1",
}


def backup_sysctl():
    if not os.path.exists(BACKUP_CONF):
        shutil.copy(SYSCTL_CONF, BACKUP_CONF)
        print(f"\033[93mBackup created at {BACKUP_CONF}\033[0m")
    else:
        print(f"\033[92mBackup already exists at {BACKUP_CONF}\033[0m")


def apply():
    with open(SYSCTL_CONF, "r") as file:
        lines = file.readlines()

    current_settings = {}
    for line in lines:
        if "=" in line:
            key, value = line.strip().split("=", 1)
            current_settings[key.strip()] = value.strip()

    with open(SYSCTL_CONF, "a") as file:
        for key, value in SETTINGS.items():
            if current_settings.get(key) != value:
                file.write(f"{key} = {value}\n")
                subprocess.run(["sysctl", "-w", f"{key}={value}"])
                print(f"\033[92mApplied \033[94m{key} \033[93m= \033[94m{value}\033[0m")
            else:
                print(f"\033[94m{key}\033[93m is already set to {value}\033[0m")


def restore_backup():
    if os.path.exists(BACKUP_CONF):
        shutil.copy(BACKUP_CONF, SYSCTL_CONF)
        subprocess.run(["sysctl", "-p"])
        print(f"\033[93mRestored configuration from {BACKUP_CONF}\033[0m")
    else:
        print(f"\033[91mNo backup found at {BACKUP_CONF}\033[0m")


def display_progress(total, current):
    width = 40
    percentage = current * 100 // total
    completed = width * current // total
    remaining = width - completed

    print(
        "\r[" + "=" * completed + ">" + " " * remaining + "] %d%%" % percentage, end=""
    )


def display_checkmark(message):
    print("\u2714 " + message)


def display_error(message):
    print("\u2718 Error: " + message)


def display_notification(message):
    print("\u2728 " + message)


def display_loading():
    frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
    delay = 0.1
    duration = 5

    end_time = time.time() + duration

    while time.time() < end_time:
        for frame in frames:
            print("\r[" + frame + "] Loading...  ", end="")
            time.sleep(delay)
            print("\r[" + frame + "]             ", end="")
            time.sleep(delay)

def main_menu():
    try:
        while True:
            logo()
            border = "\033[93m+" + "=" * 70 + "+\033[0m"
            content = "\033[93m║            ▌║█║▌│║▌│║▌║▌█║ \033[92mMain Menu\033[93m  ▌│║▌║▌│║║▌█║▌                  ║"
            footer = " \033[92m    Open issues at \033[34mhttps://github.com/Azumi67/6TO4-GRE-IPIP-SIT\033[0m "

            border_length = len(border) - 2
            centered_content = content.center(border_length)

            print(border)
            print(centered_content)
            print(border)

            print(border)
            print(footer)
            print(border)
            print(
                "\033[93m─────────────────────────────────────────────────────────────────────\033[0m"
            )
            display_notification("\033[93mFuture Updates\033[0m")
            print(
                "\033[93m─────────────────────────────────────────────────────────────────────\033[0m"
            )
            print(".   \033[92mDNS + Other methods\033[93m[Working on it]\033[0m")
            print(
                ".   \033[93mEdit Local IP Added\033[97m[NEW]\033[0m"
            )
            print(".   \033[96mISATAP Server & Client Added in Multi (4)\033[0m")
            print(
                ".   \033[97mWireguard local tunnel Added in Multi (4)\033[92m[NEW]\033[0m"
            )
            print(
                ".   \033[93mAdding Reconfig robot for multi methods step by step\033[97m [ IP6IP6 added]\033[0m"
            )
            print(
                "\033[93m─────────────────────────────────────────────────────────────────────\033[0m"
            )
            display_notification("\033[93mMethods & Configs\033[0m")
            print(
                "\033[93m─────────────────────────────────────────────────────────────────────\033[0m"
            )
            print("0. \033[91mStaus \033[97mMenu\033[0m")
            print("1. \033[94mEnable IPV4/IPV6 Forwarding \033[0m")
            print("2. \033[93mSingle Server \033[97mMenu\033[0m")
            print(
                "3. \033[92mMultiple Servers \033[97mMenu\033[92m - [10]KHAREJ [1]IRAN \033[93m| [1]KHAREJ [5]IRAN \033[0m"
            )
            print(
                "4. \033[93mMultiple Servers \033[97mMenu\033[92m - [10]KHAREJ [5]IRAN |\033[96mWireguard Added\033[0m"
            )
            print("5. \033[96mBBR FQ Codel [For IPSEC] BY Kalilovers\033[0m")
            print("6. \033[93mReset timer for Local Tunnels\033[0m")
            print("7. \033[92mEdit Local Tunnels\033[0m")
            print("8. \033[93mLocalTun \033[97m[Self Usage & Online Game]\033[0m")
            print("9. \033[92mReconfig Robot \033[97m[New]\033[0m")
            print("q. Exit")
            print(
                "\033[93m╰─────────────────────────────────────────────────────────────────────╯\033[0m"
            )
            choice = input("\033[5mEnter your choice Please: \033[0m")
            print("choice:", choice)
            if choice == "0":
                status_mnu()

            elif choice == "1":
                update_sysctl()

            elif choice == "2":
                singleserver_mnu()

            elif choice == "3":
                multiserver_mnu()

            elif choice == "4":
                multi2server_mnu()

            elif choice == "5":
                bibi_codel()

            elif choice == "6":
                locals_reset()

            elif choice == "7":
                edit_local()

            elif choice == "8":
                local_tun()

            elif choice == "9":
                robot_menu()

            elif choice == "q":
                print("Exiting...")
                sys.exit()
            else:
                print("Invalid choice.")

            input("Press Enter to continue...")

    except KeyboardInterrupt:
        display_error("\033[91m\nProgram interrupted. Exiting...\033[0m")
        sys.exit()



###
def update_sysctl():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mEnable IPV4/6 Forward Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mApply Stuff\033[0m")
    print("2. \033[93mRestore Stuff\033[0m")
    print("0.\033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            backup_sysctl()
            apply()
            break
        elif server_type == "2":
            restore_backup()
            break
        elif server_type == "0":
            os.system("clear")
            main_menu()
            break
        else:
            print("Invalid choice.")


def locals_reset():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mReset Local tunnels Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mRegular [instant]    Reset local timer\033[0m")
    print("2. \033[93mDelayed [30 seconds] Reset local timer\033[0m")
    print("0.\033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_mainmenunew()
            break
        elif server_type == "2":
            reset_local_mainmenunew()
            break
        elif server_type == "0":
            os.system("clear")
            main_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_mainmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mSingle\033[0m")
    print("2. \033[93mMulti\033[0m")
    print("0.\033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_menu2()
            break
        elif server_type == "2":
            reset_local_menu()
            break
        elif server_type == "0":
            os.system("clear")
            main_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_menu2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset Local Single Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6\033[0m")
    print("2. \033[94mIP6IP6 + IPSEC\033[0m")
    print("3. \033[93mGRE6\033[0m")
    print("4. \033[92mGRE6 + IPSEC\033[0m")
    print("5. \033[92mGRE6TAP\033[0m")
    print("6. \033[92mGRE6TAP + IPSEC\033[0m")
    print("7. \033[92mPrivate\033[0m")
    print("8. \033[93mPrivate + IPSEC\033[0m")
    print("9. \033[91mUninstall\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            display_menu_ipip()
            break
        elif server_type == "2":
            display_menu_ipip()
            break
        elif server_type == "3":
            display_menu_gre6()
            break
        elif server_type == "4":
            display_menu_gre6()
            break
        elif server_type == "5":
            display_menu_gre6tap()
            break
        elif server_type == "6":
            display_menu_gre6tap()
            break
        elif server_type == "7":
            display_menu_private()
            break
        elif server_type == "8":
            display_menu_private()
            break
        elif server_type == "9":
            reset_local_uninstallsingle()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_mainmenu()
            break
        else:
            print("Invalid choice.")


def display_menu_ipip():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("Select an option (1 or 2): ")
    if choice == "1":
        enable_reset_ip6ip6kharejmenu()
    elif choice == "2":
        enable_reset_ip6ip6iranmenu()
    else:
        print("Please select 1 or 2")


def enable_reset_ip6ip6kharejmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip6kharej(interval_seconds)
        reset_ping_ipip6kharej1()
        resetping_service_ipip1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
        print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip6iranmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip6iran(interval_seconds)
        reset_ping_ipip6iran1()
        resetping_service_ipip1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_ping_ipip6kharej1():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a220::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_ipip6iran1():
    script_content = f"""#!/bin/bash
while true; do
    ping -c 2 2002:0db8:1234:a220::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_ipip1():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


def reset_local_ip6ip6kharej(interval):
    service_name = "ip6ip6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down   
ip link delete azumi
ip link set dev azumip down
ip link delete azumip 
/bin/bash /etc/private.sh 
ping -c 1 fd1d:fc98:b73e:b481::2
/bin/bash /etc/ipip.sh 
ping -c 1 2002:0db8:1234:a220::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_local_ip6ip6iran(interval):
    service_name = "ip6ip6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down
ip link delete azumi
ip link set dev azumip down
ip link delete azumip 
/bin/bash /etc/private.sh
ping -c 1 fd1d:fc98:b73e:b481::1 
/bin/bash /etc/ipip.sh 
ping -c 1 2002:0db8:1234:a220::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def display_menu_private():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("Select an option (1 or 2): ")
    if choice == "1":
        enable_reset_privatekharejmenu()
    elif choice == "2":
        enable_reset_privateiranmenu()
    else:
        print("Please select 1 or 2")


def enable_reset_privatekharejmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_privatekharej(interval_seconds)
        reset_ping_privatekharej1()
        resetping_service_private1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_privateiranmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_privateiran(interval_seconds)
        reset_ping_privateiran1()
        resetping_service_private1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def reset_ping_privatekharej1():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_privateiran1():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_private1():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 6to4-1
def reset_local_privatekharej(interval):
    service_name = "privatereset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down
ip link delete azumi 
/bin/bash /etc/private.sh 
ping -c 1 2002:831b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_local_privateiran(interval):
    service_name = "privatereset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down
ip link delete azumi 
/bin/bash /etc/private.sh 
ping -c 1 2002:831b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def display_menu_gre6():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("Select an option (1 or 2): ")
    if choice == "1":
        enable_reset_gre6kharejmenu()
    elif choice == "2":
        enable_reset_gre6iranmenu()
    else:
        print("Please select 1 or 2")


def enable_reset_gre6kharejmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6kharej(interval_seconds)
        reset_ping_gre6kharej1()
        resetping_service_gre61()

    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True

    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6iranmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6iran(interval_seconds)
        reset_ping_gre6iran1()
        resetping_service_gre61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def reset_ping_gre6kharej1():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre61.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_gre6iran1():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre61.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_gre61():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# gre61
def reset_local_gre6kharej(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down
ip link delete azumi
ip link set dev azumig6 down
ip link delete azumig6 
/bin/bash /etc/private.sh 
ping -c 1 fd1d:fc98:b73e:b481::2
/bin/bash /etc/gre6.sh 
ping -c 1 2002:831a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_local_gre6iran(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down
ip link delete azumi
ip link set dev azumig6 down
ip link delete azumig6 
/bin/bash /etc/private.sh 
ping -c 1 fd1d:fc98:b73e:b481::1
/bin/bash /etc/gre6.sh 
ping -c 1 2002:831a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def display_menu_gre6tap():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("Select an option (1 or 2): ")
    if choice == "1":
        enable_reset_gre6tapkharejmenu()
    elif choice == "2":
        enable_reset_gre6tapiranmenu()
    else:
        print("Please select 1 or 2")


def enable_reset_gre6tapkharejmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tapkharej(interval_seconds)
        reset_ping_gre6kharej1()
        resetping_service_gre61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


enable_ipv45forward_called = False


def enable_reset_gre6tapiranmenu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tapiran(interval_seconds)
        reset_ping_gre6iran1()
        resetping_service_gre61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# gre6tap1
def reset_local_gre6tapkharej(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down
ip link delete azumi 
ip link set dev azumig6 down
ip link delete azumig6 
/bin/bash /etc/private.sh
ping -c 1 fd1d:fc98:b73e:b481::2 
/bin/bash /etc/gre6.sh 
ping -c 1 2002:831a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_local_gre6tapiran(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi down
ip link delete azumi 
ip link set dev azumig6 down
ip link delete azumig6 
/bin/bash /etc/private.sh 
ping -c 1 fd1d:fc98:b73e:b481::1
/bin/bash /etc/gre6.sh 
ping -c 1 2002:831a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_local_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset Local Multi Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6\033[0m")
    print("2. \033[94mIP6IP6 + IPSEC\033[0m")
    print("3. \033[93mGRE6\033[0m")
    print("4. \033[92mGRE6 + IPSEC\033[0m")
    print("5. \033[92mGRE6TAP\033[0m")
    print("6. \033[92mGRE6TAP + IPSEC\033[0m")
    print("7. \033[92m6TO4\033[0m")
    print("8. \033[93m6TO4 + IPSEC\033[0m")
    print("9. \033[91mUninstall\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_ip6ip6menu()
            break
        elif server_type == "2":
            reset_local_ip6ip6sec()
            break
        elif server_type == "3":
            reset_local_gre6menu()
            break
        elif server_type == "4":
            reset_local_gre6sec()
            break
        elif server_type == "5":
            reset_local_gre6tapmenu()
            break
        elif server_type == "6":
            reset_local_gre6tapsec()
            break
        elif server_type == "7":
            reset_local_privatemenu()
            break
        elif server_type == "8":
            reset_local_privatesec()
            break
        elif server_type == "9":
            reset_local_uninstall()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_mainmenu()
            break
        else:
            print("Invalid choice.")


def reset_local_uninstall():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset local Uninstall Multi Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6\033[0m")
    print("2. \033[94mIP6IP6 + IPSEC\033[0m")
    print("3. \033[93mGRE6\033[0m")
    print("4. \033[92mGRE6 + IPSEC\033[0m")
    print("5. \033[94mGRE6TAP\033[0m")
    print("6. \033[93mGRE6TAP + IPSEC\033[0m")
    print("7. \033[92m6TO4\033[0m")
    print("8. \033[93m6TO4 + IPSEC\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnu()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnu()
            break
        elif server_type == "3":
            gre6_reset_rmvmnu()
            break
        elif server_type == "4":
            gre6_reset_rmvmnu()
            break
        elif server_type == "5":
            gre6_reset_rmvmnu()
            break
        elif server_type == "6":
            gre6_reset_rmvmnu()
            break
        elif server_type == "7":
            private_reset_rmvmnu()
            break
        elif server_type == "8":
            private_reset_rmvmnu()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_mainmenu()
            break
        else:
            print("Invalid choice.")


def reset_local_uninstallsingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset Local Uninstall Single Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6\033[0m")
    print("2. \033[94mIP6IP6 + IPSEC\033[0m")
    print("3. \033[93mGRE6\033[0m")
    print("4. \033[92mGRE6 + IPSEC\033[0m")
    print("5. \033[94mGRE6TAP\033[0m")
    print("6. \033[93mGRE6TAP + IPSEC\033[0m")
    print("7. \033[92mPrivate\033[0m")
    print("8. \033[93mPrivate + IPSEC\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnussingle()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnussingle()
            break
        elif server_type == "3":
            gre6_reset_rmvmnusingle()
            break
        elif server_type == "4":
            gre6_reset_rmvmnusingle()
            break
        elif server_type == "5":
            gre6_reset_rmvmnusingle()
            break
        elif server_type == "6":
            gre6_reset_rmvmnusingle()
            break
        elif server_type == "7":
            private_reset_rmvmnusingle()
            break
        elif server_type == "8":
            private_reset_rmvmnusingle()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_mainmenu()
            break
        else:
            print("Invalid choice.")


def gre6_reset_rmvmnu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Reset timer for local\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving stuff...\033[0m")

        commands = [
            "sudo rm /etc/ipv4.sh",
            "systemctl disable ipv4",
            "systemctl stop ipv4",
            "sudo rm /etc/systemd/system/ipv4.service" "sudo rm /etc/reset_gre61.sh",
            "sudo rm /etc/reset_gre62.sh",
            "sudo rm /etc/reset_gre63.sh",
            "sudo rm /etc/reset_gre64.sh",
            "sudo rm /etc/reset_gre65.sh",
            "sudo rm /etc/reset_gre66.sh",
            "sudo rm /etc/reset_gre67.sh",
            "sudo rm /etc/reset_gre68.sh",
            "sudo rm /etc/reset_gre69.sh",
            "sudo rm /etc/resetbasedonping1.sh",
            "sudo rm /etc/resetbasedonping2.sh",
            "sudo rm /etc/resetbasedonping3.sh",
            "sudo rm /etc/resetbasedonping4.sh",
            "sudo rm /etc/resetbasedonping5.sh",
            "sudo rm /etc/resetbasedonping6.sh",
            "sudo rm /etc/resetbasedonping7.sh",
            "sudo rm /etc/resetbasedonping8.sh",
            "sudo rm /etc/resetbasedonping9.sh",
            "sudo rm /etc/resetbasedonping10.sh",
            "systemctl disable azumireset1.service",
            "systemctl stop azumireset1.service",
            "sudo rm /etc/systemd/system/azumireset1.service",
            "systemctl disable azumireset2.service",
            "systemctl stop azumireset2.service",
            "sudo rm /etc/systemd/system/azumireset2.service",
            "systemctl disable azumireset3.service",
            "systemctl stop azumireset3.service",
            "sudo rm /etc/systemd/system/azumireset3.service",
            "systemctl disable azumireset4.service",
            "systemctl stop azumireset4.service",
            "sudo rm /etc/systemd/system/azumireset4.service",
            "systemctl disable azumireset5.service",
            "systemctl stop azumireset5.service",
            "sudo rm /etc/systemd/system/azumireset5.service",
            "systemctl disable azumireset6.service",
            "systemctl stop azumireset6.service",
            "sudo rm /etc/systemd/system/azumireset6.service",
            "systemctl disable azumireset7.service",
            "systemctl stop azumireset7.service",
            "sudo rm /etc/systemd/system/azumireset7.service",
            "systemctl disable azumireset8.service",
            "systemctl stop azumireset8.service",
            "sudo rm /etc/systemd/system/azumireset8.service",
            "systemctl disable azumireset9.service",
            "systemctl stop azumireset9.service",
            "sudo rm /etc/systemd/system/azumireset9.service",
            "systemctl disable azumireset10.service",
            "systemctl stop azumireset10.service",
            "sudo rm /etc/systemd/system/azumireset10.service",
            "sudo rm /usr/local/bin/gre61_daemon.sh",
            "sudo rm /usr/local/bin/gre62_daemon.sh",
            "sudo rm /usr/local/bin/gre63_daemon.sh",
            "sudo rm /usr/local/bin/gre64_daemon.sh",
            "sudo rm /usr/local/bin/gre65_daemon.sh",
            "sudo rm /usr/local/bin/gre66_daemon.sh",
            "sudo rm /usr/local/bin/gre67_daemon.sh",
            "sudo rm /usr/local/bin/gre68_daemon.sh",
            "sudo rm /usr/local/bin/gre69_daemon.sh",
            "sudo rm /usr/local/bin/gre610_daemon.sh",
            "systemctl disable gre6reset1.service",
            "systemctl stop gre6reset1.service",
            "sudo rm /etc/systemd/system/gre6reset1.service",
            "systemctl stop gre6reset2.service",
            "sudo rm /etc/systemd/system/gre6reset2.service",
            "systemctl disable gre6reset3.service",
            "systemctl stop gre6reset3.service",
            "sudo rm /etc/systemd/system/gre6reset3.service",
            "systemctl disable gre6reset4.service",
            "systemctl stop gre6reset4.service",
            "sudo rm /etc/systemd/system/gre6reset4.service",
            "systemctl disable gre6reset5.service",
            "systemctl stop gre6reset5.service",
            "sudo rm /etc/systemd/system/gre6reset5.service",
            "systemctl disable gre6reset6.service",
            "systemctl stop gre6reset6.service",
            "sudo rm /etc/systemd/system/gre6reset6.service",
            "systemctl disable gre6reset7.service",
            "systemctl stop gre6reset7.service",
            "sudo rm /etc/systemd/system/gre6reset7.service",
            "systemctl disable gre6reset8.service",
            "systemctl stop gre6reset8.service",
            "sudo rm /etc/systemd/system/gre6reset8.service",
            "systemctl disable gre6reset9.service",
            "systemctl stop gre6reset9.service",
            "sudo rm /etc/systemd/system/gre6reset9.service",
            "systemctl disable gre6reset10.service",
            "systemctl stop gre6reset10.service",
            "sudo rm /etc/systemd/system/gre6reset10.service",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def private_reset_rmvmnu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Reset timer for local\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving stuff...\033[0m")

        commands = [
            "sudo rm /etc/ipv4.sh",
            "systemctl disable ipv4",
            "systemctl stop ipv4",
            "sudo rm /etc/systemd/system/ipv4.service" "sudo rm /etc/reset_private1.sh",
            "sudo rm /etc/reset_private2.sh",
            "sudo rm /etc/reset_private3.sh",
            "sudo rm /etc/reset_private4.sh",
            "sudo rm /etc/reset_private5.sh",
            "sudo rm /etc/reset_private6.sh",
            "sudo rm /etc/reset_private7.sh",
            "sudo rm /etc/reset_private8.sh",
            "sudo rm /etc/reset_private9.sh",
            "sudo rm /etc/reset_private10.sh",
            "sudo rm /etc/resetbasedonping1.sh",
            "sudo rm /etc/resetbasedonping2.sh",
            "sudo rm /etc/resetbasedonping3.sh",
            "sudo rm /etc/resetbasedonping4.sh",
            "sudo rm /etc/resetbasedonping5.sh",
            "sudo rm /etc/resetbasedonping6.sh",
            "sudo rm /etc/resetbasedonping7.sh",
            "sudo rm /etc/resetbasedonping8.sh",
            "sudo rm /etc/resetbasedonping9.sh",
            "sudo rm /etc/resetbasedonping10.sh",
            "systemctl disable azumireset1.service",
            "systemctl stop azumireset1.service",
            "sudo rm /etc/systemd/system/azumireset1.service",
            "systemctl disable azumireset2.service",
            "systemctl stop azumireset2.service",
            "sudo rm /etc/systemd/system/azumireset2.service",
            "systemctl disable azumireset3.service",
            "systemctl stop azumireset3.service",
            "sudo rm /etc/systemd/system/azumireset3.service",
            "systemctl disable azumireset4.service",
            "systemctl stop azumireset4.service",
            "sudo rm /etc/systemd/system/azumireset4.service",
            "systemctl disable azumireset5.service",
            "systemctl stop azumireset5.service",
            "sudo rm /etc/systemd/system/azumireset5.service",
            "systemctl disable azumireset6.service",
            "systemctl stop azumireset6.service",
            "sudo rm /etc/systemd/system/azumireset6.service",
            "systemctl disable azumireset7.service",
            "systemctl stop azumireset7.service",
            "sudo rm /etc/systemd/system/azumireset7.service",
            "systemctl disable azumireset8.service",
            "systemctl stop azumireset8.service",
            "sudo rm /etc/systemd/system/azumireset8.service",
            "systemctl disable azumireset9.service",
            "systemctl stop azumireset9.service",
            "sudo rm /etc/systemd/system/azumireset9.service",
            "systemctl disable azumireset10.service",
            "systemctl stop azumireset10.service",
            "sudo rm /etc/systemd/system/azumireset10.service",
            "sudo rm /usr/local/bin/private1_daemon.sh",
            "sudo rm /usr/local/bin/private2_daemon.sh",
            "sudo rm /usr/local/bin/private3_daemon.sh",
            "sudo rm /usr/local/bin/private4_daemon.sh",
            "sudo rm /usr/local/bin/private5_daemon.sh",
            "sudo rm /usr/local/bin/private6_daemon.sh",
            "sudo rm /usr/local/bin/private7_daemon.sh",
            "sudo rm /usr/local/bin/private8_daemon.sh",
            "sudo rm /usr/local/bin/private9_daemon.sh",
            "sudo rm /usr/local/bin/private10_daemon.sh",
            "systemctl disable privatereset1.service",
            "systemctl stop privatereset1.service",
            "sudo rm /etc/systemd/system/privatereset1.service",
            "systemctl disable privatereset2.service",
            "systemctl stop privatereset2.service",
            "sudo rm /etc/systemd/system/privatereset2.service",
            "systemctl disable privatereset3.service",
            "systemctl stop privatereset3.service",
            "sudo rm /etc/systemd/system/privatereset3.service",
            "systemctl disable privatereset4.service",
            "systemctl stop privatereset4.service",
            "sudo rm /etc/systemd/system/privatereset4.service",
            "systemctl disable privatereset5.service",
            "systemctl stop privatereset5.service",
            "sudo rm /etc/systemd/system/privatereset5.service",
            "systemctl disable privatereset6.service",
            "systemctl stop privatereset6.service",
            "sudo rm /etc/systemd/system/privatereset6.service",
            "systemctl disable privatereset7.service",
            "systemctl stop privatereset7.service",
            "sudo rm /etc/systemd/system/privatereset7.service",
            "systemctl disable privatereset8.service",
            "systemctl stop privatereset8.service",
            "sudo rm /etc/systemd/system/privatereset8.service",
            "systemctl disable privatereset9.service",
            "systemctl stop privatereset9.service",
            "sudo rm /etc/systemd/system/privatereset9.service",
            "systemctl disable privatereset10.service",
            "systemctl stop privatereset10.service",
            "sudo rm /etc/systemd/system/privatereset10.service",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def ipip6_reset_rmvmnu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Reset timer for local\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving stuff...\033[0m")

        commands = [
            "sudo rm /etc/reset_ipip1.sh",
            "sudo rm /etc/reset_ipip2.sh",
            "sudo rm /etc/reset_ipip3.sh",
            "sudo rm /etc/reset_ipip4.sh",
            "sudo rm /etc/reset_ipip5.sh",
            "sudo rm /etc/reset_ipip6.sh",
            "sudo rm /etc/reset_ipip7.sh",
            "sudo rm /etc/reset_ipip8.sh",
            "sudo rm /etc/reset_ipip9.sh",
            "sudo rm /etc/reset_ipip10.sh",
            "sudo rm /etc/resetbasedonping1.sh",
            "sudo rm /etc/resetbasedonping2.sh",
            "sudo rm /etc/resetbasedonping3.sh",
            "sudo rm /etc/resetbasedonping4.sh",
            "sudo rm /etc/resetbasedonping5.sh",
            "sudo rm /etc/resetbasedonping6.sh",
            "sudo rm /etc/resetbasedonping7.sh",
            "sudo rm /etc/resetbasedonping8.sh",
            "sudo rm /etc/resetbasedonping9.sh",
            "sudo rm /etc/resetbasedonping10.sh",
            "systemctl disable azumireset1.service",
            "systemctl stop azumireset1.service",
            "sudo rm /etc/systemd/system/azumireset1.service",
            "systemctl disable azumireset2.service",
            "systemctl stop azumireset2.service",
            "sudo rm /etc/systemd/system/azumireset2.service",
            "systemctl disable azumireset3.service",
            "systemctl stop azumireset3.service",
            "sudo rm /etc/systemd/system/azumireset3.service",
            "systemctl disable azumireset4.service",
            "systemctl stop azumireset4.service",
            "sudo rm /etc/systemd/system/azumireset4.service",
            "systemctl disable azumireset5.service",
            "systemctl stop azumireset5.service",
            "sudo rm /etc/systemd/system/azumireset5.service",
            "systemctl disable azumireset6.service",
            "systemctl stop azumireset6.service",
            "sudo rm /etc/systemd/system/azumireset6.service",
            "systemctl disable azumireset7.service",
            "systemctl stop azumireset7.service",
            "sudo rm /etc/systemd/system/azumireset7.service",
            "systemctl disable azumireset8.service",
            "systemctl stop azumireset8.service",
            "sudo rm /etc/systemd/system/azumireset8.service",
            "systemctl disable azumireset9.service",
            "systemctl stop azumireset9.service",
            "sudo rm /etc/systemd/system/azumireset9.service",
            "systemctl disable azumireset10.service",
            "systemctl stop azumireset10.service",
            "sudo rm /etc/systemd/system/azumireset10.service",
            "sudo rm /usr/local/bin/ipip1_daemon.sh",
            "sudo rm /usr/local/bin/ipip2_daemon.sh",
            "sudo rm /usr/local/bin/ipip3_daemon.sh",
            "sudo rm /usr/local/bin/ipip4_daemon.sh",
            "sudo rm /usr/local/bin/ipip5_daemon.sh",
            "sudo rm /usr/local/bin/ipip6_daemon.sh",
            "sudo rm /usr/local/bin/ipip7_daemon.sh",
            "sudo rm /usr/local/bin/ipip8_daemon.sh",
            "sudo rm /usr/local/bin/ipip9_daemon.sh",
            "sudo rm /usr/local/bin/ipip10_daemon.sh",
            "sudo rm /etc/ipv4.sh",
            "systemctl disable ipv4",
            "systemctl stop ipv4",
            "sudo rm /etc/systemd/system/ipv4.service"
            "systemctl disable ip6ip6reset1.service",
            "systemctl stop ip6ip6reset1.service",
            "sudo rm /etc/systemd/system/ip6ip6reset1.service",
            "systemctl disable ip6ip6reset2.service",
            "systemctl stop ip6ip6reset2.service",
            "sudo rm /etc/systemd/system/ip6ip6reset2.service",
            "systemctl disable ip6ip6reset3.service",
            "systemctl stop ip6ip6reset3.service",
            "sudo rm /etc/systemd/system/ip6ip6reset3.service",
            "systemctl disable ip6ip6reset4.service",
            "systemctl stop ip6ip6reset4.service",
            "sudo rm /etc/systemd/system/ip6ip6reset4.service",
            "systemctl disable ip6ip6reset5.service",
            "systemctl stop ip6ip6reset5.service",
            "sudo rm /etc/systemd/system/ip6ip6reset5.service",
            "systemctl disable ip6ip6reset6.service",
            "systemctl stop ip6ip6reset6.service",
            "sudo rm /etc/systemd/system/ip6ip6reset6.service",
            "systemctl disable ip6ip6reset7.service",
            "systemctl stop ip6ip6reset7.service",
            "sudo rm /etc/systemd/system/ip6ip6reset7.service",
            "systemctl disable ip6ip6reset8.service",
            "systemctl stop ip6ip6reset8.service",
            "sudo rm /etc/systemd/system/ip6ip6reset8.service",
            "systemctl disable ip6ip6reset9.service",
            "systemctl stop ip6ip6reset9.service",
            "sudo rm /etc/systemd/system/ip6ip6reset9.service",
            "systemctl disable ip6ip6reset10.service",
            "systemctl stop ip6ip6reset10.service",
            "sudo rm /etc/systemd/system/ip6ip6reset10.service",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# single reset local
def gre6_reset_rmvmnusingle():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Reset timer for local\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving stuff...\033[0m")

        commands = [
            "sudo rm /etc/reset_gre61.sh",
            "sudo rm /etc/ipv4.sh",
            "systemctl disable ipv4",
            "systemctl stop ipv4",
            "sudo rm /etc/systemd/system/ipv4.service"
            "sudo rm /usr/local/bin/gre61_daemon.sh",
            "systemctl disable gre6reset1.service",
            "systemctl stop gre6reset1.service",
            "sudo rm /etc/systemd/system/gre6reset1.service",
            "sudo rm /etc/resetbasedonping1.sh",
            "systemctl disable azumireset1.service",
            "systemctl stop azumireset1.service",
            "sudo rm /etc/systemd/system/azumireset1.service",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def private_reset_rmvmnusingle():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Reset timer for local\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving stuff...\033[0m")

        commands = [
            "sudo rm /etc/reset_private1.sh",
            "sudo rm /etc/ipv4.sh",
            "systemctl disable ipv4",
            "systemctl stop ipv4",
            "sudo rm /etc/systemd/system/ipv4.service"
            "sudo rm /usr/local/bin/private1_daemon.sh",
            "systemctl disable privatereset1.service",
            "systemctl stop privatereset1.service",
            "sudo rm /etc/systemd/system/privatereset1.service",
            "sudo rm /etc/resetbasedonping1.sh",
            "systemctl disable azumireset1.service",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def ipip6_reset_rmvmnussingle():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Reset timer for local\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving stuff...\033[0m")

        commands = [
            "sudo rm /etc/reset_ipip1.sh",
            "sudo rm /usr/local/bin/ipip1_daemon.sh",
            "sudo rm /etc/ipv4.sh",
            "systemctl disable ipv4",
            "systemctl stop ipv4",
            "sudo rm /etc/systemd/system/ipv4.service" "systemctl disable ip6ip6reset1",
            "systemctl stop ip6ip6reset1",
            "sudo rm /etc/systemd/system/ip6ip6reset1.service",
            "sudo rm /etc/resetbasedonping1.sh",
            "systemctl disable azumireset1",
            "systemctl stop azumireset1",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def reset_local_ip6ip6menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m IP6IP6 Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1]  IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [10] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_ip6ip6kharejmulti()
            break
        elif server_type == "2":
            reset_local_ip6ip6iranmulti()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m IP6IP6 + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_ip6ip6kharejsecmulti()
            break
        elif server_type == "2":
            reset_local_ip6ip6iransecmulti()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6kharejmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_ip6ip61()
            break
        elif server_type == "2":
            enable_reset_ip6ip62()
            break
        elif server_type == "3":
            enable_reset_ip6ip63()
            break
        elif server_type == "4":
            enable_reset_ip6ip64()
            break
        elif server_type == "5":
            enable_reset_ip6ip65()
            break
        elif server_type == "6":
            enable_reset_ip6ip66()
            break
        elif server_type == "7":
            enable_reset_ip6ip67()
            break
        elif server_type == "8":
            enable_reset_ip6ip68()
            break
        elif server_type == "9":
            enable_reset_ip6ip69()
            break
        elif server_type == "10":
            enable_reset_ip6ip610()
            break
        elif server_type == "11":
            kharej_resetlocal_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menu()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6kharejsecmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_ip6ip61()
            break
        elif server_type == "2":
            enable_reset_ip6ip62()
            break
        elif server_type == "3":
            enable_reset_ip6ip63()
            break
        elif server_type == "4":
            enable_reset_ip6ip64()
            break
        elif server_type == "5":
            enable_reset_ip6ip65()
            break
        elif server_type == "6":
            kharej_resetlocal_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menu()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocal_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_ip6ip6{}ir".format(i)
        globals()[menu_name]()


def reset_local_ip6ip6iranmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[10]IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[92mIRAN[6]\033[0m")
    print("7. \033[92mIRAN[7]\033[0m")
    print("8. \033[93mIRAN[8]\033[0m")
    print("9. \033[92mIRAN[9]\033[0m")
    print("10.\033[92mIRAN[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_ip6ip61ir()
            break
        elif server_type == "2":
            enable_reset_ip6ip62ir()
            break
        elif server_type == "3":
            enable_reset_ip6ip63ir()
            break
        elif server_type == "4":
            enable_reset_ip6ip64ir()
            break
        elif server_type == "5":
            enable_reset_ip6ip65ir()
            break
        elif server_type == "6":
            enable_reset_ip6ip66ir()
            break
        elif server_type == "7":
            enable_reset_ip6ip67ir()
            break
        elif server_type == "8":
            enable_reset_ip6ip68ir()
            break
        elif server_type == "9":
            enable_reset_ip6ip69ir()
            break
        elif server_type == "10":
            enable_reset_ip6ip610ir()
            break
        elif server_type == "11":
            iran_resetlocal_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menu()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6iransecmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_ip6ip61ir()
            break
        elif server_type == "2":
            enable_reset_ip6ip62ir()
            break
        elif server_type == "3":
            enable_reset_ip6ip63ir()
            break
        elif server_type == "4":
            enable_reset_ip6ip64ir()
            break
        elif server_type == "5":
            enable_reset_ip6ip65ir()
            break
        elif server_type == "6":
            iran_resetlocal_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menu()
            break
        else:
            print("Invalid choice.")


def iran_resetlocal_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_ip6ip6{}".format(i)
        globals()[menu_name]()


# gre6


def reset_local_gre6menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6 Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6kharejmulti()
            break
        elif server_type == "2":
            reset_local_gre6iranmulti()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6 + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6kharejsecmulti()
            break
        elif server_type == "2":
            reset_local_gre6iranmulti()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6kharejmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_gre61()
            break
        elif server_type == "2":
            enable_reset_gre62()
            break
        elif server_type == "3":
            enable_reset_gre63()
            break
        elif server_type == "4":
            enable_reset_gre64()
            break
        elif server_type == "5":
            enable_reset_gre65()
            break
        elif server_type == "6":
            enable_reset_gre66()
            break
        elif server_type == "7":
            enable_reset_gre67()
            break
        elif server_type == "8":
            enable_reset_gre68()
            break
        elif server_type == "9":
            enable_reset_gre69()
            break
        elif server_type == "10":
            enable_reset_gre610()
            break
        elif server_type == "11":
            kharej_resetlocalgre_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6menu()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6kharejsecmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_gre61()
            break
        elif server_type == "2":
            enable_reset_gre62()
            break
        elif server_type == "3":
            enable_reset_gre63()
            break
        elif server_type == "4":
            enable_reset_gre64()
            break
        elif server_type == "5":
            enable_reset_gre65()
            break
        elif server_type == "6":
            kharej_resetlocalgre_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6menu()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocalgre_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_gre6{}ir".format(i)
        globals()[menu_name]()


def reset_local_gre6iranmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_gre61ir()
            break
        elif server_type == "2":
            enable_reset_gre62ir()
            break
        elif server_type == "3":
            enable_reset_gre63ir()
            break
        elif server_type == "4":
            enable_reset_gre64ir()
            break
        elif server_type == "5":
            enable_reset_gre65ir()
            break
        elif server_type == "6":
            iran_resetlocalgre6_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6menu()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalgre6_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_gre6{}".format(i)
        globals()[menu_name]()


# gretap


def reset_local_gre6tapmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6TAP Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6tapkharejmulti()
            break
        elif server_type == "2":
            reset_local_gre6tapiranmulti()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6tapsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6TAP + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6tapkharejsecmulti()
            break
        elif server_type == "2":
            reset_local_gre6tapiranmulti()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6tapkharejmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6TAP \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_gre6tap1()  # return
            break
        elif server_type == "2":
            enable_reset_gre6tap2()
            break
        elif server_type == "3":
            enable_reset_gre6tap3()
            break
        elif server_type == "4":
            enable_reset_gre6tap4()
            break
        elif server_type == "5":
            enable_reset_gre6tap5()
            break
        elif server_type == "6":
            enable_reset_gre6tap6()
            break
        elif server_type == "7":
            enable_reset_gre6tap7()
            break
        elif server_type == "8":
            enable_reset_gre6tap8()
            break
        elif server_type == "9":
            enable_reset_gre6tap9()
            break
        elif server_type == "10":
            enable_reset_gre6tap10()
            break
        elif server_type == "11":
            kharej_resetlocalgretap_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6tapmenu()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6tapkharejsecmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6TAP \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_gre6tap1()
            break
        elif server_type == "2":
            enable_reset_gre6tap2()
            break
        elif server_type == "3":
            enable_reset_gre6tap3()
            break
        elif server_type == "4":
            enable_reset_gre6tap4()
            break
        elif server_type == "5":
            enable_reset_gre6tap5()
            break
        elif server_type == "6":
            kharej_resetlocalgretap_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6tapmenu()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocalgretap_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_gre6tap{}ir".format(i)
        globals()[menu_name]()


def reset_local_gre6tapiranmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6TAP \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_gre6tap1ir()
            break
        elif server_type == "2":
            enable_reset_gre6tap2ir()
            break
        elif server_type == "3":
            enable_reset_gre6tap3ir()
            break
        elif server_type == "4":
            enable_reset_gre6tap4ir()
            break
        elif server_type == "5":
            enable_reset_gre6tap5ir()
            break
        elif server_type == "6":
            iran_resetlocalgre6tap_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6tapmenu()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalgre6tap_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_gre6tap{}".format(i)
        globals()[menu_name]()


# private
def reset_local_privatemenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m 6TO4 Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_privatekharejmulti()
            break
        elif server_type == "2":
            reset_local_privateiranmulti()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_privatesec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Private + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_privatekharejsecmulti()
            break
        elif server_type == "2":
            reset_local_privateiransec()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_privatekharejmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_private1()
            break
        elif server_type == "2":
            enable_reset_private2()
            break
        elif server_type == "3":
            enable_reset_private3()
            break
        elif server_type == "4":
            enable_reset_private4()
            break
        elif server_type == "5":
            enable_reset_private5()
            break
        elif server_type == "6":
            enable_reset_private6()
            break
        elif server_type == "7":
            enable_reset_private7()
            break
        elif server_type == "8":
            enable_reset_private8()
            break
        elif server_type == "9":
            enable_reset_private9()
            break
        elif server_type == "10":
            enable_reset_private10()
            break
        elif server_type == "11":
            kharej_resetlocalprivate_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenu()
            break
        else:
            print("Invalid choice.")


def reset_local_privatekharejsecmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_private1sec()
            break
        elif server_type == "2":
            enable_reset_private2sec()
            break
        elif server_type == "3":
            enable_reset_private3sec()
            break
        elif server_type == "4":
            enable_reset_private4sec()
            break
        elif server_type == "5":
            enable_reset_private5sec()
            break
        elif server_type == "6":
            kharej_resetlocalprivate_qsec()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenu()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocalprivate_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_private{}ir".format(i)
        globals()[menu_name]()


def kharej_resetlocalprivate_qsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_private{}irsec".format(i)
        globals()[menu_name]()


def reset_local_privateiranmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_private1ir()
            break
        elif server_type == "2":
            enable_reset_private2ir()
            break
        elif server_type == "3":
            enable_reset_private3ir()
            break
        elif server_type == "4":
            enable_reset_private4ir()
            break
        elif server_type == "5":
            enable_reset_private5ir()
            break
        elif server_type == "6":
            iran_resetlocalprivate_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenu()
            break
        else:
            print("Invalid choice.")


def reset_local_privateiransecmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_private1irsec()
            break
        elif server_type == "2":
            enable_reset_private2irsec()
            break
        elif server_type == "3":
            enable_reset_private3irsec()
            break
        elif server_type == "4":
            enable_reset_private4irsec()
            break
        elif server_type == "5":
            enable_reset_private5irsec()
            break
        elif server_type == "6":
            iran_resetlocalprivate_qsec()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenu()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalprivate_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_private{}".format(i)
        globals()[menu_name]()


def iran_resetlocalprivate_qsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_private{}sec".format(i)
        globals()[menu_name]()


def reset_local_privateiransec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_private1ir()
            break
        elif server_type == "2":
            enable_reset_private2ir()
            break
        elif server_type == "3":
            enable_reset_private3ir()
            break
        elif server_type == "4":
            enable_reset_private4ir()
            break
        elif server_type == "5":
            enable_reset_private5ir()
            break
        elif server_type == "6":
            iran_resetlocalprivate_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenu()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalprivate_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_private{}".format(i)
        globals()[menu_name]()


def enable_reset_ip6ip61():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip61(interval_seconds)
        reset_ping_ipip61kharej()
        resetping_service_ipip61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip62():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip62(interval_seconds)
        reset_ping_ipip62kharej()
        resetping_service_ipip62()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip63():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip63(interval_seconds)
        reset_ping_ipip63kharej()
        resetping_service_ipip63()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip64():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip64(interval_seconds)
        reset_ping_ipip64kharej()
        resetping_service_ipip64()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip65():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip65(interval_seconds)
        reset_ping_ipip65kharej()
        resetping_service_ipip65()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip66():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip66(interval_seconds)
        reset_ping_ipip66kharej()
        resetping_service_ipip66()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip67():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip67(interval_seconds)
        reset_ping_ipip67kharej()
        resetping_service_ipip67()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip68():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip68(interval_seconds)
        reset_ping_ipip68kharej()
        resetping_service_ipip68()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip69():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip69(interval_seconds)
        reset_ping_ipip69kharej()
        resetping_service_ipip69()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip610():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip610(interval_seconds)
        reset_ping_ipip610kharej()
        resetping_service_ipip610()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# ip6ip61
def reset_local_ip6ip61(interval):
    service_name = "ip6ip6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
ip link set dev azumip1 down
ip link delete azumip1 
/bin/bash /etc/private1.sh 
ping -c 1 2002:801b::2
/bin/bash /etc/ipip1.sh 
ping -c 1 2002:0db8:1234:a020::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ipip62
def reset_local_ip6ip62(interval):
    service_name = "ip6ip6reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip2_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip2_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip2_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
ip link set dev azumip2 down
ip link delete azumip2 
/bin/bash /etc/private2.sh 
ping -c 1 2002:811b::2
/bin/bash /etc/ipip2.sh 
ping -c 1 2002:0db8:1234:a120::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ipip63
def reset_local_ip6ip63(interval):
    service_name = "ip6ip6reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip3_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip3_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip3_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
ip link set dev azumip3 down
ip link delete azumip3 
/bin/bash /etc/private3.sh 
ping -c 1 2002:821b::2
/bin/bash /etc/ipip3.sh 
ping -c 1 2002:0db8:1234:a220::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip64
def reset_local_ip6ip64(interval):
    service_name = "ip6ip6reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip4_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip4_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip4_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
ip link set dev azumip4 down
ip link delete azumip4 
/bin/bash /etc/private4.sh 
ping -c 1 2002:831b::2
/bin/bash /etc/ipip4.sh 
ping -c 1 2002:0db8:1234:a320::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip65
def reset_local_ip6ip65(interval):
    service_name = "ip6ip6reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip5_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip5_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip5_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
ip link set dev azumip5 down
ip link delete azumip5 
/bin/bash /etc/private5.sh
ping -c 1 2002:841b::2 
/bin/bash /etc/ipip5.sh 
ping -c 1 2002:0db8:1234:a420::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip66
def reset_local_ip6ip66(interval):
    service_name = "ip6ip6reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip6.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip6_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip6_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip6_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
ip link set dev azumip6 down
ip link delete azumip6 
/bin/bash /etc/private6.sh 
ping -c 1 2002:851b::2
/bin/bash /etc/ipip6.sh 
ping -c 1 2002:0db8:1234:a520::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip6.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip6.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip67
def reset_local_ip6ip67(interval):
    service_name = "ip6ip6reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip7.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip7_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip7_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip7_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7 down
ip link delete azumi7
ip link set dev azumip7 down 
ip link delete azumip7 
/bin/bash /etc/private7.sh 
ping -c 1 2002:861b::2
/bin/bash /etc/ipip7.sh 
ping -c 1 2002:0db8:1234:a620::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip7.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip7.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip68
def reset_local_ip6ip68(interval):
    service_name = "ip6ip6reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip8.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip8_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip8_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip8_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8 
ip link set dev azumip8 down
ip link delete azumip8 
/bin/bash /etc/private8.sh 
ping -c 1 2002:871b::2
/bin/bash /etc/ipip8.sh 
ping -c 1 2002:0db8:1234:a720::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip8.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip8.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip69
def reset_local_ip6ip69(interval):
    service_name = "ip6ip6reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip9.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip9_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip9_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip9_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
ip link set dev azumip9 down
ip link delete azumip9 
/bin/bash /etc/private9.sh 
ping -c 1 2002:881b::2
/bin/bash /etc/ipip9.sh 
ping -c 1 2002:0db8:1234:a820::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip9.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip9.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip610
def reset_local_ip6ip610(interval):
    service_name = "ip6ip6reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip10.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip10_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip10_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip10_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi10 down
ip link delete azumi10 
ip link set dev azumip10 down
ip link delete azumip10 
/bin/bash /etc/private10.sh 
ping -c 1 2002:891b::2
/bin/bash /etc/ipip10.sh 
ping -c 1 2002:0db8:1234:a920::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip10.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip10.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def enable_reset_ip6ip61ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip61ir(interval_seconds)
        reset_ping_ipip61iran()
        resetping_service_ipip61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip62ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip62ir(interval_seconds)
        reset_ping_ipip62iran()
        resetping_service_ipip62()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip63ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip63ir(interval_seconds)
        reset_ping_ipip63iran()
        resetping_service_ipip63()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip64ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip64ir(interval_seconds)
        reset_ping_ipip64iran()
        resetping_service_ipip64()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip65ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip65ir(interval_seconds)
        reset_ping_ipip65iran()
        resetping_service_ipip65()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip66ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip66ir(interval_seconds)
        reset_ping_ipip66iran()
        resetping_service_ipip66()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip67ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip67ir(interval_seconds)
        reset_ping_ipip67iran()
        resetping_service_ipip67()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip68ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip68ir(interval_seconds)
        reset_ping_ipip68iran()
        resetping_service_ipip68()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip69ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip69ir(interval_seconds)
        reset_ping_ipip69iran()
        resetping_service_ipip69()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_ip6ip610ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_ip6ip610ir(interval_seconds)
        reset_ping_ipip610iran()
        resetping_service_ipip610()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# ip6ip61
def reset_local_ip6ip61ir(interval):
    service_name = "ip6ip6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
ip link set dev azumip1 down
ip link delete azumip1 
/bin/bash /etc/private1.sh 
ping -c 1 2002:801b::1
/bin/bash /etc/ipip1.sh 
ping -c 1 2002:0db8:1234:a020::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ipip62
def reset_local_ip6ip62ir(interval):
    service_name = "ip6ip6reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip2_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip2_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip2_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
ip link set dev azumip2 down
ip link delete azumip2 
/bin/bash /etc/private2.sh 
ping -c 1 2002:811b::1
/bin/bash /etc/ipip2.sh 
ping -c 1 2002:0db8:1234:a120::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ipip63
def reset_local_ip6ip63ir(interval):
    service_name = "ip6ip6reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip3_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip3_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip3_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
ip link set dev azumip3 down
ip link delete azumip3 
/bin/bash /etc/private3.sh 
ping -c 1 2002:821b::1
/bin/bash /etc/ipip3.sh 
ping -c 1 2002:0db8:1234:a220::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip64
def reset_local_ip6ip64ir(interval):
    service_name = "ip6ip6reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip4_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip4_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip4_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
ip link set dev azumip4 down
ip link delete azumip4 
/bin/bash /etc/private4.sh 
ping -c 1 2002:831b::1
/bin/bash /etc/ipip4.sh 
ping -c 1 2002:0db8:1234:a320::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip65
def reset_local_ip6ip65ir(interval):
    service_name = "ip6ip6reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip5_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip5_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip5_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
ip link set dev azumip5 down
ip link delete azumip5 
/bin/bash /etc/private5.sh 
ping -c 1 2002:841b::1
/bin/bash /etc/ipip5.sh 
ping -c 1 2002:0db8:1234:a420::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip66
def reset_local_ip6ip66ir(interval):
    service_name = "ip6ip6reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip6.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip6_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip6_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip6_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
ip link set dev azumip6 down
ip link delete azumip6 
/bin/bash /etc/private6.sh 
ping -c 1 2002:851b::1
/bin/bash /etc/ipip6.sh 
ping -c 1 2002:0db8:1234:a520::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip6.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip6.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip67
def reset_local_ip6ip67ir(interval):
    service_name = "ip6ip6reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip7.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip7_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip7_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip7_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7
ip link delete azumi7 
ip link set dev azumip7
ip link delete azumip7 
/bin/bash /etc/private7.sh 
ping -c 1 2002:861b::1
/bin/bash /etc/ipip7.sh 
ping -c 1 2002:0db8:1234:a620::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip7.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip7.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip68
def reset_local_ip6ip68ir(interval):
    service_name = "ip6ip6reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip8.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip8_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip8_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip8_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8 
ip link set dev azumip8 down
ip link delete azumip8 
/bin/bash /etc/private8.sh 
ping -c 1 2002:871b::1
/bin/bash /etc/ipip8.sh 
ping -c 1 2002:0db8:1234:a720::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip8.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip8.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip69
def reset_local_ip6ip69ir(interval):
    service_name = "ip6ip6reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip9.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip9_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip9_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip9_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
ip link set dev azumip9 down
ip link delete azumip9 
/bin/bash /etc/private9.sh 
ping -c 1 2002:881b::1
/bin/bash /etc/ipip9.sh 
ping -c 1 2002:0db8:1234:a820::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip9.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip9.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ip6ip610
def reset_local_ip6ip610ir(interval):
    service_name = "ip6ip6reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipip10.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipip10_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipip10_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipip10_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi10 down
ip link delete azumi10 
ip link set dev azumip10 down
ip link delete azumip10 
/bin/bash /etc/private10.sh 
ping -c 1 2002:891b::1
/bin/bash /etc/ipip10.sh 
ping -c 1 2002:0db8:1234:a920::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_ipip10.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipip10.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# reset
def reset_ping_ipip61kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 4 2002:0db8:1234:a020::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip1.sh
    fi
    sleep 
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_ipip61iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a020::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_ipip61():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 2
def reset_ping_ipip62kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a120::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip2.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_ipip62iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a120::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip2.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def resetping_service_ipip62():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping2.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset2.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset2"])
    subprocess.run(["systemctl", "restart", "azumireset2"])


# 3
def reset_ping_ipip63kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a220::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip3.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_ipip63iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a220::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip3.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def resetping_service_ipip63():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping3.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset3.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset3"])
    subprocess.run(["systemctl", "restart", "azumireset3"])


# 4
def reset_ping_ipip64kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a320::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip4.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_ipip64iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a320::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip4.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def resetping_service_ipip64():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset4"])
    subprocess.run(["systemctl", "restart", "azumireset4"])


# 5
def reset_ping_ipip65kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a420::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip5.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_ipip65iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a420::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip5.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def resetping_service_ipip65():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping5.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset5.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset5"])
    subprocess.run(["systemctl", "restart", "azumireset5"])


# 6
def reset_ping_ipip66kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a520::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip6.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_ipip66iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a520::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip6.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def resetping_service_ipip66():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping6.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset6.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset6"])
    subprocess.run(["systemctl", "restart", "azumireset6"])


# 7
def reset_ping_ipip67kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a620::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip7.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_ipip67iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a620::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip7.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def resetping_service_ipip67():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping7.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset7.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset7"])
    subprocess.run(["systemctl", "restart", "azumireset7"])


# 8
def reset_ping_ipip68kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a720::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip8.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_ipip68iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a720::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip8.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def resetping_service_ipip68():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping8.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset8.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset8"])
    subprocess.run(["systemctl", "restart", "azumireset8"])


# 9
def reset_ping_ipip69kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a820::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip9.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_ipip69iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a820::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip9.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def resetping_service_ipip69():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping9.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset9.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset9"])
    subprocess.run(["systemctl", "restart", "azumireset9"])


# 10
def reset_ping_ipip610kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a920::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip10.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_ipip610iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a920::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_ipip10.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def resetping_service_ipip610():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping10.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset10.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset10"])
    subprocess.run(["systemctl", "restart", "azumireset10"])


def enable_reset_gre61():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre61(interval_seconds)
        reset_ping_gre61kharej()
        resetping_service_gre61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre62():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre62(interval_seconds)
        reset_ping_gre62kharej()
        resetping_service_gre62()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre63():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre63(interval_seconds)
        reset_ping_gre63kharej()
        resetping_service_gre63()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre64():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre64(interval_seconds)
        reset_ping_gre64kharej()
        resetping_service_gre64()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre65():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre65(interval_seconds)
        reset_ping_gre65kharej()
        resetping_service_gre65()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre66():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre66(interval_seconds)
        reset_ping_gre66kharej()
        resetping_service_gre66()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre67():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre67(interval_seconds)
        reset_ping_gre67kharej()
        resetping_service_gre67()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre68():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre68(interval_seconds)
        reset_ping_gre68kharej()
        resetping_service_gre68()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre69():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre69(interval_seconds)
        reset_ping_gre69kharej()
        resetping_service_gre69()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre610():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre610(interval_seconds)
        reset_ping_gre610kharej()
        resetping_service_gre610()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# gre61
def reset_local_gre61(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
ip link set dev azumig61 down
ip link delete azumig61 
/bin/bash /etc/private1.sh 
ping -c 1 2002:801b::2
/bin/bash /etc/gre61.sh 
ping -c 1 2002:801a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre62
def reset_local_gre62(interval):
    service_name = "gre6reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre62.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre62_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre62_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre62_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
ip link set dev azumig62 down
ip link delete azumig62 
/bin/bash /etc/private2.sh 
ping -c 1 2002:811b::2
/bin/bash /etc/gre62.sh 
ping -c 1 2002:811a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre62.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre62.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre63
def reset_local_gre63(interval):
    service_name = "gre6reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre63.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre63_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre63_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre63_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
ip link set dev azumig63 down
ip link delete azumig63 
/bin/bash /etc/private3.sh 
ping -c 1 2002:821b::2
/bin/bash /etc/gre63.sh 
ping -c 1 2002:821a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre63.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre63.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre64
def reset_local_gre64(interval):
    service_name = "gre6reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre64.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre64_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre64_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre64_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
ip link set dev azumig64 down
ip link delete azumig64 
/bin/bash /etc/private4.sh 
ping -c 1 2002:831b::2
/bin/bash /etc/gre64.sh 
ping -c 1 2002:831a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre64.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre64.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre64
def reset_local_gre65(interval):
    service_name = "gre6reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre65.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre65_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre65_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre65_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
ip link set dev azumig65 down
ip link delete azumig65 
/bin/bash /etc/private5.sh 
ping -c 1 2002:841b::2
/bin/bash /etc/gre65.sh 
ping -c 1 2002:841a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre65.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre65.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre66
def reset_local_gre66(interval):
    service_name = "gre6reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre66.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre66_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre66_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre66_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
ip link set dev azumig66 down
ip link delete azumig66 
/bin/bash /etc/private6.sh 
ping -c 1 2002:851b::2
/bin/bash /etc/gre66.sh 
ping -c 1 2002:851a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre66.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre66.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre67
def reset_local_gre67(interval):
    service_name = "gre6reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre67.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre67_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre67_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre67_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7 down
ip link delete azumi7
ip link set dev azumig67 down
ip link delete azumig67 
/bin/bash /etc/private7.sh
ping -c 1 2002:861b::2 
/bin/bash /etc/gre67.sh 
ping -c 1 2002:861a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre67.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre67.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre68
def reset_local_gre68(interval):
    service_name = "gre6reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre68.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre68_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre68_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre68_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8
ip link set dev azumig68 down
ip link delete azumig68 
/bin/bash /etc/private8.sh 
ping -c 1 2002:871b::2
/bin/bash /etc/gre68.sh 
ping -c 1 2002:871a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre68.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre68.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre69
def reset_local_gre69(interval):
    service_name = "gre6reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre69.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre69_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre69_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre69_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
ip link set dev azumig69 down
ip link delete azumig69 
/bin/bash /etc/private9.sh 
ping -c 1 2002:881b::2
/bin/bash /etc/gre69.sh 
ping -c 1 2002:881a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre69.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre69.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre610
def reset_local_gre610(interval):
    service_name = "gre6reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre610.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre610_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre610_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre610_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi10 down
ip link delete azumi10 
ip link set dev azumig610 down
ip link delete azumig610 
/bin/bash /etc/private10.sh
ping -c 1 2002:891b::2 
/bin/bash /etc/gre610.sh 
ping -c 1 2002:891a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre610.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre610.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def enable_reset_gre61ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre61ir(interval_seconds)
        reset_ping_gre61iran()
        resetping_service_gre61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre62ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre62ir(interval_seconds)
        reset_ping_gre62iran()
        resetping_service_gre62()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre63ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre63ir(interval_seconds)
        reset_ping_gre63iran()
        resetping_service_gre63()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre64ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre64ir(interval_seconds)
        reset_ping_gre64iran()
        resetping_service_gre64()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre65ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre65ir(interval_seconds)
        reset_ping_gre65iran()
        resetping_service_gre65()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre66ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre66ir(interval_seconds)
        reset_ping_gre66iran()
        resetping_service_gre66()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre67ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre67ir(interval_seconds)
        reset_ping_gre67iran()
        resetping_service_gre67()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre68ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre68ir(interval_seconds)
        reset_ping_gre68iran()
        resetping_service_gre68()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre69ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre69ir(interval_seconds)
        reset_ping_gre69iran()
        resetping_service_gre69()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre610ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre610ir(interval_seconds)
        reset_ping_gre610iran()
        resetping_service_gre610()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# gre61
def reset_local_gre61ir(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
ip link set dev azumig61 down
ip link delete azumig61 
/bin/bash /etc/private1.sh 
ping -c 1 2002:801b::1
/bin/bash /etc/gre61.sh 
ping -c 1 2002:801a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre662
def reset_local_gre62ir(interval):
    service_name = "gre6reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre62.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre62_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre62_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre62_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
ip link set dev azumig62 down
ip link delete azumig62 
/bin/bash /etc/private2.sh 
ping -c 1 2002:811b::1
/bin/bash /etc/gre62.sh 
ping -c 1 2002:811a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre62.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre62.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre663
def reset_local_gre63ir(interval):
    service_name = "gre6reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre63.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre63_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre63_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre63_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
ip link set dev azumig63 down
ip link delete azumig63 
/bin/bash /etc/private3.sh 
ping -c 1 2002:821b::1
/bin/bash /etc/gre63.sh 
ping -c 1 2002:821a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre63.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre63.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre64
def reset_local_gre64ir(interval):
    service_name = "gre6reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre64.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre64_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre64_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre64_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
ip link set dev azumig64 down
ip link delete azumig64 
/bin/bash /etc/private4.sh 
ping -c 1 2002:831b::1
/bin/bash /etc/gre64.sh 
ping -c 1 2002:831a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre64.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre64.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre65
def reset_local_gre65ir(interval):
    service_name = "gre6reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre65.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre65_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre65_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre65_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
ip link set dev azumig65 down
ip link delete azumig65 
/bin/bash /etc/private5.sh 
ping -c 1 2002:841b::1
/bin/bash /etc/gre65.sh 
ping -c 1 2002:841a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre65.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre65.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre66
def reset_local_gre66ir(interval):
    service_name = "gre6reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre66.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre66_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre66_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre66_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
ip link set dev azumig66 down
ip link delete azumig66 
/bin/bash /etc/private6.sh 
ping -c 1 2002:851b::1
/bin/bash /etc/gre66.sh 
ping -c 1 2002:851a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre66.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre66.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre67
def reset_local_gre67ir(interval):
    service_name = "gre6reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre67.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre67_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre67_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre67_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7 down
ip link delete azumi7 
ip link set dev azumig67 down
ip link delete azumig67 
/bin/bash /etc/private7.sh 
ping -c 1 2002:861b::1
/bin/bash /etc/gre67.sh 
ping -c 1 2002:861a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre67.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre67.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre68
def reset_local_gre68ir(interval):
    service_name = "gre6reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre68.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre68_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre68_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre68_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8 
ip link set dev azumig68 down
ip link delete azumig68 
/bin/bash /etc/private8.sh 
ping -c 1 2002:871b::1
/bin/bash /etc/gre68.sh 
ping -c 1 2002:871a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre68.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre68.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre69
def reset_local_gre69ir(interval):
    service_name = "gre6reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre69.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre69_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre69_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre69_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
ip link set dev azumig69 down
ip link delete azumig69 
/bin/bash /etc/private9.sh 
ping -c 1 2002:881b::1
/bin/bash /etc/gre69.sh 
ping -c 1 2002:881a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre69.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre69.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre610
def reset_local_gre610ir(interval):
    service_name = "gre6reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre610.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre610_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre610_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre610_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set down azumi10 down
ip link delete azumi10 
ip link set dev azumig610 down
ip link delete azumig610 
/bin/bash /etc/private10.sh 
ping -c 1 2002:891b::1
/bin/bash /etc/gre610.sh 
ping -c 1 2002:891a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre610.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre610.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# reset
def reset_ping_gre61kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre61.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_gre61iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre61.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_gre61():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 2
def reset_ping_gre62kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre62.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_gre62iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre62.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def resetping_service_gre62():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping2.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset2.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset2"])
    subprocess.run(["systemctl", "restart", "azumireset2"])


# 2
def reset_ping_gre63kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre63.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_gre63iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre63.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def resetping_service_gre63():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping3.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset3.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset3"])
    subprocess.run(["systemctl", "restart", "azumireset3"])


# 4
def reset_ping_gre64kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre64.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_gre64iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre64.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def resetping_service_gre64():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset4"])
    subprocess.run(["systemctl", "restart", "azumireset4"])


# 5
def reset_ping_gre65kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre65.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_gre65iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre65.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def resetping_service_gre65():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping5.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset5.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset5"])
    subprocess.run(["systemctl", "restart", "azumireset5"])


# 6
def reset_ping_gre66kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre66.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_gre66iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre66.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def resetping_service_gre66():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping6.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset6.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset6"])
    subprocess.run(["systemctl", "restart", "azumireset6"])


# 7
def reset_ping_gre67kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre67.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_gre67iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre67.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def resetping_service_gre67():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping7.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset7.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset7"])
    subprocess.run(["systemctl", "restart", "azumireset7"])


# 8
def reset_ping_gre68kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre68.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_gre68iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre68.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def resetping_service_gre68():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping8.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset8.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset8"])
    subprocess.run(["systemctl", "restart", "azumireset8"])


# 9
def reset_ping_gre69kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre69.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_gre69iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre69.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def resetping_service_gre69():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping9.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset9.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset9"])
    subprocess.run(["systemctl", "restart", "azumireset9"])


# 10
def reset_ping_gre610kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre610.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_gre610iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre610.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def resetping_service_gre610():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping10.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset10.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset10"])
    subprocess.run(["systemctl", "restart", "azumireset10"])


def enable_ipv45forward():
    print("\033[93m────────────────────────────────────────\033[0m")
    ip4_enable = input(
        "\033[93mDo you want \033[92mIPV4/6 \033[93mto be checked & enabled every minute? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ip4_enable in ["yes", "y"]:
        ipv4forwardipv6()
        ipv4_service()


def ipv4forwardipv6():
    script_content = """#!/bin/bash

set_sysctl_value() {
    local key="$1"
    local value="$2"

    sysctl -w $key=$value
    
    if grep -q "^$key" /etc/sysctl.conf; then
        sed -i "s/^$key.*/$key = $value/" /etc/sysctl.conf
    else
        echo "$key = $value" >> /etc/sysctl.conf
    fi
}

while true; do
    set_sysctl_value net.ipv4.ip_forward 1
    set_sysctl_value net.ipv6.conf.all.disable_ipv6 0
    set_sysctl_value net.ipv6.conf.default.disable_ipv6 0
    set_sysctl_value net.ipv6.conf.all.forwarding 1
    
    sleep 60
done
"""
    script_path = "/etc/ipv4.sh"
    with open(script_path, "w") as f:
        f.write(script_content)

    os.chmod(script_path, 0o755)


def ipv4_service():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/ipv4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/ipv4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ipv4"])
    subprocess.run(["systemctl", "restart", "ipv4"])


def enable_reset_gre6tap1():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap1(interval_seconds)
        reset_ping_gre61kharej()
        resetping_service_gre61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap2():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap2(interval_seconds)
        reset_ping_gre62kharej()
        resetping_service_gre62()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap3():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap3(interval_seconds)
        reset_ping_gre63kharej()
        resetping_service_gre63()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap4():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap4(interval_seconds)
        reset_ping_gre64kharej()
        resetping_service_gre64()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap5():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap5(interval_seconds)
        reset_ping_gre65kharej()
        resetping_service_gre65()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap6():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap6(interval_seconds)
        reset_ping_gre66kharej()
        resetping_service_gre66()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap7():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap7(interval_seconds)
        reset_ping_gre67kharej()
        resetping_service_gre67()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap8():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap8(interval_seconds)
        reset_ping_gre68kharej()
        resetping_service_gre68()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap9():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap9(interval_seconds)
        reset_ping_gre69kharej()
        resetping_service_gre69()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap10():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap10(interval_seconds)
        reset_ping_gre610kharej()
        resetping_service_gre610()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# gre61
def reset_local_gre6tap1(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
ip link set dev azumig61 down
ip link delete azumig61 
/bin/bash /etc/private1.sh
ping -c 1 fd1d:fc98:b73e:b081::2 
/bin/bash /etc/gre61.sh 
ping -c 1 2002:801a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre62
def reset_local_gre6tap2(interval):
    service_name = "gre6reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre62.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre62_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre62_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre62_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
ip link set dev azumig62 down
ip link delete azumig62 
/bin/bash /etc/private2.sh 
ping -c 1 fd1d:fc98:b73e:b181::2
/bin/bash /etc/gre62.sh 
ping -c 1 2002:811a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre62.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre62.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre63
def reset_local_gre6tap3(interval):
    service_name = "gre6reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre63.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre63_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre63_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre63_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
ip link set dev azumig63 down
ip link delete azumig63 
/bin/bash /etc/private3.sh 
ping -c 1 fd1d:fc98:b73e:b281::2
/bin/bash /etc/gre63.sh 
ping -c 1 2002:821a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre63.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre63.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre64
def reset_local_gre6tap4(interval):
    service_name = "gre6reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre64.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre64_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre64_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre64_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
ip link set dev azumig64 down
ip link delete azumig64 
/bin/bash /etc/private4.sh
ping -c 1 fd1d:fc98:b73e:b381::2 
/bin/bash /etc/gre64.sh 
ping -c 1 2002:831a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre64.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre64.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre64
def reset_local_gre6tap5(interval):
    service_name = "gre6reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre65.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre65_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre65_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre65_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5
ip link set dev azumig65 down
ip link delete azumig65 
/bin/bash /etc/private5.sh 
ping -c 1 fd1d:fc98:b73e:b481::2
/bin/bash /etc/gre65.sh 
ping -c 1 2002:841a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre65.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre65.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre66
def reset_local_gre6tap6(interval):
    service_name = "gre6reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre66.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre66_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre66_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre66_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
ip link set dev azumig66 down
ip link delete azumig66 
/bin/bash /etc/private6.sh
ping -c 1 fd1d:fc98:b73e:b581::2 
/bin/bash /etc/gre66.sh 
ping -c 1 2002:851a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre66.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre66.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre67
def reset_local_gre6tap7(interval):
    service_name = "gre6reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre67.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre67_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre67_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre67_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7 down
ip link delete azumi7 
ip link set dev azumig67 down
ip link delete azumig67 
/bin/bash /etc/private7.sh 
ping -c 1 fd1d:fc98:b73e:b681::2
/bin/bash /etc/gre67.sh 
ping -c 1 2002:861a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre67.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre67.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre68
def reset_local_gre6tap8(interval):
    service_name = "gre6reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre68.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre68_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre68_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre68_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8 
ip link set dev azumig68 down
ip link delete azumig68 
/bin/bash /etc/private8.sh 
ping -c 1 fd1d:fc98:b73e:b781::2
/bin/bash /etc/gre68.sh 
ping -c 1 2002:871a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre68.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre68.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre69
def reset_local_gre6tap9(interval):
    service_name = "gre6reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre69.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre69_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre69_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre69_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
ip link set dev azumig69 down
ip link delete azumig69 
/bin/bash /etc/private9.sh 
ping -c 1 fd1d:fc98:b73e:b881::2
/bin/bash /etc/gre69.sh 
ping -c 1 2002:881a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre69.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre69.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre6tap10
def reset_local_gre6tap10(interval):
    service_name = "gre6reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre610.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre610_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre610_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre610_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi10 down
ip link delete azumi10 
ip link set dev azumig610 down
ip link delete azumig610 
/bin/bash /etc/private10.sh 
ping -c 1 fd1d:fc98:b73e:b981::2
/bin/bash /etc/gre610.sh 
ping -c 1 2002:891a::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre610.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre610.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def enable_reset_gre6tap1ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap1ir(interval_seconds)
        reset_ping_gre61iran()
        resetping_service_gre61()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap2ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap2ir(interval_seconds)
        reset_ping_gre62iran()
        resetping_service_gre62()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap3ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap3ir(interval_seconds)
        reset_ping_gre63iran()
        resetping_service_gre63()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap4ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap4ir(interval_seconds)
        reset_ping_gre64iran()
        resetping_service_gre64()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap5ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap5ir(interval_seconds)
        reset_ping_gre65iran()
        resetping_service_gre65()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap6ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap6ir(interval_seconds)
        reset_ping_gre66iran()
        resetping_service_gre66()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap7ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap7ir(interval_seconds)
        reset_ping_gre67iran()
        resetping_service_gre67()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap8ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap8ir(interval_seconds)
        reset_ping_gre68iran()
        resetping_service_gre68()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap9ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap9ir(interval_seconds)
        reset_ping_gre69iran()
        resetping_service_gre69()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_gre6tap10ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_gre6tap10ir(interval_seconds)
        reset_ping_gre610iran()
        resetping_service_gre610()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# gre61
def reset_local_gre6tap1ir(interval):
    service_name = "gre6reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre61.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre61_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre61_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre61_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
ip link set dev azumig61 down
ip link delete azumig61 
/bin/bash /etc/private1.sh 
ping -c 1 fd1d:fc98:b73e:b081::1
/bin/bash /etc/gre61.sh 
ping -c 1 2002:801a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre61.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre61.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre662
def reset_local_gre6tap2ir(interval):
    service_name = "gre6reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre62.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre62_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre62_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre62_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
ip link set dev azumig62 down
ip link delete azumig62 
/bin/bash /etc/private2.sh 
ping -c 1 fd1d:fc98:b73e:b181::1
/bin/bash /etc/gre62.sh 
ping -c 1 2002:811a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre62.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre62.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre663
def reset_local_gre6tap3ir(interval):
    service_name = "gre6reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre63.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre63_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre63_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre63_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
ip link set dev azumig63 down
ip link delete azumig63 
/bin/bash /etc/private3.sh 
ping -c 1 fd1d:fc98:b73e:b281::1
/bin/bash /etc/gre63.sh 
ping -c 1 2002:821a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre63.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre63.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre64
def reset_local_gre6tap4ir(interval):
    service_name = "gre6reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre64.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre64_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre64_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre64_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4
ip link set dev azumig64 down 
ip link delete azumig64 
/bin/bash /etc/private4.sh 
ping -c 1 fd1d:fc98:b73e:b381::1
/bin/bash /etc/gre64.sh 
ping -c 1 2002:831a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre64.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre64.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre65
def reset_local_gre6tap5ir(interval):
    service_name = "gre6reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre65.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre65_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre65_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre65_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
ip link set dev azumig65 down
ip link delete azumig65 
/bin/bash /etc/private5.sh
ping -c 1 fd1d:fc98:b73e:b481::1 
/bin/bash /etc/gre65.sh 
ping -c 1 2002:841a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre65.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre65.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre66
def reset_local_gre6tap6ir(interval):
    service_name = "gre6reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre66.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre66_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre66_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre66_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
ip link set dev azumig66 down
ip link delete azumig66 
/bin/bash /etc/private6.sh 
ping -c 1 fd1d:fc98:b73e:b581::1
/bin/bash /etc/gre66.sh 
ping -c 1 2002:851a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre66.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre66.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre67
def reset_local_gre6tap7ir(interval):
    service_name = "gre6reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre67.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre67_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre67_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre67_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7 down
ip link delete azumi7 
ip link set dev azumig67 down
ip link delete azumig67 
/bin/bash /etc/private7.sh 
/bin/bash /etc/gre67.sh 
ping -c 1 fd1d:fc98:b73e:b681::1
ping -c 1 2002:861a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre67.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre67.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre68
def reset_local_gre6tap8ir(interval):
    service_name = "gre6reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre68.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre68_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre68_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre68_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8 
ip link set dev azumig68 down
ip link delete azumig68 
/bin/bash /etc/private8.sh 
ping -c 1 fd1d:fc98:b73e:b781::1
/bin/bash /etc/gre68.sh 
ping -c 1 2002:871a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre68.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre68.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre69
def reset_local_gre6tap9ir(interval):
    service_name = "gre6reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre69.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre69_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre69_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre69_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
ip link set dev azumig69 down
ip link delete azumig69 
/bin/bash /etc/private9.sh 
ping -c 1 fd1d:fc98:b73e:b881::1
/bin/bash /etc/gre69.sh 
ping -c 1 2002:881a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre69.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre69.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# gre610
def reset_local_gre6tap10ir(interval):
    service_name = "gre6reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_gre610.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/gre610_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/gre610_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/gre610_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi10 down
ip link delete azumi10 
ip link set dev azumig610 down
ip link delete azumig610 
/bin/bash /etc/private10.sh
ping -c 1 fd1d:fc98:b73e:b981::1 
/bin/bash /etc/gre610.sh 
ping -c 1 2002:891a::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_gre610.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_gre610.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# reset
def reset_ping_gre61kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre61.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_gre61iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre61.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_gre61():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 2
def reset_ping_gre62kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre62.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_gre62iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre62.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def resetping_service_gre62():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping2.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset2.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset2"])
    subprocess.run(["systemctl", "restart", "azumireset2"])


# 2
def reset_ping_gre63kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre63.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_gre63iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre63.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def resetping_service_gre63():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping3.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset3.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset3"])
    subprocess.run(["systemctl", "restart", "azumireset3"])


# 4
def reset_ping_gre64kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre64.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_gre64iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre64.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def resetping_service_gre64():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset4"])
    subprocess.run(["systemctl", "restart", "azumireset4"])


# 5
def reset_ping_gre65kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre65.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_gre65iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre65.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def resetping_service_gre65():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping5.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset5.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset5"])
    subprocess.run(["systemctl", "restart", "azumireset5"])


# 6
def reset_ping_gre66kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre66.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_gre66iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre66.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def resetping_service_gre66():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping6.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset6.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset6"])
    subprocess.run(["systemctl", "restart", "azumireset6"])


# 7
def reset_ping_gre67kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre67.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_gre67iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre67.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def resetping_service_gre67():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping7.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset7.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset7"])
    subprocess.run(["systemctl", "restart", "azumireset7"])


# 8
def reset_ping_gre68kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre68.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_gre68iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre68.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def resetping_service_gre68():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping8.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset8.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset8"])
    subprocess.run(["systemctl", "restart", "azumireset8"])


# 9
def reset_ping_gre69kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre69.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_gre69iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre69.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def resetping_service_gre69():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping9.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset9.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset9"])
    subprocess.run(["systemctl", "restart", "azumireset9"])


# 10
def reset_ping_gre610kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre610.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_gre610iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_gre610.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def resetping_service_gre610():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping10.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset10.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset10"])
    subprocess.run(["systemctl", "restart", "azumireset10"])


def enable_reset_private1():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private1(interval_seconds)
        reset_ping_private1kharej()
        resetping_service_private1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private2():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private2(interval_seconds)
        reset_ping_private2kharej()
        resetping_service_private2()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private3():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private3(interval_seconds)
        reset_ping_private3kharej()
        resetping_service_private3()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private4():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private4(interval_seconds)
        reset_ping_private4kharej()
        resetping_service_private4()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private5():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private5(interval_seconds)
        reset_ping_private5kharej()
        resetping_service_private5()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private6():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private6(interval_seconds)
        reset_ping_private6kharej()
        resetping_service_private6()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private7():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private7(interval_seconds)
        reset_ping_private7kharej()
        resetping_service_private7()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private8():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private8(interval_seconds)
        reset_ping_private8kharej()
        resetping_service_private8()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private9():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private9(interval_seconds)
        reset_ping_private9kharej()
        resetping_service_private9()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private10():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private10(interval_seconds)
        reset_ping_private10kharej()
        resetping_service_private10()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# 6to4-1
def reset_local_private1(interval):
    service_name = "privatereset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
/bin/bash /etc/private1.sh 
ping -c 1 2002:801b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-2
def reset_local_private2(interval):
    service_name = "privatereset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private2_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private2_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private2_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
/bin/bash /etc/private2.sh 
ping -c 1 2002:811b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-3
def reset_local_private3(interval):
    service_name = "privatereset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private3_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private3_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private3_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
/bin/bash /etc/private3.sh 
ping -c 1 2002:821b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-4
def reset_local_private4(interval):
    service_name = "privatereset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private4_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private4_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private4_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
/bin/bash /etc/private4.sh 
ping -c 1 2002:831b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-5
def reset_local_private5(interval):
    service_name = "privatereset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private5_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private5_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private5_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
/bin/bash /etc/private5.sh 
ping -c 1 2002:841b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# ipsec


# 6to4-6
def reset_local_private6(interval):
    service_name = "privatereset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private6.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private6_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private6_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private6_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
/bin/bash /etc/private6.sh 
ping -c 1 2002:851b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private6.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private6.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-7
def reset_local_private7(interval):
    service_name = "privatereset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private7.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private7_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private7_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private7_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7 down
ip link delete azumi7 
/bin/bash /etc/private7.sh 
ping -c 1 2002:861b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private7.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private7.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-8
def reset_local_private8(interval):
    service_name = "privatereset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private8.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private8_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private8_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private8_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8 
/bin/bash /etc/private8.sh 
ping -c 1 2002:871b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private8.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private8.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-9
def reset_local_private9(interval):
    service_name = "privatereset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private9.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private9_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private9_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private9_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
/bin/bash /etc/private9.sh 
ping -c 1 2002:881b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private9.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private9.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-10
def reset_local_private10(interval):
    service_name = "privatereset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private10.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private10_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private10_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private10_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi10 down
ip link delete azumi10 
/bin/bash /etc/private10.sh 
ping -c 1 2002:891b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private10.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private10.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def enable_reset_private1ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private1ir(interval_seconds)
        reset_ping_private1iran()
        resetping_service_private1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private2ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private2ir(interval_seconds)
        reset_ping_private2iran()
        resetping_service_private2()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private3ir():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private3ir(interval_seconds)
        reset_ping_private3iran()
        resetping_service_private3()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private4ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private4ir(interval_seconds)
        reset_ping_private4iran()
        resetping_service_private4()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private5ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private5ir(interval_seconds)
        reset_ping_private5iran()
        resetping_service_private5()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private6ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private6ir(interval_seconds)
        reset_ping_private6iran()
        resetping_service_private6()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private7ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private7ir(interval_seconds)
        reset_ping_private7iran()
        resetping_service_private7()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private8ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private8ir(interval_seconds)
        reset_ping_private8iran()
        resetping_service_private8()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private9ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private9ir(interval_seconds)
        reset_ping_private9iran()
        resetping_service_private9()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private10ir():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private10ir(interval_seconds)
        reset_ping_private10iran()
        resetping_service_private10()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


# private1
def reset_local_private1ir(interval):
    service_name = "privatereset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
/bin/bash /etc/private1.sh 
ping -c 1 2002:801b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private62
def reset_local_private2ir(interval):
    service_name = "privatereset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private2_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private2_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private2_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
/bin/bash /etc/private2.sh 
ping -c 1 2002:811b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private63
def reset_local_private3ir(interval):
    service_name = "privatereset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private3_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private3_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private3_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
/bin/bash /etc/private3.sh 
ping -c 1 2002:821b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private4
def reset_local_private4ir(interval):
    service_name = "privatereset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private4_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private4_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private4_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
/bin/bash /etc/private4.sh 
ping -c 1 2002:831b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private5
def reset_local_private5ir(interval):
    service_name = "privatereset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private5_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private5_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private5_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
/bin/bash /etc/private5.sh 
ping -c 1 2002:841b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private6
def reset_local_private6ir(interval):
    service_name = "privatereset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private6.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private6_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private6_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private6_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi6 down
ip link delete azumi6 
/bin/bash /etc/private6.sh 
ping -c 1 2002:851b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private6.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private6.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private7
def reset_local_private7ir(interval):
    service_name = "privatereset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private7.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private7_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private7_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private7_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi7 down
ip link delete azumi7 
/bin/bash /etc/private7.sh 
ping -c 1 2002:861b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private7.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private7.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private8
def reset_local_private8ir(interval):
    service_name = "privatereset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private8.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private8_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private8_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private8_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi8 down
ip link delete azumi8 
/bin/bash /etc/private8.sh 
ping -c 1 2002:871b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private8.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private8.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private9
def reset_local_private9ir(interval):
    service_name = "privatereset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private9.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private9_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private9_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private9_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi9 down
ip link delete azumi9 
/bin/bash /etc/private9.sh 
ping -c 1 2002:881b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private9.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private9.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private10
def reset_local_private10ir(interval):
    service_name = "privatereset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private10.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private10_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private10_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private10_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi10 down
ip link delete azumi10 
/bin/bash /etc/private10.sh 
ping -c 1 2002:891b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private10.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private10.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# reset
def reset_ping_private1kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_private1iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_private1():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 2
def reset_ping_private2kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private2.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_private2iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private2.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def resetping_service_private2():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping2.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset2.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset2"])
    subprocess.run(["systemctl", "restart", "azumireset2"])


# 2
def reset_ping_private3kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private3.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_private3iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private3.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def resetping_service_private3():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping3.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset3.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset3"])
    subprocess.run(["systemctl", "restart", "azumireset3"])


# 4
def reset_ping_private4kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private4.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_private4iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private4.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def resetping_service_private4():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset4"])
    subprocess.run(["systemctl", "restart", "azumireset4"])


# 5
def reset_ping_private5kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private5.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_private5iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private5.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def resetping_service_private5():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping5.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset5.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset5"])
    subprocess.run(["systemctl", "restart", "azumireset5"])


# 6
def reset_ping_private6kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private6.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_private6iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private6.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def resetping_service_private6():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping6.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset6.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset6"])
    subprocess.run(["systemctl", "restart", "azumireset6"])


# 7
def reset_ping_private7kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private7.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_private7iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private7.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def resetping_service_private7():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping7.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset7.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset7"])
    subprocess.run(["systemctl", "restart", "azumireset7"])


# 8
def reset_ping_private8kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private8.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_private8iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private8.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def resetping_service_private8():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping8.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset8.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset8"])
    subprocess.run(["systemctl", "restart", "azumireset8"])


# 9
def reset_ping_private9kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private9.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_private9iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private9.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def resetping_service_private9():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping9.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset9.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset9"])
    subprocess.run(["systemctl", "restart", "azumireset9"])


# 10
def reset_ping_private10kharej():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private10.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_private10iran():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private10.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def resetping_service_private10():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping10.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset10.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset10"])
    subprocess.run(["systemctl", "restart", "azumireset10"])


# ipsec private reset
def enable_reset_private1sec():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private1sec(interval_seconds)
        reset_ping_private1kharejsec()
        resetping_service_private1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private2sec():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private2sec(interval_seconds)
        reset_ping_private2kharejsec()
        resetping_service_private2()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private3sec():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private3sec(interval_seconds)
        reset_ping_private3kharejsec()
        resetping_service_private3()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private4sec():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private4sec(interval_seconds)
        reset_ping_private4kharejsec()
        resetping_service_private4()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private5sec():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private5sec(interval_seconds)
        reset_ping_private5kharejsec()
        resetping_service_private5()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def reset_local_private1sec(interval):
    service_name = "privatereset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
/bin/bash /etc/private1.sh 
ping -c 1 2002:831b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-2
def reset_local_private2sec(interval):
    service_name = "privatereset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private2_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private2_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private2_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
/bin/bash /etc/private2.sh 
ping -c 1 2002:841b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-3
def reset_local_private3sec(interval):
    service_name = "privatereset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private3_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private3_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private3_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
/bin/bash /etc/private3.sh 
ping -c 1 2002:851b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-4
def reset_local_private4sec(interval):
    service_name = "privatereset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private4_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private4_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private4_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
/bin/bash /etc/private4.sh 
ping -c 1 2002:861b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# 6to4-5
def reset_local_private5sec(interval):
    service_name = "privatereset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private5_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private5_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private5_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
/bin/bash /etc/private5.sh 
ping -c 1 2002:871b::2
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def enable_reset_private1irsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private1irsec(interval_seconds)
        reset_ping_private1iransec()
        resetping_service_private1()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private2irsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private2irsec(interval_seconds)
        reset_ping_private2iransec()
        resetping_service_private2()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private3irsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private3irsec(interval_seconds)
        reset_ping_private3iransec()
        resetping_service_private3()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private4irsec():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private4irsec(interval_seconds)
        reset_ping_private4iransec()
        resetping_service_private4()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def enable_reset_private5irsec():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mlocal \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local_private5irsec(interval_seconds)
        reset_ping_private5iransec()
        resetping_service_private5()
    global enable_ipv45forward_called
    if not enable_ipv45forward_called:
        enable_ipv45forward()
        enable_ipv45forward_called = True
    print("\033[93m────────────────────────────────────────\033[0m")


def reset_local_private1irsec(interval):
    service_name = "privatereset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private1_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private1_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private1_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi1 down
ip link delete azumi1 
/bin/bash /etc/private1.sh 
ping -c 1 2002:831b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private62
def reset_local_private2irsec(interval):
    service_name = "privatereset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private2_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private2_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private2_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi2 down
ip link delete azumi2 
/bin/bash /etc/private2.sh 
ping -c 1 2002:841b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private63
def reset_local_private3irsec(interval):
    service_name = "privatereset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private3_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private3_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private3_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi3 down
ip link delete azumi3 
/bin/bash /etc/private3.sh 
ping -c 1 2002:851b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private4
def reset_local_private4irsec(interval):
    service_name = "privatereset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private4_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private4_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private4_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi4 down
ip link delete azumi4 
/bin/bash /etc/private4.sh 
ping -c 1 2002:861b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


# private5
def reset_local_private5irsec(interval):
    service_name = "privatereset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_private5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/private5_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/private5_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/private5_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link set dev azumi5 down
ip link delete azumi5 
/bin/bash /etc/private5.sh 
ping -c 1 2002:871b::1
systemctl restart strong-azumi1 
"""

    with open("/etc/reset_private5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_private5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

    # reset


def reset_ping_private1kharejsec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_private1iransec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private1.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


# 2
def reset_ping_private2kharejsec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private2.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_private2iransec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private2.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


# 3
def reset_ping_private3kharejsec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private3.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_private3iransec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private3.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


# 4
def reset_ping_private4kharejsec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private4.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_private4iransec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private4.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


# 5
def reset_ping_private5kharejsec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private5.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_private5iransec():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_private5.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


# test reset
# single
# ipip


def reset_local_mainmenunew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset Local Menu [Test]\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mSingle\033[0m")
    print("2. \033[93mMulti\033[0m")
    print("0.\033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_menu2new()
            break
        elif server_type == "2":
            reset_local_menunew()
            break
        elif server_type == "0":
            os.system("clear")
            main_menu()
            break
        else:
            print("Invalid choice.")


def reset_local_menu2new():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset Local Single Menu [Test]\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6\033[0m")
    print("2. \033[94mIP6IP6 + IPSEC\033[0m")
    print("3. \033[93mGRE6\033[0m")
    print("4. \033[92mGRE6 + IPSEC\033[0m")
    print("5. \033[92mGRE6TAP\033[0m")
    print("6. \033[92mGRE6TAP + IPSEC\033[0m")
    print("7. \033[92mPrivate\033[0m")
    print("8. \033[93mPrivate + IPSEC\033[0m")
    print("9. \033[91mUninstall\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            display_menu_ipipnew()
            break
        elif server_type == "2":
            display_menu_ipipnew()
            break
        elif server_type == "3":
            display_menu_gre6new()
            break
        elif server_type == "4":
            display_menu_gre6new()
            break
        elif server_type == "5":
            display_menu_gre6new()
            break
        elif server_type == "6":
            display_menu_gre6new()
            break
        elif server_type == "7":
            display_menu_privatenew()
            break
        elif server_type == "8":
            display_menu_privatenew()
            break
        elif server_type == "9":
            reset_local_uninstallsingle()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_mainmenunew()
            break
        else:
            print("Invalid choice.")


def display_menu_ipipnew():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("Select an option (1 or 2): ")
    if choice == "1":
        reset_ping_ipip6kharej1new()
        resetping_service_ipip1new()
        enable_ipv45forward()
    elif choice == "2":
        reset_ping_ipip6iran1new()
        resetping_service_ipip1new()
        enable_ipv45forward()
    else:
        print("Please select 1 or 2")


def display_menu_privatenew():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("Select an option (1 or 2): ")
    if choice == "1":
        reset_ping_privatekharej1new()
        resetping_service_private1new()
        enable_ipv45forward()
    elif choice == "2":
        reset_ping_privateiran1new()
        resetping_service_private1new()
        enable_ipv45forward()
    else:
        print("Please select 1 or 2")


def display_menu_gre6new():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("Select an option (1 or 2): ")
    if choice == "1":
        reset_ping_gre6kharej1new()
        resetping_service_gre61new()
        enable_ipv45forward()
    elif choice == "2":
        reset_ping_gre6iran1new()
        resetping_service_gre61new()
        enable_ipv45forward()
    else:
        print("Please select 1 or 2")


def reset_local_menunew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Reset Local Multi Menu[Test]\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6\033[0m")
    print("2. \033[94mIP6IP6 + IPSEC\033[0m")
    print("3. \033[93mGRE6\033[0m")
    print("4. \033[92mGRE6 + IPSEC\033[0m")
    print("5. \033[92mGRE6TAP\033[0m")
    print("6. \033[92mGRE6TAP + IPSEC\033[0m")
    print("7. \033[92m6TO4\033[0m")
    print("8. \033[93m6TO4 + IPSEC\033[0m")
    print("9. \033[91mUninstall\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_ip6ip6menunew()
            break
        elif server_type == "2":
            reset_local_ip6ip6secnew()
            break
        elif server_type == "3":
            reset_local_gre6menunew()
            break
        elif server_type == "4":
            reset_local_gre6secnew()
            break
        elif server_type == "5":
            reset_local_gre6tapmenunew()
            break
        elif server_type == "6":
            reset_local_gre6tapsecnew()
            break
        elif server_type == "7":
            reset_local_privatemenunew()
            break
        elif server_type == "8":
            reset_local_privatesecnew()
            break
        elif server_type == "9":
            reset_local_uninstall()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_mainmenunew()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6menunew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m IP6IP6 Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1]  IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [10] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_ip6ip6kharejmultinew()
            break
        elif server_type == "2":
            reset_local_ip6ip6iranmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6secnew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m IP6IP6 + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_ip6ip6kharejsecmultinew()
            break
        elif server_type == "2":
            reset_local_ip6ip6iransecmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6kharejmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_ipip61kharejnew()
            resetping_service_ipip61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_ipip62kharejnew()
            resetping_service_ipip62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_ipip63kharejnew()
            resetping_service_ipip63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_ipip64kharejnew()
            resetping_service_ipip64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_ipip65kharejnew()
            resetping_service_ipip65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            reset_ping_ipip66kharejnew()
            resetping_service_ipip66new()
            enable_ipv45forward()
            break
        elif server_type == "7":
            reset_ping_ipip67kharejnew()
            resetping_service_ipip67new()
            enable_ipv45forward()
            break
        elif server_type == "8":
            reset_ping_ipip68kharejnew()
            resetping_service_ipip68new()
            enable_ipv45forward()
            break
        elif server_type == "9":
            reset_ping_ipip69kharejnew()
            resetping_service_ipip69new()
            enable_ipv45forward()
            break
        elif server_type == "10":
            reset_ping_ipip610kharejnew()
            resetping_service_ipip610new()
            enable_ipv45forward()
            break
        elif server_type == "11":
            kharej_resetlocal_qnew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6kharejsecmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_ipip61kharejnew()
            resetping_service_ipip61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_ipip62kharejnew()
            resetping_service_ipip62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_ipip63kharejnew()
            resetping_service_ipip63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_ipip64kharejnew()
            resetping_service_ipip64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_ipip65kharejnew()
            resetping_service_ipip65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            kharej_resetlocal_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menunew()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocal_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")
        reset_ping_private_name = f"reset_ping_ipip6{i}irannew"
        resetping_service_private_name = f"resetping_service_ipip6{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


def reset_local_ip6ip6iranmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[10]IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[92mIRAN[6]\033[0m")
    print("7. \033[92mIRAN[7]\033[0m")
    print("8. \033[93mIRAN[8]\033[0m")
    print("9. \033[92mIRAN[9]\033[0m")
    print("10.\033[92mIRAN[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_ipip61irannew()
            resetping_service_ipip61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_ipip62irannew()
            resetping_service_ipip62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_ipip63irannew()
            resetping_service_ipip63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_ipip64irannew()
            resetping_service_ipip64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_ipip65irannew()
            resetping_service_ipip65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            reset_ping_ipip66irannew()
            resetping_service_ipip66new()
            enable_ipv45forward()
            break
        elif server_type == "7":
            reset_ping_ipip67irannew()
            resetping_service_ipip67new()
            enable_ipv45forward()
            break
        elif server_type == "8":
            reset_ping_ipip68irannew()
            resetping_service_ipip68new()
            enable_ipv45forward()
            break
        elif server_type == "9":
            reset_ping_ipip69irannew()
            resetping_service_ipip69new()
            enable_ipv45forward()
            break
        elif server_type == "10":
            reset_ping_ipip610irannew()
            resetping_service_ipip610new()
            enable_ipv45forward()
            break
        elif server_type == "11":
            iran_resetlocal_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_ip6ip6iransecmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_ipip61irannew()
            resetping_service_ipip61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_ipip62irannew()
            resetping_service_ipip62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_ipip63irannew()
            resetping_service_ipip63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_ipip64irannew()
            resetping_service_ipip64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_ipip65irannew()
            resetping_service_ipip65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            iran_resetlocal_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_ip6ip6menunew()
            break
        else:
            print("Invalid choice.")


def iran_resetlocal_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")
        reset_ping_private_name = f"reset_ping_ipip6{i}kharejnew"
        resetping_service_private_name = f"resetping_service_ipip6{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


# gre6menu
def reset_local_gre6menunew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6 Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6kharejmultinew()
            break
        elif server_type == "2":
            reset_local_gre6iranmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6secnew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6 + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6kharejsecmultinew()
            break
        elif server_type == "2":
            reset_local_gre6iranmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6kharejmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_gre61kharejnew()
            resetping_service_gre61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_gre62kharejnew()
            resetping_service_gre62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_gre63kharejnew()
            resetping_service_gre63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_gre64kharejnew()
            resetping_service_gre64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_gre65kharejnew()
            resetping_service_gre65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            reset_ping_gre66kharejnew()
            resetping_service_gre66new()
            enable_ipv45forward()
            break
        elif server_type == "7":
            reset_ping_gre67kharejnew()
            resetping_service_gre67new()
            enable_ipv45forward()
            break
        elif server_type == "8":
            reset_ping_gre68kharejnew()
            resetping_service_gre68new()
            enable_ipv45forward()
            break
        elif server_type == "9":
            reset_ping_gre69kharejnew()
            resetping_service_gre69new()
            enable_ipv45forward()
            break
        elif server_type == "10":
            reset_ping_gre610kharejnew()
            resetping_service_gre610new()
            enable_ipv45forward()
            break
        elif server_type == "11":
            kharej_resetlocalgre_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6kharejsecmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_gre61kharejnew()
            resetping_service_gre61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_gre62kharejnew()
            resetping_service_gre62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_gre63kharejnew()
            resetping_service_gre63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_gre64kharejnew()
            resetping_service_gre64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_gre65kharejnew()
            resetping_service_gre65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            kharej_resetlocalgre_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6menunew()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocalgre_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")
        reset_ping_private_name = f"reset_ping_gre6{i}irannew"
        resetping_service_private_name = f"resetping_service_gre6{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


def reset_local_gre6iranmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_gre61irannew()
            resetping_service_gre61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_gre62irannew()
            resetping_service_gre62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_gre63irannew()
            resetping_service_gre63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_gre64irannew()
            resetping_service_gre64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_gre65irannew()
            resetping_service_gre65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            iran_resetlocalgre6_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6menunew()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalgre6_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")
        reset_ping_private_name = f"reset_ping_gre6{i}kharejnew"
        resetping_service_private_name = f"resetping_service_gre6{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


# gretap


def reset_local_gre6tapmenunew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6TAP Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6tapkharejmultinew()
            break
        elif server_type == "2":
            reset_local_gre6tapiranmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6tapsecnew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m GRE6TAP + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_gre6tapkharejsecmultinew()
            break
        elif server_type == "2":
            reset_local_gre6tapiranmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6tapkharejmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6TAP \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_gre6tap1kharejnew()
            resetping_service_gre61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_gre6tap2kharejnew()
            resetping_service_gre62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_gre6tap3kharejnew()
            resetping_service_gre63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_gre6tap4kharejnew()
            resetping_service_gre64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_gre6tap5kharejnew()
            resetping_service_gre65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            reset_ping_gre6tap6kharejnew()
            resetping_service_gre66new()
            enable_ipv45forward()
            break
        elif server_type == "7":
            reset_ping_gre6tap7kharejnew()
            resetping_service_gre67new()
            enable_ipv45forward()
            break
        elif server_type == "8":
            reset_ping_gre6tap8kharejnew()
            resetping_service_gre68new()
            enable_ipv45forward()
            break
        elif server_type == "9":
            reset_ping_gre6tap9kharejnew()
            resetping_service_gre69new()
            enable_ipv45forward()
            break
        elif server_type == "10":
            reset_ping_gre6tap10kharejnew()
            resetping_service_gre610new()
            enable_ipv45forward()
            break
        elif server_type == "11":
            kharej_resetlocalgretap_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6tapmenunew()
            break
        else:
            print("Invalid choice.")


def reset_local_gre6tapkharejsecmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6TAP \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_gre6tap1kharejnew()
            resetping_service_gre61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_gre6tap2kharejnew()
            resetping_service_gre62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_gre6tap3kharejnew()
            resetping_service_gre63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_gre6tap4kharejnew()
            resetping_service_gre64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_gre6tap5kharejnew()
            resetping_service_gre65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            kharej_resetlocalgretap_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6tapmenunew()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocalgretap_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")
        reset_ping_private_name = f"reset_ping_gre6tap{i}irannew"
        resetping_service_private_name = f"resetping_service_gre6{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


def reset_local_gre6tapiranmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6TAP \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_gre6tap1irannew()
            resetping_service_gre61new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_gre6tap2irannew()
            resetping_service_gre62new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_gre6tap3irannew()
            resetping_service_gre63new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_gre6tap4irannew()
            resetping_service_gre64new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_gre6tap5irannew()
            resetping_service_gre65new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            iran_resetlocalgre6tap_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_gre6tapmenunew()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalgre6tap_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        reset_ping_private_name = f"reset_ping_gre6tap{i}kharejnew"
        resetping_service_private_name = f"resetping_service_gre6{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


# private
def reset_local_privatemenunew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m 6TO4 Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[10] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1]  KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_privatekharejmultinew()
            break
        elif server_type == "2":
            reset_local_privateiranmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_privatesecnew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Private + IPSEC Reset Local Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[5] KHAREJ [1] IRAN\033[0m")
    print("2. \033[92m[1] KHAREJ [5] IRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_local_privatekharejsecmultinew()
            break
        elif server_type == "2":
            reset_local_privateiransecmultinew()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_menunew()
            break
        else:
            print("Invalid choice.")


def reset_local_privatekharejmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_private1kharejnew()
            resetping_service_private1new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_private2kharejnew()
            resetping_service_private2new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_private3kharejnew()
            resetping_service_private3new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_private4kharejnew()
            resetping_service_private4new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_private5kharejnew()
            resetping_service_private5new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            reset_ping_private6kharejnew()
            resetping_service_private6new()
            enable_ipv45forward()
            break
        elif server_type == "7":
            reset_ping_private7kharejnew()
            resetping_service_private7new()
            enable_ipv45forward()
            break
        elif server_type == "8":
            reset_ping_private8kharejnew()
            resetping_service_private8new()
            enable_ipv45forward()
            break
        elif server_type == "9":
            reset_ping_private9kharejnew()
            resetping_service_private9new()
            enable_ipv45forward()
            break
        elif server_type == "10":
            reset_ping_private10kharejnew()
            resetping_service_private10new()
            enable_ipv45forward()
            break
        elif server_type == "11":
            kharej_resetlocalprivate_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenunew()
            break
        else:
            print("Invalid choice.")


def reset_local_privatekharejsecmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_private1kharejsecnew()
            resetping_service_private1new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_private2kharejsecnew()
            resetping_service_private2new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_private3kharejsecnew()
            resetping_service_private3new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_private4kharejsecnew()
            resetping_service_private4new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_private5kharejsecnew()
            resetping_service_private5new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            kharej_resetlocalprivate_qsecnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenunew()
            break
        else:
            print("Invalid choice.")


def kharej_resetlocalprivate_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        reset_ping_private_name = f"reset_ping_private{i}irannew"
        resetping_service_private_name = f"resetping_service_private{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


def kharej_resetlocalprivate_qsecnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        reset_ping_private_name = f"reset_ping_private{i}iransecnew"
        resetping_service_private_name = f"resetping_service_private{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


def reset_local_privateiranmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_private1irannew()
            resetping_service_private1new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_private2irannew()
            resetping_service_private2new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_private3irannew()
            resetping_service_private3new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_private4irannew()
            resetping_service_private4new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_private5irannew()
            resetping_service_private5new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            iran_resetlocalprivate_qnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenunew()
            break
        else:
            print("Invalid choice.")


def reset_local_privateiransecmultinew():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            reset_ping_private1iransecnew()
            resetping_service_private1new()
            enable_ipv45forward()
            break
        elif server_type == "2":
            reset_ping_private2iransecnew()
            resetping_service_private2new()
            enable_ipv45forward()
            break
        elif server_type == "3":
            reset_ping_private3iransecnew()
            resetping_service_private3new()
            enable_ipv45forward()
            break
        elif server_type == "4":
            reset_ping_private4iransecnew()
            resetping_service_private4new()
            enable_ipv45forward()
            break
        elif server_type == "5":
            reset_ping_private5iransecnew()
            resetping_service_private5new()
            enable_ipv45forward()
            break
        elif server_type == "6":
            iran_resetlocalprivate_qsecnew()
            enable_ipv45forward()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenunew()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalprivate_qnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        reset_ping_private_name = f"reset_ping_private{i}kharejnew"
        resetping_service_private_name = f"resetping_service_private{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


def iran_resetlocalprivate_qsecnew():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification("\033[93mDoing some stuff\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")
        reset_ping_private_name = f"reset_ping_private{i}kharejsecnew"
        resetping_service_private_name = f"resetping_service_private{i}new"

        if reset_ping_private_name in globals():
            globals()[reset_ping_private_name]()
        else:
            print(f"\033[91mFunction reset ping doesn't exist.\033[0m")

        if resetping_service_private_name in globals():
            globals()[resetping_service_private_name]()
        else:
            print(f"\033[91mFunction reset ping does not exist.\033[0m")


def reset_local_privateiransec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6TO4 \033[92m[5IRAN\033[96m [1]Kharej\033[93m Reset Menu\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            enable_reset_private1ir()
            break
        elif server_type == "2":
            enable_reset_private2ir()
            break
        elif server_type == "3":
            enable_reset_private3ir()
            break
        elif server_type == "4":
            enable_reset_private4ir()
            break
        elif server_type == "5":
            enable_reset_private5ir()
            break
        elif server_type == "6":
            iran_resetlocalprivate_q()
            break
        elif server_type == "0":
            os.system("clear")
            reset_local_privatemenu()
            break
        else:
            print("Invalid choice.")


def iran_resetlocalprivate_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        print("\033[93m───────────────────────────────────────\033[0m")
        display_notification(f"\033[93mServer {i}\033[0m")
        print("\033[93m───────────────────────────────────────\033[0m")

        menu_name = "enable_reset_private{}".format(i)
        globals()[menu_name]()


def install_bash():
    if not os.path.isfile("/bin/bash"):
        try:
            subprocess.run(["sudo", "apt-get", "update"], check=True)
            subprocess.run(["sudo", "apt-get", "install", "-y", "bash"], check=True)
            print("\033[92mbash has been installed successfully\033[0m")
        except subprocess.CalledProcessError as e:
            print(f"\033[91mError occurred during installation: {e}\033[0m")
            return False
    else:
        print("\033[93mbash is already installed\033[0m")
        return True


def reset_ping_ipip6kharej1new():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a220::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi down
        ip link delete azumi
        ip link set dev azumip down
        ip link delete azumip
        sleep 30
        /bin/bash /etc/private.sh
        ping -c 1 fd1d:fc98:b73e:b481::2 
        /bin/bash /etc/ipip.sh 
        ping -c 1 2002:0db8:1234:a220::2
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_ipip6iran1new():
    script_content = f"""#!/bin/bash
while true; do
    ping -c 2 2002:0db8:1234:a220::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi down
        ip link delete azumi
        ip link set dev azumip down
        ip link delete azumip
        sleep 30
        /bin/bash /etc/private.sh 
        ping -c 1 fd1d:fc98:b73e:b481::1
        /bin/bash /etc/ipip.sh 
        ping -c 1 2002:0db8:1234:a220::1
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_ipip1new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# private
def reset_ping_privatekharej1new():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi down
        ip link delete azumi
        sleep 30
        /bin/bash /etc/private.sh 
        ping -c 1 2002:831b::2
        systemctl restart strong-azumi1 

    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_privateiran1new():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi down
        ip link delete azumi
        sleep 30
        /bin/bash /etc/private.sh 
        ping -c 1 2002:831b::1
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_private1new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# gre6
def reset_ping_gre6kharej1new():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi down
        ip link delete azumi
        ip link set dev azumig6 down
        ip link delete azumig6
        sleep 30
        /bin/bash /etc/private.sh 
        ping -c 1 fd1d:fc98:b73e:b481::2
        /bin/bash /etc/gre6.sh 
        ping -c 1 2002:831a::2
        systemctl restart strong-azumi1 

    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_gre6iran1new():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi down
        ip link delete azumi
        ip link set dev azumig6 down
        ip link delete azumig6
        sleep 30
        /bin/bash /etc/private.sh 
        ping -c 1 fd1d:fc98:b73e:b481::1
        /bin/bash /etc/gre6.sh 
        ping -c 1 2002:831a::1
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_gre61new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# multi
# ipip6
def reset_ping_ipip61kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a020::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        ip link set dev azumip1 down
        ip link delete azumip1
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:801b::2 
        /bin/bash /etc/ipip1.sh 
        ping -c 1 2002:0db8:1234:a020::2
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_ipip61irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a020::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        ip link set dev azumip1 down
        ip link delete azumip1
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:801b::1
        /bin/bash /etc/ipip1.sh
        ping -c 1 2002:0db8:1234:a020::1
        systemctl restart strong-azumi1 
        
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_ipip61new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 2
def reset_ping_ipip62kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a120::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        ip link set dev azumip2 down
        ip link delete azumip2
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:811b::2
        /bin/bash /etc/ipip2.sh 
        ping -c 1 2002:0db8:1234:a120::2
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_ipip62irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a120::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        ip link set dev azumip2 down
        ip link delete azumip2
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:811b::1
        /bin/bash /etc/ipip2.sh 
        ping -c 1 2002:0db8:1234:a120::1
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def resetping_service_ipip62new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping2.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset2.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset2"])
    subprocess.run(["systemctl", "restart", "azumireset2"])


# 3
def reset_ping_ipip63kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a220::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        ip link set dev azumip3 down
        ip link delete azumip3
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 2002:821b::2
        /bin/bash /etc/ipip3.sh
        ping -c 1 2002:0db8:1234:a220::2
        systemctl restart strong-azumi1 
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_ipip63irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a220::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        ip link set dev azumip3 down
        ip link delete azumip3
        sleep 30
        /bin/bash /etc/private3.sh
        ping -c 1 2002:821b::1
        /bin/bash /etc/ipip3.sh 
        ping -c 1 2002:0db8:1234:a220::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def resetping_service_ipip63new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping3.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset3.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset3"])
    subprocess.run(["systemctl", "restart", "azumireset3"])


# 4
def reset_ping_ipip64kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a320::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        ip link set dev azumip4 down
        ip link delete azumip4
        sleep 30
        /bin/bash /etc/private4.sh
        ping -c 1 2002:831b::2
        /bin/bash /etc/ipip4.sh 
        ping -c 1 2002:0db8:1234:a320::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_ipip64irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a320::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        ip link set dev azumip4 down
        ip link delete azumip4
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 2002:831b::1
        /bin/bash /etc/ipip4.sh 
        ping -c 1 2002:0db8:1234:a320::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def resetping_service_ipip64new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset4"])
    subprocess.run(["systemctl", "restart", "azumireset4"])


# 5
def reset_ping_ipip65kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a420::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        ip link set dev azumip5 down
        ip link delete azumip5
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:841b::2
        /bin/bash /etc/ipip5.sh 
        ping -c 1 2002:0db8:1234:a420::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_ipip65irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a420::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        ip link set dev azumip5 down
        ip link delete azumip5
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:841b::1
        /bin/bash /etc/ipip5.sh
        ping -c 1 2002:0db8:1234:a420::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def resetping_service_ipip65new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping5.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset5.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset5"])
    subprocess.run(["systemctl", "restart", "azumireset5"])


# 6
def reset_ping_ipip66kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a520::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        ip link set dev azumip6 down
        ip link delete azumip6
        sleep 30
        /bin/bash /etc/private6.sh
        ping -c 1 2002:851b::2
        /bin/bash /etc/ipip6.sh 
        ping -c 1 2002:0db8:1234:a520::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_ipip66irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a520::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        ip link set azumip6 down
        ip link delete azumip6
        sleep 30
        /bin/bash /etc/private6.sh 
        ping -c 1 2002:851b::1
        /bin/bash /etc/ipip6.sh 
        ping -c 1 2002:0db8:1234:a520::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def resetping_service_ipip66new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping6.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset6.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset6"])
    subprocess.run(["systemctl", "restart", "azumireset6"])


# 7
def reset_ping_ipip67kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a620::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        ip link set dev azumip7 down
        ip link delete azumip7
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 2002:861b::2
        /bin/bash /etc/ipip7.sh 
        ping -c 1 2002:0db8:1234:a620::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_ipip67irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a620::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        ip link set dev azumip7 down
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 2002:861b::1
        /bin/bash /etc/ipip7.sh 
        ping -c 1 2002:0db8:1234:a620::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def resetping_service_ipip67new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping7.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset7.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset7"])
    subprocess.run(["systemctl", "restart", "azumireset7"])


# 8
def reset_ping_ipip68kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a720::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        ip link set dev azumip8 down
        ip link delete azumip8
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 2002:871b::2
        /bin/bash /etc/ipip8.sh 
        ping -c 1 2002:0db8:1234:a720::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_ipip68irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a720::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        ip link set dev azumip8 down
        ip link delete azumip8
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 2002:871b::1
        /bin/bash /etc/ipip8.sh 
        ping -c 1 2002:0db8:1234:a720::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def resetping_service_ipip68new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping8.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset8.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset8"])
    subprocess.run(["systemctl", "restart", "azumireset8"])


# 9
def reset_ping_ipip69kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a820::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        ip link set dev azumip9 down
        ip link delete azumip9
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 2002:881b::2
        /bin/bash /etc/ipip9.sh 
        ping -c 1 2002:0db8:1234:a820::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_ipip69irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a820::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        ip link set dev azumip9 down
        ip link delete azumip9
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 2002:881b::1
        /bin/bash /etc/ipip9.sh 
        ping -c 1 2002:0db8:1234:a820::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def resetping_service_ipip69new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping9.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset9.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset9"])
    subprocess.run(["systemctl", "restart", "azumireset9"])


# 10
def reset_ping_ipip610kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a920::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        ip link set dev azumip10 down
        ip link delete azumip10
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 2002:891b::2
        /bin/bash /etc/ipip10.sh 
        ping -c 1 2002:0db8:1234:a920::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_ipip610irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:0db8:1234:a920::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        ip link set dev azumip10 down
        ip link delete azumip10
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 2002:891b::1
        /bin/bash /etc/ipip10.sh 
        ping -c 1 2002:0db8:1234:a920::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def resetping_service_ipip610new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping10.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset10.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset10"])
    subprocess.run(["systemctl", "restart", "azumireset10"])


# gre6
def reset_ping_gre61kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        ip link set dev azumig61 down
        ip link delete azumig61
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:801b::2
        /bin/bash /etc/gre61.sh 
        ping -c 1 2002:801a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_gre61irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        ip link set dev azumig61 down
        ip link delete azumig61
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:801b::1
        /bin/bash /etc/gre61.sh 
        ping -c 1 2002:801a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_gre61new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 2
def reset_ping_gre62kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        ip link set dev azumig62 down
        ip link delete azumig62
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:811b::2
        /bin/bash /etc/gre62.sh 
        ping -c 1 2002:811a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_gre62irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        ip link set dev azumig62 down
        ip link delete azumig62
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:811b::1
        /bin/bash /etc/gre62.sh 
        ping -c 1 2002:811a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def resetping_service_gre62new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping2.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset2.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset2"])
    subprocess.run(["systemctl", "restart", "azumireset2"])


# 2
def reset_ping_gre63kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        ip link set dev azumig63 down
        ip link delete azumig63
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 2002:821b::2
        /bin/bash /etc/gre63.sh 
        ping -c 1 2002:821a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_gre63irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        ip link set dev azumig63 down
        ip link delete azumig63
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 2002:821b::1
        /bin/bash /etc/gre63.sh 
        ping -c 1 2002:821a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def resetping_service_gre63new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping3.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset3.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset3"])
    subprocess.run(["systemctl", "restart", "azumireset3"])


# 4
def reset_ping_gre64kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        ip link set dev azumig64 down
        ip link delete azumig64
        systemctl restart networking
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 2002:831b::2
        /bin/bash /etc/gre64.sh 
        ping -c 1 2002:831a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_gre64irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        ip link set dev azumig64 down
        ip link delete azumig64
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 2002:831b::1
        /bin/bash /etc/gre64.sh 
        ping -c 1 2002:831a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def resetping_service_gre64new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset4"])
    subprocess.run(["systemctl", "restart", "azumireset4"])


# 5
def reset_ping_gre65kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        ip link set dev azumig65 down
        ip link delete azumig65
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:841b::2
        /bin/bash /etc/gre65.sh 
        ping -c 1 2002:841a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_gre65irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        ip link set dev azumig65 down
        ip link delete azumig65
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:841b::1
        /bin/bash /etc/gre65.sh 
        ping -c 1 2002:841a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def resetping_service_gre65new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping5.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset5.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset5"])
    subprocess.run(["systemctl", "restart", "azumireset5"])


# 6
def reset_ping_gre66kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        ip link set dev azumig66 down
        ip link delete azumig66
        sleep 30
        /bin/bash /etc/private6.sh 
        ping -c 1 2002:851b::2
        /bin/bash /etc/gre66.sh 
        ping -c 1 2002:851a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_gre66irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        ip link set dev azumig66 down
        ip link delete azumig66
        sleep 30
        /bin/bash /etc/private6.sh 
        ping -c 1 2002:851b::1
        /bin/bash /etc/gre66.sh 
        ping -c 1 2002:851a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def resetping_service_gre66new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping6.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset6.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset6"])
    subprocess.run(["systemctl", "restart", "azumireset6"])


# 7
def reset_ping_gre67kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        ip link set dev azumig67 down
        ip link delete azumig67
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 2002:861b::2
        /bin/bash /etc/gre67.sh 
        ping -c 1 2002:861a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_gre67irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        ip link set dev azumig67 down
        ip link delete azumig67
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 2002:861b::1
        /bin/bash /etc/gre67.sh 
        ping -c 1 2002:861a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def resetping_service_gre67new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping7.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset7.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset7"])
    subprocess.run(["systemctl", "restart", "azumireset7"])


# 8
def reset_ping_gre68kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        ip link set dev azumig68 down
        ip link delete azumig68
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 2002:871b::2
        /bin/bash /etc/gre68.sh 
        ping -c 1 2002:871a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_gre68irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        ip link set dev azumig68 down
        ip link delete azumig68
        systemctl restart networking
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 2002:871b::1
        /bin/bash /etc/gre68.sh 
        ping -c 1 2002:871a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def resetping_service_gre68new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping8.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset8.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset8"])
    subprocess.run(["systemctl", "restart", "azumireset8"])


# 9
def reset_ping_gre69kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        ip link set dev azumig69 down
        ip link delete azumig69
        systemctl restart networking
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 2002:881b::2
        /bin/bash /etc/gre69.sh 
        ping -c 1 2002:881a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_gre69irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        ip link set dev azumig69 down
        ip link delete azumig69
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 2002:881b::1
        /bin/bash /etc/gre69.sh 
        ping -c 1 2002:881a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def resetping_service_gre69new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping9.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset9.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset9"])
    subprocess.run(["systemctl", "restart", "azumireset9"])


# 10
def reset_ping_gre610kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        ip link set dev azumig610 down
        ip link delete azumig610
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 2002:891b::2
        /bin/bash /etc/gre610.sh 
        ping -c 1 2002:891a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_gre610irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        ip link set dev azumig610 down
        ip link delete azumig610
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 2002:891b::1
        /bin/bash /etc/gre610.sh 
        ping -c 1 2002:891a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def resetping_service_gre610new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping10.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset10.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset10"])
    subprocess.run(["systemctl", "restart", "azumireset10"])


# gre6tap
def reset_ping_gre6tap1kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        ip link set dev azumig61 down
        ip link delete azumig61
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 fd1d:fc98:b73e:b081::2
        /bin/bash /etc/gre61.sh 
        ping -c 1 2002:801a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_gre6tap1irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        ip link set dev azumig61 down
        ip link delete azumig61
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 fd1d:fc98:b73e:b081::1
        /bin/bash /etc/gre61.sh 
        ping -c 1 2002:801a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


# 2
def reset_ping_gre6tap2kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        ip link set dev azumig62 down
        ip link delete azumig62
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 fd1d:fc98:b73e:b181::2
        /bin/bash /etc/gre62.sh 
        ping -c 1 2002:811a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_gre6tap2irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        ip link set dev azumig62 down
        ip link delete azumig62
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 fd1d:fc98:b73e:b181::1
        /bin/bash /etc/gre62.sh 
        ping -c 1 2002:811a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


# 2
def reset_ping_gre6tap3kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        ip lin set dev azumig63 down
        ip link delete azumig63
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 fd1d:fc98:b73e:b281::2
        /bin/bash /etc/gre63.sh 
        ping -c 1 2002:821a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_gre6tap3irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        ip link set dev azumig63 down
        ip link delete azumig63
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 fd1d:fc98:b73e:b281::1
        /bin/bash /etc/gre63.sh 
        ping -c 1 2002:821a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


# 4
def reset_ping_gre6tap4kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down 
        ip link delete azumi4
        ip link set dev azumig64 down
        ip link delete azumig64
        systemctl restart networking
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 fd1d:fc98:b73e:b381::2
        /bin/bash /etc/gre64.sh 
        ping -c 1 2002:831a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_gre6tap4irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        ip link set dev azumig64 down
        ip link delete azumig64
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 fd1d:fc98:b73e:b381::1
        /bin/bash /etc/gre64.sh 
        ping -c 1 2002:831a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


# 5
def reset_ping_gre6tap5kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        ip link set dev azumig65 down
        ip link delete azumig65
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 fd1d:fc98:b73e:b481::2
        /bin/bash /etc/gre65.sh 
        ping -c 1 2002:841a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_gre6tap5irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        ip link set dev azumig65 down
        ip link delete azumig65
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 fd1d:fc98:b73e:b481::1
        /bin/bash /etc/gre65.sh 
        ping -c 1 2002:841a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


# 6
def reset_ping_gre6tap6kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        ip link set dev azumig66 down
        ip link delete azumig66
        sleep 30
        /bin/bash /etc/private6.sh 
        ping -c 1 fd1d:fc98:b73e:b581::2
        /bin/bash /etc/gre66.sh 
        ping -c 1 2002:851a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_gre6tap6irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        ip link set dev azumig66 down
        ip link delete azumig66
        sleep 30
        /bin/bash /etc/private6.sh 
        ping -c 1 fd1d:fc98:b73e:b581::1
        /bin/bash /etc/gre66.sh 
        ping -c 1 2002:851a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


# 7
def reset_ping_gre6tap7kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        ip link set dev azumig67 down
        ip link delete azumig67
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 fd1d:fc98:b73e:b681::2
        /bin/bash /etc/gre67.sh 
        ping -c 1 2002:861a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_gre6tap7irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        ip link set dev azumig67 down
        ip link delete azumig67
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 fd1d:fc98:b73e:b681::1
        /bin/bash /etc/gre67.sh 
        ping -c 1 2002:861a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


# 8
def reset_ping_gre6tap8kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        ip link set dev azumig68 down
        ip link delete azumig68
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 fd1d:fc98:b73e:b781::2
        /bin/bash /etc/gre68.sh 
        ping -c 1 2002:871a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_gre6tap8irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        ip link set dev azumig68 down
        ip link delete azumig68
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 fd1d:fc98:b73e:b781::1
        /bin/bash /etc/gre68.sh 
        ping -c 1 2002:871a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


# 9
def reset_ping_gre6tap9kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        ip link set dev azumig69 down
        ip link delete azumig69
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 fd1d:fc98:b73e:b881::2
        /bin/bash /etc/gre69.sh 
        ping -c 1 2002:881a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_gre6tap9irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        ip link set dev azumig69 down
        ip link delete azumig69
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 fd1d:fc98:b73e:b881::1
        /bin/bash /etc/gre69.sh 
        ping -c 1 2002:881a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


# 10
def reset_ping_gre6tap10kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        ip link set dev azumg610 down
        ip link delete azumig610
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 fd1d:fc98:b73e:b981::2
        /bin/bash /etc/gre610.sh 
        ping -c 1 2002:891a::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_gre6tap10irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891a::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        ip link set dev azumig610 down
        ip link delete azumig610
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 fd1d:fc98:b73e:b981::1
        /bin/bash /etc/gre610.sh 
        ping -c 1 2002:891a::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


# rpivate
def reset_ping_private1kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:801b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_private1irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:801b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        systemctl restart networking
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:801b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_private1new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


# 2
def reset_ping_private2kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:811b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_private2irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:811b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:811b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def resetping_service_private2new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping2.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset2.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset2"])
    subprocess.run(["systemctl", "restart", "azumireset2"])


# 2
def reset_ping_private3kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 2002:821b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_private3irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:821b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 2002:821b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def resetping_service_private3new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping3.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset3.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset3"])
    subprocess.run(["systemctl", "restart", "azumireset3"])


# 4
def reset_ping_private4kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 2002:831b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_private4irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 2002:831b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def resetping_service_private4new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping4.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset4.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset4"])
    subprocess.run(["systemctl", "restart", "azumireset4"])


# 5
def reset_ping_private5kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:841b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_private5irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:841b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def resetping_service_private5new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping5.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset5.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset5"])
    subprocess.run(["systemctl", "restart", "azumireset5"])


# 6
def reset_ping_private6kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        sleep 30
        /bin/bash /etc/private6.sh 
        ping -c 1 2002:851b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def reset_ping_private6irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi6 down
        ip link delete azumi6
        sleep 30
        /bin/bash /etc/private6.sh 
        ping -c 1 2002:851b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping6.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping6.sh", 0o755)


def resetping_service_private6new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping6.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset6.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset6"])
    subprocess.run(["systemctl", "restart", "azumireset6"])


# 7
def reset_ping_private7kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 2002:861b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def reset_ping_private7irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi7 down
        ip link delete azumi7
        sleep 30
        /bin/bash /etc/private7.sh 
        ping -c 1 2002:861b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping7.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping7.sh", 0o755)


def resetping_service_private7new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping7.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset7.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset7"])
    subprocess.run(["systemctl", "restart", "azumireset7"])


# 8
def reset_ping_private8kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 2002:871b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def reset_ping_private8irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi8 down
        ip link delete azumi8
        sleep 30
        /bin/bash /etc/private8.sh 
        ping -c 1 2002:871b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping8.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping8.sh", 0o755)


def resetping_service_private8new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping8.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset8.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset8"])
    subprocess.run(["systemctl", "restart", "azumireset8"])


# 9
def reset_ping_private9kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 2002:881b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def reset_ping_private9irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:881b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi9 down
        ip link delete azumi9
        sleep 30
        /bin/bash /etc/private9.sh 
        ping -c 1 2002:881b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping9.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping9.sh", 0o755)


def resetping_service_private9new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping9.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset9.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset9"])
    subprocess.run(["systemctl", "restart", "azumireset9"])


# 10
def reset_ping_private10kharejnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 2002:891b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def reset_ping_private10irannew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:891b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi10 down
        ip link delete azumi10
        sleep 30
        /bin/bash /etc/private10.sh 
        ping -c 1 2002:891b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping10.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping10.sh", 0o755)


def resetping_service_private10new():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping10.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset10.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset10"])
    subprocess.run(["systemctl", "restart", "azumireset10"])


def reset_ping_private1kharejsecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:831b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def reset_ping_private1iransecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:831b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi1 down
        ip link delete azumi1
        sleep 30
        /bin/bash /etc/private1.sh 
        ping -c 1 2002:831b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


# 2
def reset_ping_private2kharejsecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:841b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


def reset_ping_private2iransecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:841b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi2 down
        ip link delete azumi2
        sleep 30
        /bin/bash /etc/private2.sh 
        ping -c 1 2002:841b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping2.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping2.sh", 0o755)


# 3
def reset_ping_private3kharejsecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 2002:851b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


def reset_ping_private3iransecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:851b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi3 down
        ip link delete azumi3
        sleep 30
        /bin/bash /etc/private3.sh 
        ping -c 1 2002:851b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping3.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping3.sh", 0o755)


# 4
def reset_ping_private4kharejsecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 2002:861b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


def reset_ping_private4iransecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:861b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi4 down
        ip link delete azumi4
        sleep 30
        /bin/bash /etc/private4.sh 
        ping -c 1 2002:861b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping4.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping4.sh", 0o755)


# 5
def reset_ping_private5kharejsecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::2 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:871b::2
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def reset_ping_private5iransecnew():
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 2002:871b::1 >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        ip link set dev azumi5 down
        ip link delete azumi5
        sleep 30
        /bin/bash /etc/private5.sh 
        ping -c 1 2002:871b::1
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping5.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping5.sh", 0o755)


def name_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mTunnel names\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is a guide for tunnel names:\033[0m")
    print(
        ". \033[93mTunnel interface name : azumi       \033[97m=\033[92m Sit or 6to4\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : azumip      \033[97m=\033[92m IP6IP6\033[0m"
    )
    print(". \033[93mTunnel interface name : azumig      \033[97m=\033[92m GRE\033[0m")
    print(
        ". \033[93mTunnel interface name : azumig6     \033[97m=\033[92m GRE6 or GRE6tap\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : azumigen    \033[97m=\033[92m Geneve\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : azumiespn   \033[97m=\033[92m Erspan\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : Tun0 - Tun1 \033[97m=\033[92m ICMP Tunnel\033[0m"
    )
    print(". \033[93mTunnel interface name : icmp        \033[97m=\033[92m Hans\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[97mSome more Examples:\033[0m")
    print(
        ". \033[93mInterface names : azumi + azumig6              \033[97m=\033[92m Privateip + GRE6 | GRE6tap\033[0m"
    )
    print(
        ". \033[93mInterface names : azumi + azumig6 + azumigen   \033[97m=\033[92m Privateip + GRE6 | GRE6tap + Geneve\033[0m"
    )
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter 0 to get back to the main menu: \033[0m")
        if choice == "0":
            clear()
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def name3_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mTunnel names\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is a guide for tunnel names:\033[0m")
    print(
        ". \033[93mTunnel interface name : vxlan       \033[97m=\033[92m vxlan\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : azumi       \033[97m=\033[92m Sit or 6to4\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : azumip      \033[97m=\033[92m IP6IP6\033[0m"
    )
    print(". \033[93mTunnel interface name : azumig      \033[97m=\033[92m GRE\033[0m")
    print(
        ". \033[93mTunnel interface name : azumig6     \033[97m=\033[92m GRE6 or GRE6tap\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : azumigen    \033[97m=\033[92m Geneve\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : azumiespn   \033[97m=\033[92m Erspan\033[0m"
    )
    print(
        ". \033[93mTunnel interface name : Tun0 - Tun1 \033[97m=\033[92m ICMP Tunnel\033[0m"
    )
    print(". \033[93mTunnel interface name : icmp        \033[97m=\033[92m Hans\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter 0 to get back to the main menu: \033[0m")
        if choice == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def name2_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mTunnel names\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is a guide for tunnel names:\033[0m")
    print(
        ". \033[93miran1config3    \033[97m=\033[92m Sit | IRAN Server 1 Kharej 3\033[0m"
    )
    print(
        ". \033[93miran2config1    \033[97m=\033[92m Sit | IRAN Server 2 Kharej 1\033[0m"
    )
    print(
        ". \033[93miran5config4    \033[97m=\033[92m Sit | IRAN Server 5 Kharej 4\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter 0 to get back to the main menu: \033[0m")
        if choice == "0":
            clear()
            multi2server_mnu()
            break
        else:
            print("Invalid choice.")


def status_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mStatus\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1 \033[93mSingle Status\033[0m")
    print("2 \033[92mMulti Status\033[0m")
    print("3 \033[92mIsatap Status\033[0m")
    print("4 \033[92mWireguard Status\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter 0 to get back to the main menu: \033[0m")
        if choice == "1":
            clear()
            single_status()
            break
        elif choice == "2":
            clear()
            multi_status()
            break
        elif choice == "3":
            clear()
            isatap_status()
            break
        elif choice == "4":
            clear()
            wireguard_status()
            break
        if choice == "0":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


def bibi_codel():
    choice = input(
        "\033[93mDo you want to install BBR Codel \033[92moptimized \033[93mfor \033[96mIPSec\033[93m? \033[93m(\033[92mYes\033[93m/\033[91mNo\033[93m): \033[0m"
    ).lower()
    if choice in ["y", "yes"]:
        subprocess.run(
            [
                "bash",
                "-c",
                "python3 <(curl -Ls https://raw.githubusercontent.com/kalilovers/LightKnightBBR/main/bbr.py --ipv4)",
            ]
        )
    elif choice in ["n", "no"]:
        pass
    else:
        print("\033[91mWrong choice! Plz try again..\033[0m")


def local_tun():
    choice = input(
        "\033[93mDo you want to call \033[96mlocaltun script\033[93m? \033[93m(\033[92mYes\033[93m/\033[91mNo\033[93m): \033[0m"
    ).lower()
    if choice in ["y", "yes"]:
        subprocess.run(
            [
                "bash",
                "-c",
                "bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Azumi67/LocalTun_TCP/main/tun.sh)\"",
            ]
        )
    elif choice in ["n", "no"]:
        pass
    else:
        print("\033[91mWrong choice! Plz try again..\033[0m")

def iran5_kharej10_mnu():
    choice = input(
        "\033[93mDo you want to call \033[96mPrivate multi script\033[93m? \033[93m(\033[92mYes\033[93m/\033[91mNo\033[93m): \033[0m"
    ).lower()
    if choice in ["y", "yes"]:
        subprocess.run(
            [
                "bash",
                "-c",
                "python3 <(curl -Ls https://raw.githubusercontent.com/Azumi67/6TO4-GRE-IPIP-SIT/main/private_multi4.py --ipv4)",
            ]
        )
    elif choice in ["n", "no"]:
        pass
    else:
        print("\033[91mWrong choice! Plz try again..\033[0m")


def edit_local():
    choice = input(
        "\033[93mDo you want to call \033[96mEdit local script \033[93m? \033[93m(\033[92mYes\033[93m/\033[91mNo\033[93m): \033[0m"
    ).lower()
    if choice in ["y", "yes"]:
        subprocess.run(
            [
                "bash",
                "-c",
                "python3 <(curl -Ls https://raw.githubusercontent.com/Azumi67/6TO4-GRE-IPIP-SIT/main/wire_edit.py --ipv4)",
            ]
        )
    elif choice in ["n", "no"]:
        pass
    else:
        print("\033[91mWrong choice! Plz try again..\033[0m")

def wireguard_allinone_mnu():
    choice = input(
        "\033[93mDo you want to call \033[96mWireguard script\033[93m? \033[93m(\033[92mYes\033[93m/\033[91mNo\033[93m): \033[0m"
    ).lower()
    if choice in ["y", "yes"]:
        subprocess.run(
            [
                "bash",
                "-c",
                "python3 <(curl -Ls https://raw.githubusercontent.com/Azumi67/6TO4-GRE-IPIP-SIT/main/wireguard_script.py --ipv4)",
            ]
        )
    elif choice in ["n", "no"]:
        pass
    else:
        print("\033[91mWrong choice! Plz try again..\033[0m")

def restart_forced_strongazumi():
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"], stdout=subprocess.DEVNULL
    )


def multi2server_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mMulti 2 Server\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]KHAREJ [5]IRAN Methods\033[0m")
    print("2. \033[93mISATAP Server & Client\033[0m")
    print("3. \033[92mWireguard Server & Client\033[0m")
    print("0. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            iran5_kharej10_mnu()
            break
        elif choice == "2":
            isatap_mnu()
            break
        elif choice == "3":
            wireguard_allinone_mnu()
            break
        elif choice == "0":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


##wireguard start


def singleserver_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mSingle Server\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[36mExtra Native IPV6\033[0m")
    print("2. \033[93mEdit \033[92mMTU\033[0m")
    print("3. \033[92mGeneve UDP \033[0m")
    print("4. \033[96mGeneve + IPsec\033[0m")
    print("5. \033[93mICMP + IPsec\033[0m")
    print("42.\033[97mERSPAN [test][Some of them will be removed]\033[0m")
    print("6. \033[96mIP6IP6\033[0m")
    print("7. \033[92mIP6IP6 + IPSec\033[0m")
    print("8. \033[93mPrivate IP\033[0m")
    print("9. \033[96mPrivate IP + IPSec\033[0m")
    print("10. \033[92mGRE\033[0m")
    print("11. \033[96mGRE6\033[0m")
    print("12. \033[93mGRE6 + IPSec\033[0m")
    print("13. \033[97mGRE6tap\033[0m")
    print("14. \033[96mGRE6tap + IPSec\033[0m")
    print("15. \033[93m6TO4 \033[0m")
    print("16. \033[92m6TO4 \033[97m[Anycasnt] \033[0m")
    print("17. \033[93mVxlan \033[0m")
    print("18. \033[96mVxlan + IPsec \033[0m")
    print("19. \033[91mUninstall\033[0m")
    print("q. \033[91mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            Native_menu()
            break
        elif choice == "2":
            mtu_menu()
            break
        elif choice == "3":
            genz_ip()
            break
        elif choice == "42":
            espn_menu()
            break
        elif choice == "4":
            gen4_ipsec_mnu()
            break
        elif choice == "5":
            icmp_ip_mnu()
            break
        elif choice == "6":
            ipip_menu()
            break
        elif choice == "7":
            ipip__ipsec_menu()
            break
        elif choice == "8":
            private_ip_menu()
            break
        elif choice == "9":
            private_ipsec()
            break
        elif choice == "10":
            gre_menu()
            break
        elif choice == "11":
            gre6_menu()
            break
        elif choice == "12":
            gre6sec_menu()
            break
        elif choice == "13":
            gre6tapsingle_mnu()
            break
        elif choice == "14":
            gre6tapsec_mnu()
            break
        elif choice == "15":
            i6to4_no()
            break
        elif choice == "16":
            i6to4_any()
            break
        elif choice == "17":
            vxlan_choose_regular()
            break
        elif choice == "18":
            vxlan_choose_ipsecmnu()
            break
        elif choice == "19":
            remove_menu()
            break
        elif choice == "q":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


def multiserver_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mMulti Server\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("0  \033[92mTunnel Names Guide \033[97mMENU\033[0m")
    print("1. \033[96mIP6IP6 Multiple Servers\033[0m")
    print("2. \033[93mIP6IP6 + IPSec Multiple Servers\033[0m")
    print("3. \033[92mGRE6 Multiple Servers\033[0m")
    print("4. \033[96mGRE6 + IPSsec Multiple Servers\033[0m")
    print("5. \033[93m6tO4 Multiple Servers\033[0m")
    print("6. \033[96m6tO4 + IPsec Multiple Servers\033[0m")
    print("7. \033[92mGre6tap Multiple Servers\033[0m")
    print("8. \033[93mGeneve Multiple Servers\033[0m")
    print("9. \033[96mAnycast Multiple Servers\033[0m")
    print("10. \033[93mEdit \033[92mServers\033[0m")
    print("11. \033[97mEdit \033[92mMTU\033[0m")
    print("12. \033[91mUninstall\033[0m")
    print("q. \033[91mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "0":
            name_mnu()
            break
        elif choice == "1":
            ip6_mnu_ip()
            break
        elif choice == "2":
            ip6_mnu_ipsec()
            break
        elif choice == "3":
            gre6_mnu_ip()
            break
        elif choice == "4":
            gre6_mnu_ipsec()
            break
        elif choice == "5":
            priv_mnu_ip()
            break
        elif choice == "6":
            priv_mnu_ipsec()
            break
        elif choice == "7":
            gre6tapmulti_mnu()
            break
        elif choice == "8":
            gen_multi_menuz()
            break
        elif choice == "9":
            i6to41_any()
            break
        elif choice == "10":
            edit_server()
            break
        elif choice == "11":
            mtu2_menu()
            break
        elif choice == "12":
            remove2_menu()
            break
        elif choice == "q":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


## gretapsec
def gre6tapsec_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGRE6tap + IPSec\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE6tap IPV4 + IPSec \033[0m")
    print("2. \033[93mGRE6tap Native + IPSec \033[0m")
    print("3. \033[96mIPsec Reset Timer \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnusingle()
            gretap4sec()
            break
        elif server_type == "2":
            gre6_reset_rmvmnusingle()
            gretapnsec()
            break
        elif server_type == "3":
            choose_reset()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def gretapnsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative \033[93m+\033[92m Gretap6 + IPSec \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tapsec_k()
            break
        elif server_type == "2":
            gre6tapsec_i()
            break
        elif server_type == "3":
            clear()
            gre6tapsec_mnu()
            break
        else:
            print("Invalid choice.")


def azumi_gretap_k(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def azumi_gretap_ir(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def gre6tapsec_k():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_gretap_k(psk)
    kharej_gre6tap_tunnel()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tapsec_i():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_gretap_ir(psk)
    iran_gre6tap_tunnel()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


## gre6tap ip4


def gretap4sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[96mGRE6tap + IPSec \033[93m+ \033[92mIPV4 \033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap6sec_kharej()
            break
        elif server_type == "2":
            gre6tap6sec_iran()
            break
        elif server_type == "3":
            clear()
            gre6tapsec_mnu()
            break
        else:
            print("Invalid choice.")


def gre6tap6sec_kharej():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_gretap_k(psk)
    kharej_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6sec_iran():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_gretap_ir(psk)
    iran_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


## gre6tap simple


def gre6tapsingle_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGRE6tap\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE6tap IPV4 \033[0m")
    print("2. \033[93mGRE6tap Native \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnusingle()
            gretap4()
            break
        elif server_type == "2":
            gre6_reset_rmvmnusingle()
            gretapn()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def gretapn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_k()
            break
        elif server_type == "2":
            gre6tap_i()
            break
        elif server_type == "3":
            clear()
            gre6tapsingle_mnu()
            break
        else:
            print("Invalid choice.")


def gre6tapk_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def kharej_gre6tap_tunnel():
    global local_ip, remote_ip
    gre6tapk_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    gre6_cronjob()


def gre6tap_k():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def iran_gre6tap_tunnel():
    global local_ip, remote_ip
    gre6tapi_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    gre6_cronjob()


def gre6tap_i():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


## gre6tap ip4


def gretap4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mGRE6tap \033[93m+ \033[92mIPV4 \033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap6_kharej()
            break
        elif server_type == "2":
            gre6tap6_iran()
            break
        elif server_type == "3":
            clear()
            gre6tapsingle_mnu()
            break
        else:
            print("Invalid choice.")


def gre6tap6_kharej():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iran():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def espn_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mERSPAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan \033[0m")
    print("2. \033[93mErspan + \033[92mNative \033[0m")
    print("3. \033[96mErspan + ip6ip6 [NEW] \033[0m")
    print("4. \033[93mErspan + Gretap6 \033[0m")
    print("5. \033[92mErspan + IPsec Tunnels \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ip4_spn()
            break
        elif server_type == "2":
            ip6_spn()
            break
        elif server_type == "3":
            spn_ipip6()
            break
        elif server_type == "4":
            spn_gre6tap()
            break
        elif server_type == "5":
            ipsec_mnu()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


# simple ip4 & native ipip6
def spn_ipip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mIP6IP6 \033[93m+ \033[96mErspan\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mMethod 1 \033[0m")
    print("2. \033[92mMethod 2 \033[0m")
    print("3. \033[93mMethod 3 Native \033[0m")
    print("0. \033[91mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_m2_ipip4()
            break
        elif server_type == "2":
            spn_m2_sit4()
            break
        elif server_type == "3":
            spn_ipipn()
            break
        elif server_type == "0":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


# native ipip spn
def spn_ipipn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mERSPAN +  \033[96mNative \033[93m+\033[92m IP6IP6 \033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipip_gre6k()
            break
        elif server_type == "2":
            spn_ipip_gre6i()
            break
        elif server_type == "3":
            clear()
            spn_ipip6()
            break
        else:
            print("Invalid choice.")


def spn_ipip_gre6k():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipip_grek1()
            break
        elif server_type == "2":
            spn_ipip_grek2()
            break
        else:
            print("Invalid choice.")


def ipip6rn_kharej1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/sys.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip6 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
            with open("/etc/sys.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip6 mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def ip6ip6_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/sys.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/sys.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ipip6rn_kharej1():
    ipip6rn_kharej1_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    ip6ip6_cronjob()


def spn_ipip_grek1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    ipip6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def spn_ipip_grek2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    ipip6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# iran


def ipip6rn_iran1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/sys.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip6 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
            with open("/etc/sys.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip6 mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def ipip6rn_iran1():
    ipip6rn_iran1_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    ip6ip6_cronjob()


def spn_ipip_gre6i():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipip_grei1()
            break
        elif server_type == "2":
            spn_ipip_grei2()
            break
        else:
            print("Invalid choice.")


def spn_ipip_grei1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    ipip6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def spn_ipip_grei2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    ipip6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# ip4 ip6ip6 erspan


def spn_ipip4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[96mMethod 1 \033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipip_kharej()
            break
        elif server_type == "2":
            spn_ipip_iran()
            break
        elif server_type == "3":
            clear()
            spn_ipip6()
            break
        else:
            print("Invalid choice.")


def spn_ipip_kharej():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_ipipkh()


def spn_ipipkh():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipipk_1()
            break
        elif server_type == "2":
            spn_ipipk_2()
            break
        else:
            print("Invalid choice.")


def ip6ip64_kharej():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mIP6IP6\033[97m tunnel: "
        )
    )
    ipip64_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    ip6ip6_cronjob()


# espn_gre
def kharej1_ip6ip64_menu():
    global local_ip, remote_ip
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
        f.write("ip -6 route add fd1d::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mServer Configuration Completed!\033[0m")
    ip6ip64_kharej()
    sleep(1)


##
def spn_ipipk_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_ip6ip64_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def spn_ipipk_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_ip6ip64_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def spn_ipip_iran():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn2_ipipir()


def spn2_ipipir():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipipi_1()
            break
        elif server_type == "2":
            spn_ipipi_2()
            break
        else:
            print("Invalid choice.")


## prequisite
def ip6ip64_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/sys.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip6' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
        with open("/etc/sys.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip6 mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ip6ip64_iran():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mIP6IP6\033[97m tunnel: "
        )
    )
    ip6ip64_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    ip6ip6_cronjob()


## ip6ip6 erspan iran
def iran1_ip6ip64_menu():
    global local_ip, remote_ip
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
        f.write("ip -6 route add fd1d::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_pingg()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    ip6ip64_iran()
    sleep(1)
    display_checkmark("\033[92mServer Configuration Completed!\033[0m")


##
def spn_ipipi_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_ip6ip64_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5

interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def spn_ipipi_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_ip6ip64_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5

interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## method2
# ip4 ipip erspan


def spn_m2_ipip4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[92mMethod 1 \033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_m2_ipip_kharej()
            break
        elif server_type == "2":
            spn_m2_ipip_iran()
            break
        elif server_type == "3":
            clear()
            spn_m2_ipip6()
            break
        else:
            print("Invalid choice.")


def spn_m2_ipip_kharej():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_m2_ipipkh()


def spn_m2_ipipkh():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_m2_ipipk_1()
            break
        elif server_type == "2":
            spn_m2_ipipk_2()
            break
        else:
            print("Invalid choice.")


## method2 menu
def spn_m2_sit4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[92mMethod 2 \033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_m2_sit_kharej()
            break
        elif server_type == "2":
            spn_m2_sit_iran()
            break
        elif server_type == "3":
            clear()
            spn_m2_ipip6()
            break
        else:
            print("Invalid choice.")


def spn_m2_sit_kharej():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_m2_sitkh()


def spn_m2_sitkh():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_m2_sitk_1()
            break
        elif server_type == "2":
            spn_m2_sitk_2()
            break
        else:
            print("Invalid choice.")


# prequisite
def ipip64_m2_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/sys.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo '/sbin/modprobe fou' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumip6 type ipip remote {remote_ip} local {local_ip} encap fou encap-sport auto encap-dport 5555' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip addr add 192.168.1.1/30 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip6 mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


def ip6ip64_m2_kharej():

    ipip64_m2_tunnel()

    ip_address = "192.168.1.2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    ip6ip6_cronjob()


# espn_sit
def kharej1_m2_ip6ip64_menu():
    global local_ip, remote_ip
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "link",
            "add",
            "name",
            "azumi",
            "type",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "addr", "add", "192.168.1.1/30", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip link add name azumi type sit remote {remote_ip} local {local_ip}\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add 192.168.1.1/30 dev azumi\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="192.168.1.2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_checkmark("\033[92mServer Configuration Completed!\033[0m")


## for ipip
def spn_m2_ipipk_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip6ip64_m2_kharej()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.1",
            "remote",
            "192.168.1.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.1 remote 192.168.1.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## for sit
def spn_m2_sitk_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_m2_sitk_1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.1",
            "remote",
            "192.168.1.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.1 remote 192.168.1.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


##ipv6 for ipip
def spn_m2_ipipk_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip6ip64_m2_kharej()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.1",
            "remote",
            "192.168.1.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.1 remote 192.168.1.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


##ipv6 for sit
def spn_m2_sitk_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_m2_ip6ip64_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.1",
            "remote",
            "192.168.1.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.1 remote 192.168.1.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# iran side


def spn_m2_ipip_iran():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn2_m2_ipipir()


def spn2_m2_ipipir():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_m2_ipipi_1()
            break
        elif server_type == "2":
            spn_m2_ipipi_2()
            break
        else:
            print("Invalid choice.")


# method 2 iran ip6 erspan
def spn_m2_sit_iran():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn2_m2_sitir()


def spn2_m2_sitir():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_m2_siti_1()
            break
        elif server_type == "2":
            spn_m2_siti_2()
            break
        else:
            print("Invalid choice.")


## prequisite ipip
def ip6ip64_m2_iran_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/sys.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo '/sbin/modprobe fou' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumip6 type ipip remote {remote_ip} local {local_ip} encap fou encap-sport auto encap-dport 5555' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip addr add 192.168.1.2/30 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip6 mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


# prequisite sit
def ip6ip64_m2_iran():
    global local_ip, remote_ip
    ip6ip64_m2_iran_tunnel()

    ip_address = "192.168.1.1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    ip6ip6_cronjob()


## IP6IP6 erspan iran
def iran1_m2_ip6ip64_menu():
    global local_ip, remote_ip
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "link",
            "add",
            "name",
            "azumi",
            "type",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "addr", "add", "192.168.1.2/30", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip link add name azumi type sit remote {remote_ip} local {local_ip}\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add 192.168.1.2/30 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="192.168.1.1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_checkmark("\033[92mServer Configuration Completed!\033[0m")


## method2 ipip erspan6
def spn_m2_ipipi_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip6ip64_m2_iran()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.2",
            "remote",
            "192.168.1.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.2 remote 192.168.1.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## method3 sit erspan4
def spn_m2_siti_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_m2_ip6ip64_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.2",
            "remote",
            "192.168.1.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.2 remote 192.168.1.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def spn_m2_ipipi_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip6ip64_m2_iran()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.2",
            "remote",
            "192.168.1.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.2 remote 192.168.1.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")

#robot#
def robot_menu():
    choice = input(
        "\033[93mDo you want to call \033[96mRobot script \033[93m? \033[93m(\033[92mYes\033[93m/\033[91mNo\033[93m): \033[0m"
    ).lower()
    if choice in ["y", "yes"]:
        subprocess.run(
            [
                "bash",
                "-c",
                "python3 <(curl -Ls https://raw.githubusercontent.com/Azumi67/6TO4-GRE-IPIP-SIT/main/re.py --ipv4)",
            ]
        )
    elif choice in ["n", "no"]:
        pass
    else:
        print("\033[91mWrong choice! Plz try again..\033[0m")
## sit
def spn_m2_siti_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_m2_ip6ip64_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "192.168.1.2",
            "remote",
            "192.168.1.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 192.168.1.2 remote 192.168.1.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## simple ip4 & native gretap6
def spn_gre6tap():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGRE6tap \033[93m+ \033[96mErspan\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + GRE6tap IPV4 \033[0m")
    print("2. \033[93mErspan + GRE6tap Native \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_gretap4()
            break
        elif server_type == "2":
            spn_gretapn()
            break
        elif server_type == "0":
            clear()
            espn_menu()
            break
        else:
            print("Invalid choice.")


# native gre spn
def spn_gretapn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mERSPAN +  \033[96mNative \033[93m+\033[92m Gretap6 \033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_sim_gre6tapk()
            break
        elif server_type == "2":
            spn_sim_gre6tapi()
            break
        elif server_type == "3":
            clear()
            spn_gre6tap()
            break
        else:
            print("Invalid choice.")


def spn_sim_gre6tapk():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ip4_gretapk1()
            break
        elif server_type == "2":
            spn_ip4_gretapk2()
            break
        else:
            print("Invalid choice.")


def tap6rn_kharej1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def tap6rn_kharej1():
    tap6rn_kharej1_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", "2002:831a::2"], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    gre6_cronjob()


def spn_ip4_gretapk1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    tap6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def spn_ip4_gretapk2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    tap6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# iran


def tap6rn_iran1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def tap6rn_iran1():
    tap6rn_iran1_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    gre6_cronjob()


def spn_sim_gre6tapi():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ip4_gretapi1()
            break
        elif server_type == "2":
            spn_ip4_gretapi2()
            break
        else:
            print("Invalid choice.")


def spn_ip4_gretapi1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    tap6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def spn_ip4_gretapi2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    tap6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# ip4 gre6 erspan


def spn_gretap4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mErspan \033[93m+ \033[96mGRE6tap \033[93m+ \033[92mIPV4 \033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gretapk_spn()
            break
        elif server_type == "2":
            gretapi_spn()
            break
        elif server_type == "3":
            clear()
            spn_gre6tap()
            break
        else:
            print("Invalid choice.")


def gretapk_spn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_kh_tap()


def spn_kh_tap():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipk_tap1()
            break
        elif server_type == "2":
            spn_ipk_tap2()
            break
        else:
            print("Invalid choice.")


def spn_ipk_tap1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def spn_ipk_tap2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gretapi_spn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn2_tapir()


def spn2_tapir():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_tapipi_1()
            break
        elif server_type == "2":
            spn_tapipi_2()
            break
        else:
            print("Invalid choice.")


def spn_tapipi_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def spn_tapipi_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# simple ip4 & native gre6
def spn_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGRE6 \033[93m+ \033[96mErspan\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + GRE6 IPV4 \033[0m")
    print("2. \033[93mErspan + GRE6 Native \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_gre4()
            break
        elif server_type == "2":
            spn_gren()
            break
        elif server_type == "0":
            clear()
            espn_menu()
            break
        else:
            print("Invalid choice.")


# native gre spn
def spn_gren():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mERSPAN +  \033[96mNative \033[93m+\033[92m Gre6 \033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_sim_gre6k()
            break
        elif server_type == "2":
            spn_sim_gre6i()
            break
        elif server_type == "3":
            clear()
            spn_gre6()
            break
        else:
            print("Invalid choice.")


def spn_sim_gre6k():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ip4_grek1()
            break
        elif server_type == "2":
            spn_ip4_grek2()
            break
        else:
            print("Invalid choice.")


def gree6rn_kharej1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def gree6rn_kharej1():
    gree6rn_kharej1_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    gre6_cronjob()


def spn_ip4_grek1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    gree6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def spn_ip4_grek2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    gree6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# iran


def gree6rn_iran1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def gree6rn_iran1():
    gree6rn_iran1_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    gre6_cronjob()


def spn_sim_gre6i():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ip4_grei1()
            break
        elif server_type == "2":
            spn_ip4_grei2()
            break
        else:
            print("Invalid choice.")


def spn_ip4_grei1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    gree6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def spn_ip4_grei2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    gree6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# ip4 gre6 erspan


def spn_gre4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mErspan \033[93m+ \033[96mGRE6 \033[93m+ \033[92mIPV4 \033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_spn_mnu()
            break
        elif server_type == "2":
            iran_spn_mnu()
            break
        elif server_type == "3":
            clear()
            spn_gre6()
            break
        else:
            print("Invalid choice.")


def kharej_spn_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_kh()


def spn_kh():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipk_1()
            break
        elif server_type == "2":
            spn_ipk_2()
            break
        else:
            print("Invalid choice.")


def spn_ipk_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def spn_ipk_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def iran_spn_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn2_ir()


def spn2_ir():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipi_1()
            break
        elif server_type == "2":
            spn_ipi_2()
            break
        else:
            print("Invalid choice.")


def spn_ipi_1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def spn_ipi_2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# gre6tap ip4 & ip6


def ipsec_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan + IPsec\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + IPsec \033[0m")
    print("2. \033[96mGRE6 | Erspan + IPsec  \033[0m")
    print("3. \033[93mGRE6tap | Erspan + IPsec  \033[0m")
    print("4. \033[96mIPsec Reset Timer \033[92m[Optional] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            simple_ipsec_mn()
            break
        elif server_type == "2":
            espn_sec()
            break
        elif server_type == "3":
            espn_gretap()
            break
        elif server_type == "4":
            choose_reset()
            break
        elif server_type == "0":
            clear()
            espn_menu()
            break
        else:
            print("Invalid choice.")


# reset
def ipsec_sh():
    subprocess.run(["rm", "-f", "/etc/ipsec.sh"])

    ipsec_script = """
#!/bin/bash

sudo systemctl daemon-reload
sudo ipsec stop
sudo systemctl restart strongswan-starter
sudo systemctl restart strongswan
sudo journalctl --vacuum-size=1M --unit=strongswan-starter.service
sudo journalctl --vacuum-size=1M --unit=strongswan.service


"""

    with open("/etc/ipsec.sh", "w") as file:
        file.write(ipsec_script)
    subprocess.run(["chmod", "+x", "/etc/ipsec.sh"])


def ipsec2_sh():
    subprocess.run(["rm", "-f", "/etc/ipsec2.sh"])

    ipsec_script = """
#!/bin/bash
sudo systemctl daemon-reload
sudo ipsec stop
sudo systemctl restart strong-azumi1
sudo journalctl --vacuum-size=1M --unit=strong-azumi1.service

"""

    with open("/etc/ipsec2.sh", "w") as file:
        file.write(ipsec_script)
    subprocess.run(["chmod", "+x", "/etc/ipsec2.sh"])


# ipsec
def vxlan_choose_ipsecmnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan IPSEC Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan Method:\033[0m")
    print("1. \033[92mRegular Vxlan + IPSEC\033[0m")
    print("2. \033[93mVXLAN + Geneve + IPSEC [ Working on it]\033[0m")
    print("3. \033[96mVxlan + DNS + IPSEC [ Working on it]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlan_menusec1()
            break
        elif server_type == "2":
            vxlan_menusec2()
            break
        elif server_type == "3":
            vxlan_menusec3()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def vxlan_menusec1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mRegular Vxlan IPSEC Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Regular Vxlan + IPSEC Method:\033[0m")
    print("1. \033[96mP2P\033[0m")
    print("2. \033[92mVXLAN Bridge Setup with IP Pointing\033[0m")
    print("3. \033[93mFDB VXLAN /W Bridge\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlansec_p2p()
            break
        elif server_type == "2":
            vxlan_pointipsec()
            break
        elif server_type == "3":
            vxlan_macipsec()
            break
        elif server_type == "0":
            clear()
            vxlan_choose_ipsecmnu()
            break
        else:
            print("Invalid choice.")


def vxlansec_p2p():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlanp2p_ipv4_sec()
            break
        elif server_type == "2":
            vxlanp2p_ipv6_sec()
            break
        elif server_type == "0":
            clear()
            vxlan_menusec1()
            break
        else:
            print("Invalid choice.")


def get_default_interface():
    try:
        output = subprocess.check_output(["ip", "route", "show", "default"]).decode()
        lines = output.strip().split("\n")
        for line in lines:
            if "default via" in line:
                parts = line.split()
                interface = parts[4]
                return interface
    except subprocess.CalledProcessError:
        pass
    return None


def has_ipv4_address(interface):
    addresses = netifaces.ifaddresses(interface)
    return netifaces.AF_INET in addresses


def main_interface():
    default_interface = get_default_interface()
    if default_interface and has_ipv4_address(default_interface):
        return default_interface

    return None


def vxlan_ping1():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "30.0.0.2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def vxlan_ping2():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "30.0.0.1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def vxlan_cron_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/bin/bash /usr/local/bin/bridge.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /usr/local/bin/bridge.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_vxlan_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_vxlan.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_vxlan_service.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_vxlan_service"])
    subprocess.run(["systemctl", "start", "ping_vxlan_service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_vxlan_service"])


def install_vxlan():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling Bridge..\033[0m")
    install_process = subprocess.Popen(
        ["sudo", "apt", "install", "bridge-utils", "iproute2", "-y"]
    )
    install_process.wait()
    print("Bridge Installation complete.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")


def config_vxlan(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn vxlan1
  left=%defaultroute
  leftsubnet=30.0.0.1/32
  leftid=30.0.0.1
  right=30.0.0.2
  rightsubnet=30.0.0.2/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'30.0.0.2 30.0.0.1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def permissionz1():
    print("Setting permissions for config files...")
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    print("Setting permissions was successful.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")


def config_vxlan2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn vxlan1
  left=%defaultroute
  leftsubnet=30.0.0.2/32
  leftid=30.0.0.2
  right=30.0.0.1
  rightsubnet=30.0.0.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'30.0.0.1 30.0.0.2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def vxlan_pingv6_1():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db8:0:1::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def vxlan_pingv6_2():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db8:0:1::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def configv6_vxlan(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn vxlan1
  left=%defaultroute
  leftsubnet=2001:db8:0:1::1/64
  leftid=2001:db8:0:1::1
  right=2001:db8:0:1::2
  rightsubnet=2001:db8:0:1::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8:0:1::2 2001:db8:0:1::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def configv6_vxlan2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn vxlan1
  left=%defaultroute
  leftsubnet=2001:db8:0:1::2/64
  leftid=2001:db8:0:1::2
  right=2001:db8:0:1::1
  rightsubnet=2001:db8:0:1::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8:0:1::1 2001:db8:0:1::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def vxlanp2p_ipv4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan P2P IPSEC V4 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejsec_vxlan_v4p2p()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iransec_vxlan_v4p2p()
            restart_forced_strongazumi()
            break
        elif server_type == "0":
            os.system("clear")
            vxlansec_p2p()
            break
        else:
            print("Invalid choice.")


def kharejsec_vxlan_v4p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P IPSEC \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    config_vxlan(psk)
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.1/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 30.0.0.1/24 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P /W IPSEC Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.1         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iransec_vxlan_v4p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    config_vxlan2(psk)
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.2/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 30.0.0.2/24 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P /W IPSEC Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.2         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# ipv6
def vxlanp2p_ipv6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan P2P IPSEC V6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejv6sec_vxlan_p2p()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iranv6sec_vxlan_p2p()
            restart_forced_strongazumi()
            break
        elif server_type == "0":
            os.system("clear")
            vxlansec_p2p()
            break
        else:
            print("Invalid choice.")


def kharejv6sec_vxlan_p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P IPSEC V6 \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    configv6_vxlan(psk)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::1/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::1/64 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P /W IPSEC Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::1      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iranv6sec_vxlan_p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P IPSEC V6 \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    configv6_vxlan2(psk)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::2/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::2/64 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P /W IPSEC Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::2       |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# method2 brige point ip


def vxlan_macipsec():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlanmac_ipv4_sec()
            break
        elif server_type == "2":
            vxlanmac_ipv6_sec()
            break
        elif server_type == "0":
            clear()
            vxlan_menusec1()
            break
        else:
            print("Invalid choice.")


def vxlanmac_ipv4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Bridge & Mac IPSEC V4 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejsec_vxlan_v4mac()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iransec_vxlan_v4mac()
            restart_forced_strongazumi()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_macipsec()
            break
        else:
            print("Invalid choice.")


def kharejsec_vxlan_v4mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring Vxlan Bridge & Mac IPSEC \033[92mKharej\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    config_vxlan(psk)
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.1/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 30.0.0.1/24 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.1         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iransec_vxlan_v4mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Mac IPSEC \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    config_vxlan2(psk)
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.2/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 30.0.0.2/24 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.2         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# ipv6
def vxlanmac_ipv6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Mac IPSEC V6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejv6sec_vxlan_mac()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iranv6sec_vxlan_mac()
            restart_forced_strongazumi()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_macipsec()
            break
        else:
            print("Invalid choice.")


def kharejv6sec_vxlan_mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Mac IPSEC V6 \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    configv6_vxlan(psk)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::1/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::1/64 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::1      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iranv6sec_vxlan_mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Mac IPSEC V6 \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    configv6_vxlan2(psk)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::2/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::2/64 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::2      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# method 2 point
def vxlan_pointipsec():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlanip_ipv4_sec()
            break
        elif server_type == "2":
            vxlanip_ipv6_sec()
            break
        elif server_type == "0":
            clear()
            vxlan_menusec1()
            break
        else:
            print("Invalid choice.")


def vxlanip_ipv4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Bridge & IP IPSEC V4 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejsec_vxlan_v4ip()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iransec_vxlan_v4ip()
            restart_forced_strongazumi()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_pointipsec()
            break
        else:
            print("Invalid choice.")


def kharejsec_vxlan_v4ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring Vxlan Bridge & IP IPSEC \033[92mKharej\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    config_vxlan(psk)
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.1/24", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 30.0.0.1/24 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.1         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iransec_vxlan_v4ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan IP IPSEC \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    config_vxlan2(psk)
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.2/24", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 30.0.0.2/24 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.2         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# ipv6
def vxlanip_ipv6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan IP IPSEC V6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejv6sec_vxlan_ip()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iranv6sec_vxlan_ip()
            restart_forced_strongazumi()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_pointipsec()
            break
        else:
            print("Invalid choice.")


def kharejv6sec_vxlan_ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan IP IPSEC V6 \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    configv6_vxlan(psk)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::1/64", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 2001:db8:0:1::1/64 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::1      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iranv6sec_vxlan_ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan IP IPSEC V6 \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    configv6_vxlan2(psk)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::2/64", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 2001:db8:0:1::2/64 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::2      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# no ipsec


def vxlan_choose_regular():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan Method:\033[0m")
    print("1. \033[92mRegular Vxlan\033[0m")
    print("2. \033[93mIsatap + Vxlan \033[0m")
    print("3. \033[96mSit + Vxlan \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlan_menu1()
            break
        elif server_type == "2":
            vxlan_menu2()
            break
        elif server_type == "3":
            vxlan_menu3()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def vxlan_menu1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mRegular Vxlan Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Regular Vxlan Method:\033[0m")
    print("1. \033[96mP2P\033[0m")
    print("2. \033[92mVXLAN Bridge Setup /W IP Pointing\033[0m")
    print("3. \033[93mFDB VXLAN /W Bridge\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlan_p2p()
            break
        elif server_type == "2":
            vxlan_pointip()
            break
        elif server_type == "3":
            vxlan_macip()
            break
        elif server_type == "0":
            clear()
            vxlan_choose_regular()
            break
        else:
            print("Invalid choice.")


def vxlan_p2p():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlanp2p_ipv4_regular()
            break
        elif server_type == "2":
            vxlanp2p_ipv6_regular()
            break
        elif server_type == "0":
            clear()
            vxlan_menu1()
            break
        else:
            print("Invalid choice.")


def vxlanp2p_ipv4_regular():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan P2P V4 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_vxlan_v4p2p()
            break
        elif server_type == "2":
            iran_vxlan_v4p2p()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_p2p()
            break
        else:
            print("Invalid choice.")


def kharej_vxlan_v4p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.1/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 30.0.0.1/24 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.1         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_vxlan_v4p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    ufw(remote_ip)
    ufw("30.0.0.2")
    ufw("30.0.0.1")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.2/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 30.0.0.2/24 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.2         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# ipv6
def vxlanp2p_ipv6_regular():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan P2P V6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejv6_vxlan_p2p()
            break
        elif server_type == "2":
            iranv6_vxlan_p2p()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_p2p()
            break
        else:
            print("Invalid choice.")


def kharejv6_vxlan_p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P V6 \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::1/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::1/64 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::1      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iranv6_vxlan_p2p():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan P2P V6 \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN \033[93mIPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "88",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "dev",
            interface,
            "dstport",
            dst_port,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::2/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "up"], stdout=subprocess.DEVNULL
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 88 local {local_ip} remote {remote_ip} dev {interface} dstport {dst_port}\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::2/64 dev vxlan\n")
        f.write("sudo ip link set vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan P2P Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::2      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# method2 brige point ip


def vxlan_macip():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlanmac_ipv4_regular()
            break
        elif server_type == "2":
            vxlanmac_ipv6_regular()
            break
        elif server_type == "0":
            clear()
            vxlan_menu1()
            break
        else:
            print("Invalid choice.")


def vxlanmac_ipv4_regular():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Bridge & Mac V4 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_vxlan_v4mac()
            break
        elif server_type == "2":
            iran_vxlan_v4mac()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_macip()
            break
        else:
            print("Invalid choice.")


def kharej_vxlan_v4mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Bridge & Mac \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.1/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 30.0.0.1/24 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.1         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_vxlan_v4mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Mac \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("30.0.0.2")
    ufw("30.0.0.1")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.2/24", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 30.0.0.2/24 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.2         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# ipv6
def vxlanmac_ipv6_regular():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Mac V6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejv6_vxlan_mac()
            break
        elif server_type == "2":
            iranv6_vxlan_mac()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_macip()
            break
        else:
            print("Invalid choice.")


def kharejv6_vxlan_mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Mac V6 \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::1/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::1/64 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|       2001:db8:0:1::1     |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iranv6_vxlan_mac():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Mac V6 \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "100",
            "dstport",
            dst_port,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        [
            "sudo",
            "bridge",
            "fdb",
            "append",
            "to",
            "00:00:00:00:00:00",
            "dst",
            remote_ip,
            "dev",
            "vxlan",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::2/64", "dev", "vxlan"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 100 dstport {dst_port} dev {interface} \n"
        )
        f.write(
            f"sudo bridge fdb append to 00:00:00:00:00:00 dst {remote_ip} dev vxlan\n"
        )
        f.write("sudo ip addr add 2001:db8:0:1::2/64 dev vxlan\n")
        f.write("sudo ip link set dev vxlan up\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan FDB With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::2      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# method 2 point
def vxlan_pointip():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Vxlan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlanip_ipv4_regular()
            break
        elif server_type == "2":
            vxlanip_ipv6_regular()
            break
        elif server_type == "0":
            clear()
            vxlan_menu1()
            break
        else:
            print("Invalid choice.")


def vxlanip_ipv4_regular():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Bridge & IP V4 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_vxlan_v4ip()
            break
        elif server_type == "2":
            iran_vxlan_v4ip()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_pointip()
            break
        else:
            print("Invalid choice.")


def kharej_vxlan_v4ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan Bridge & IP \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.1/24", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 30.0.0.1/24 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.1         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_vxlan_v4ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan IP \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("30.0.0.1")
    ufw("30.0.0.2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "30.0.0.2/24", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 30.0.0.2/24 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="30.0.0.1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|          30.0.0.2         |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# ipv6
def vxlanip_ipv6_regular():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan IP V6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejv6_vxlan_ip()
            break
        elif server_type == "2":
            iranv6_vxlan_ip()
            break
        elif server_type == "0":
            os.system("clear")
            vxlan_pointip()
            break
        else:
            print("Invalid choice.")


def kharejv6_vxlan_ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan IP V6 \033[92mKharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding Vxlan IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::1/64", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 2001:db8:0:1::1/64 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mKharej Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::1      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iranv6_vxlan_ip():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Vxlan IP V6 \033[92mIRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification("\033[93mAdding Vxlan IP addresses for IRAN server...\033[0m")

    if os.path.isfile("/usr/local/bin/bridge.sh"):
        os.remove("/usr/local/bin/bridge.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    dst_port = input("\033[93mEnter \033[92mdestination port\033[93m: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufwport(dst_port)
    install_vxlan()
    ufw(remote_ip)
    ufw("2001:db8:0:1::1")
    ufw("2001:db8:0:1::2")
    find_interface = input(
        "\033[93mDo you want meh to find the \033[92mmain interface\033[96m automatically\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if find_interface.lower() == "yes" or find_interface.lower() == "y":
        interface = main_interface()
        if interface is None:
            print("\033[91merror: Couldn't find your network interface.\033[0m")
            return
    else:
        interface = input(
            "\033[93mWhat is your \033[92mmain interface\033[93m? \033[0m"
        )

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "vxlan",
            "type",
            "vxlan",
            "id",
            "42",
            "dstport",
            dst_port,
            "remote",
            remote_ip,
            "dev",
            interface,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "add", "azumibr", "type", "bridge"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "vxlan", "master", "azumibr"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "vxlan", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "dev", "azumibr", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8:0:1::2/64", "dev", "azumibr"],
        stdout=subprocess.DEVNULL,
    )

    with open("/usr/local/bin/bridge.sh", "w") as f:
        f.write(
            f"sudo ip link add vxlan type vxlan id 42 dstport {dst_port} remote {remote_ip} dev {interface} \n"
        )
        f.write("sudo ip link add azumibr type bridge\n")
        f.write("sudo ip link set vxlan master azumibr\n")
        f.write("sudo ip link set dev vxlan up\n")
        f.write("sudo ip link set dev azumibr up\n")
        f.write("sudo ip addr add 2001:db8:0:1::2/64 dev azumibr\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Vxlan & Bridge]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value[Vxlan]\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"
        mtu_value2 = input(
            "\033[93mEnter the desired\033[92m MTU value[Bridge]\033[93m: \033[0m"
        )
        mtu_command2 = f"ip link set dev azumibr mtu {mtu_value2}\n"
        with open("/usr/local/bin/bridge.sh", "a") as f:
            f.write(mtu_command)
            f.write(mtu_command2)
        subprocess.run(mtu_command, shell=True, check=True)
        subprocess.run(mtu_command2, shell=True, check=True)

    display_checkmark("\033[92mVxlan ip added successfully!\033[0m")
    file_path = "/usr/local/bin/bridge.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    vxlan_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    vxlan_pingv6_2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2001:db8:0:1::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_vxlan.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_vxlan.sh", 0o755)
    ping_vxlan_service()

    display_notification("\033[93mVxlan IP With Bridge Configured\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mIRAN Server \033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "|      2001:db8:0:1::2      |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# uninstall ipsec


def vxlan_uninstall():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mRegular Vxlan\033[0m")
    print("2. \033[92mRegular Vxlan + IPSEC\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_vxlan()
            break
        elif server_type == "2":
            remove_vxlansec()
            break
        elif server_type == "0":
            os.system("clear")
            remove_menu()
            break
        else:
            print("Invalid choice.")


def remote_ip_vx2():
    gen_path = "/usr/local/bin/bridge.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "sudo bridge fdb append" in line:
                parts = line.split()
                remote_ip = parts[-3]
                return remote_ip

    return None


def remote_ip_vx():
    gen_path = "/usr/local/bin/bridge.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "remote" in line:
                parts = line.split()
                remote_index = parts.index("remote")
                remote_ip = parts[remote_index + 1]
                remote_ip = remote_ip.strip('"')

                return remote_ip

    return None


def remove_vxlansec():
    os.system("clear")
    delete_cron1()
    delete_cron2()
    remote_ip = remote_ip_vx()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    remote_ip2 = remote_ip_vx2()

    if remote_ip2 is None:
        print("Unable to retrieve FDB remote IP")
    else:
        delufw(remote_ip2)
    delufw("30.0.0.1")
    delufw("30.0.0.2")
    delufw("2001:db8:0:1::2")
    delufw("2001:db8:0:1::1")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mVxlan + IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if (
            subprocess.call(
                "test -f /usr/local/bin/bridge.sh > /dev/null 2>&1", shell=True
            )
            == 0
        ):
            subprocess.run("rm /usr/local/bin/bridge.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /usr/local/bin/bridge.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_vxlan.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_vxlan_service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_vxlan_service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_vxlan_service.service > /dev/null 2>&1",
            shell=True,
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev vxlan down > /dev/null", shell=True)
        subprocess.run("ip link delete vxlan > /dev/null", shell=True)
        subprocess.run("ip link delete azumibr > /dev/null", shell=True)
        sleep(1)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_vxlan():
    os.system("clear")
    remote_ip = remote_ip_vx()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    remote_ip2 = remote_ip_vx2()

    if remote_ip2 is None:
        print("Unable to retrieve FDB remote IP")
    else:
        delufw(remote_ip2)
    delufw("30.0.0.1")
    delufw("30.0.0.2")
    delufw("2001:db8:0:1::2")
    delufw("2001:db8:0:1::1")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mVxlan\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if (
            subprocess.call(
                "test -f /usr/local/bin/bridge.sh > /dev/null 2>&1", shell=True
            )
            == 0
        ):
            subprocess.run("rm /usr/local/bin/bridge.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /usr/local/bin/bridge.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_vxlan.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_vxlan_service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_vxlan_service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_vxlan_service.service > /dev/null 2>&1",
            shell=True,
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev vxlan down > /dev/null", shell=True)
        subprocess.run("ip link delete vxlan > /dev/null", shell=True)
        subprocess.run("ip link delete azumibr > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def vxlan_mtu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mVxlan MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mRegular Vxlan\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlan_mtuz()
            break
        elif server_type == "0":
            os.system("clear")
            mtu_menu()
            break
        else:
            print("Invalid choice.")


def vxlan_mtuz():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mRegular Vxlan MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mP2P\033[0m")
    print("2. \033[93mVXLAN Bridge Setup with IP Pointing\033[0m")
    print("3. \033[97mFDB\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            vxlan_mtuz1()
            break
        elif server_type == "2":
            vxlan_mtuz2()
            break
        elif server_type == "3":
            vxlan_mtuz2()
            break
        elif server_type == "0":
            os.system("clear")
            mtu_menu()
            break
        else:
            print("Invalid choice.")


def vxlan_mtuz1():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mVxlan \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev vxlan mtu {mtu_value}\n"

    if os.path.exists("/usr/local/bin/bridge.sh"):
        with open("/usr/local/bin/bridge.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev vxlan mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/usr/local/bin/bridge.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def vxlan_mtuz2():
    mtu_value_vxlan = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mVxlan \033[93m]:\033[0m "
    )
    mtu_command_vxlan = f"ip link set dev vxlan mtu {mtu_value_vxlan}\n"

    mtu_value_bridge = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mBridge \033[93m]:\033[0m "
    )
    mtu_command_bridge = f"ip link set dev azumibr mtu {mtu_value_bridge}\n"

    if os.path.exists("/usr/local/bin/bridge.sh"):
        with open("/usr/local/bin/bridge.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_vxlan_exists = False
        mtu_bridge_exists = False
        for i in range(len(sh_contents)):
            if "link set dev vxlan mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command_vxlan
                mtu_vxlan_exists = True
            elif "link set dev azumibr mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command_bridge
                mtu_bridge_exists = True

        if not mtu_vxlan_exists:
            sh_contents.append(mtu_command_vxlan)
        if not mtu_bridge_exists:
            sh_contents.append(mtu_command_bridge)

        with open("/usr/local/bin/bridge.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU commands edited successfully\033[0m")
        subprocess.run(mtu_command_vxlan, shell=True)
        subprocess.run(mtu_command_bridge, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def delete_cron1():
    entries_to_delete = [
        "0 * * * * /bin/bash /etc/ipsec.sh",
        "0 */2 * * * /bin/bash /etc/ipsec.sh",
        "0 */3 * * * /bin/bash /etc/ipsec.sh",
        "0 */4 * * * /bin/bash /etc/ipsec.sh",
        "0 */5 * * * /bin/bash /etc/ipsec.sh",
        "0 */6 * * * /bin/bash /etc/ipsec.sh",
        "0 */7 * * * /bin/bash /etc/ipsec.sh",
        "0 */8 * * * /bin/bash /etc/ipsec.sh",
        "0 */9 * * * /bin/bash /etc/ipsec.sh",
        "0 */10 * * * /bin/bash /etc/ipsec.sh",
        "0 */11 * * * /bin/bash /etc/ipsec.sh",
        "0 */12 * * * /bin/bash /etc/ipsec.sh",
        "0 */13 * * * /bin/bash /etc/ipsec.sh",
        "0 */14 * * * /bin/bash /etc/ipsec.sh",
        "0 */15 * * * /bin/bash /etc/ipsec.sh",
        "0 */16 * * * /bin/bash /etc/ipsec.sh",
        "0 */17 * * * /bin/bash /etc/ipsec.sh",
        "0 */18 * * * /bin/bash /etc/ipsec.sh",
        "0 */19 * * * /bin/bash /etc/ipsec.sh",
        "0 */20 * * * /bin/bash /etc/ipsec.sh",
        "0 */21 * * * /bin/bash /etc/ipsec.sh",
        "0 */22 * * * /bin/bash /etc/ipsec.sh",
        "0 */23 * * * /bin/bash /etc/ipsec.sh",
    ]

    existing_crontab = ""
    try:
        existing_crontab = subprocess.check_output("crontab -l", shell=True).decode()
    except subprocess.CalledProcessError:

        return

    new_crontab = existing_crontab
    for entry in entries_to_delete:
        if entry in existing_crontab:
            new_crontab = new_crontab.replace(entry, "")

    if new_crontab != existing_crontab:
        subprocess.call(f"echo '{new_crontab}' | crontab -", shell=True)
        display_notification("\033[92mDeleting Previous Crons..\033[0m")


def delete_cron3():
    entries_to_delete = [
        "0 * * * * /bin/bash /etc/ipsec2.sh",
        "0 */2 * * * /bin/bash /etc/ipsec2.sh",
        "0 */3 * * * /bin/bash /etc/ipsec2.sh",
        "0 */4 * * * /bin/bash /etc/ipsec2.sh",
        "0 */5 * * * /bin/bash /etc/ipsec2.sh",
        "0 */6 * * * /bin/bash /etc/ipsec2.sh",
        "0 */7 * * * /bin/bash /etc/ipsec2.sh",
        "0 */8 * * * /bin/bash /etc/ipsec2.sh",
        "0 */9 * * * /bin/bash /etc/ipsec2.sh",
        "0 */10 * * * /bin/bash /etc/ipsec2.sh",
        "0 */11 * * * /bin/bash /etc/ipsec2.sh",
        "0 */12 * * * /bin/bash /etc/ipsec2.sh",
        "0 */13 * * * /bin/bash /etc/ipsec2.sh",
        "0 */14 * * * /bin/bash /etc/ipsec2.sh",
        "0 */15 * * * /bin/bash /etc/ipsec2.sh",
        "0 */16 * * * /bin/bash /etc/ipsec2.sh",
        "0 */17 * * * /bin/bash /etc/ipsec2.sh",
        "0 */18 * * * /bin/bash /etc/ipsec2.sh",
        "0 */19 * * * /bin/bash /etc/ipsec2.sh",
        "0 */20 * * * /bin/bash /etc/ipsec2.sh",
        "0 */21 * * * /bin/bash /etc/ipsec2.sh",
        "0 */22 * * * /bin/bash /etc/ipsec2.sh",
        "0 */23 * * * /bin/bash /etc/ipsec2.sh",
    ]

    existing_crontab = ""
    try:
        existing_crontab = subprocess.check_output("crontab -l", shell=True).decode()
    except subprocess.CalledProcessError:

        return

    new_crontab = existing_crontab
    for entry in entries_to_delete:
        if entry in existing_crontab:
            new_crontab = new_crontab.replace(entry, "")

    if new_crontab != existing_crontab:
        subprocess.call(f"echo '{new_crontab}' | crontab -", shell=True)
        display_notification("\033[92mDeleting Previous Crons..\033[0m")


def delete_cron2():
    entries_to_delete = [
        "*/1 * * * * /bin/bash /etc/ipsec.sh",
        "*/2 * * * * /bin/bash /etc/ipsec.sh",
        "*/3 * * * * /bin/bash /etc/ipsec.sh",
        "*/4 * * * * /bin/bash /etc/ipsec.sh",
        "*/5 * * * * /bin/bash /etc/ipsec.sh",
        "*/6 * * * * /bin/bash /etc/ipsec.sh",
        "*/7 * * * * /bin/bash /etc/ipsec.sh",
        "*/8 * * * * /bin/bash /etc/ipsec.sh",
        "*/9 * * * * /bin/bash /etc/ipsec.sh",
        "*/10 * * * * /bin/bash /etc/ipsec.sh",
        "*/11 * * * * /bin/bash /etc/ipsec.sh",
        "*/12 * * * * /bin/bash /etc/ipsec.sh",
        "*/13 * * * * /bin/bash /etc/ipsec.sh",
        "*/14 * * * * /bin/bash /etc/ipsec.sh",
        "*/15 * * * * /bin/bash /etc/ipsec.sh",
        "*/16 * * * * /bin/bash /etc/ipsec.sh",
        "*/17 * * * * /bin/bash /etc/ipsec.sh",
        "*/18 * * * * /bin/bash /etc/ipsec.sh",
        "*/19 * * * * /bin/bash /etc/ipsec.sh",
        "*/20 * * * * /bin/bash /etc/ipsec.sh",
        "*/21 * * * * /bin/bash /etc/ipsec.sh",
        "*/22 * * * * /bin/bash /etc/ipsec.sh",
        "*/23 * * * * /bin/bash /etc/ipsec.sh",
        "*/24 * * * * /bin/bash /etc/ipsec.sh",
        "*/25 * * * * /bin/bash /etc/ipsec.sh",
        "*/26 * * * * /bin/bash /etc/ipsec.sh",
        "*/27 * * * * /bin/bash /etc/ipsec.sh",
        "*/28 * * * * /bin/bash /etc/ipsec.sh",
        "*/29 * * * * /bin/bash /etc/ipsec.sh",
        "*/30 * * * * /bin/bash /etc/ipsec.sh",
        "*/31 * * * * /bin/bash /etc/ipsec.sh",
        "*/32 * * * * /bin/bash /etc/ipsec.sh",
        "*/33 * * * * /bin/bash /etc/ipsec.sh",
        "*/34 * * * * /bin/bash /etc/ipsec.sh",
        "*/35 * * * * /bin/bash /etc/ipsec.sh",
        "*/36 * * * * /bin/bash /etc/ipsec.sh",
        "*/37 * * * * /bin/bash /etc/ipsec.sh",
        "*/38 * * * * /bin/bash /etc/ipsec.sh",
        "*/39 * * * * /bin/bash /etc/ipsec.sh",
        "*/40 * * * * /bin/bash /etc/ipsec.sh",
        "*/41 * * * * /bin/bash /etc/ipsec.sh",
        "*/42 * * * * /bin/bash /etc/ipsec.sh",
        "*/43 * * * * /bin/bash /etc/ipsec.sh",
        "*/44 * * * * /bin/bash /etc/ipsec.sh",
        "*/45 * * * * /bin/bash /etc/ipsec.sh",
        "*/46 * * * * /bin/bash /etc/ipsec.sh",
        "*/47 * * * * /bin/bash /etc/ipsec.sh",
        "*/48 * * * * /bin/bash /etc/ipsec.sh",
        "*/49 * * * * /bin/bash /etc/ipsec.sh",
        "*/50 * * * * /bin/bash /etc/ipsec.sh",
        "*/51 * * * * /bin/bash /etc/ipsec.sh",
        "*/52 * * * * /bin/bash /etc/ipsec.sh",
        "*/53 * * * * /bin/bash /etc/ipsec.sh",
        "*/54 * * * * /bin/bash /etc/ipsec.sh",
        "*/55 * * * * /bin/bash /etc/ipsec.sh",
        "*/56 * * * * /bin/bash /etc/ipsec.sh",
        "*/57 * * * * /bin/bash /etc/ipsec.sh",
        "*/58 * * * * /bin/bash /etc/ipsec.sh",
        "*/59 * * * * /bin/bash /etc/ipsec.sh",
    ]

    existing_crontab = ""
    try:
        existing_crontab = subprocess.check_output("crontab -l", shell=True).decode()
    except subprocess.CalledProcessError:

        return

    new_crontab = existing_crontab
    for entry in entries_to_delete:
        if entry in existing_crontab:
            new_crontab = new_crontab.replace(entry, "")

    if new_crontab != existing_crontab:
        subprocess.call(f"echo '{new_crontab}' | crontab -", shell=True)
        display_notification("\033[92mDeleting Previous Crons..\033[0m")


def delete_cron4():
    entries_to_delete = [
        "*/1 * * * * /bin/bash /etc/ipsec2.sh",
        "*/2 * * * * /bin/bash /etc/ipsec2.sh",
        "*/3 * * * * /bin/bash /etc/ipsec2.sh",
        "*/4 * * * * /bin/bash /etc/ipsec2.sh",
        "*/5 * * * * /bin/bash /etc/ipsec2.sh",
        "*/6 * * * * /bin/bash /etc/ipsec2.sh",
        "*/7 * * * * /bin/bash /etc/ipsec2.sh",
        "*/8 * * * * /bin/bash /etc/ipsec2.sh",
        "*/9 * * * * /bin/bash /etc/ipsec2.sh",
        "*/10 * * * * /bin/bash /etc/ipsec2.sh",
        "*/11 * * * * /bin/bash /etc/ipsec2.sh",
        "*/12 * * * * /bin/bash /etc/ipsec2.sh",
        "*/13 * * * * /bin/bash /etc/ipsec2.sh",
        "*/14 * * * * /bin/bash /etc/ipsec2.sh",
        "*/15 * * * * /bin/bash /etc/ipsec2.sh",
        "*/16 * * * * /bin/bash /etc/ipsec2.sh",
        "*/17 * * * * /bin/bash /etc/ipsec2.sh",
        "*/18 * * * * /bin/bash /etc/ipsec2.sh",
        "*/19 * * * * /bin/bash /etc/ipsec2.sh",
        "*/20 * * * * /bin/bash /etc/ipsec2.sh",
        "*/21 * * * * /bin/bash /etc/ipsec2.sh",
        "*/22 * * * * /bin/bash /etc/ipsec2.sh",
        "*/23 * * * * /bin/bash /etc/ipsec2.sh",
        "*/24 * * * * /bin/bash /etc/ipsec2.sh",
        "*/25 * * * * /bin/bash /etc/ipsec2.sh",
        "*/26 * * * * /bin/bash /etc/ipsec2.sh",
        "*/27 * * * * /bin/bash /etc/ipsec2.sh",
        "*/28 * * * * /bin/bash /etc/ipsec2.sh",
        "*/29 * * * * /bin/bash /etc/ipsec2.sh",
        "*/30 * * * * /bin/bash /etc/ipsec2.sh",
        "*/31 * * * * /bin/bash /etc/ipsec2.sh",
        "*/32 * * * * /bin/bash /etc/ipsec2.sh",
        "*/33 * * * * /bin/bash /etc/ipsec2.sh",
        "*/34 * * * * /bin/bash /etc/ipsec2.sh",
        "*/35 * * * * /bin/bash /etc/ipsec2.sh",
        "*/36 * * * * /bin/bash /etc/ipsec2.sh",
        "*/37 * * * * /bin/bash /etc/ipsec2.sh",
        "*/38 * * * * /bin/bash /etc/ipsec2.sh",
        "*/39 * * * * /bin/bash /etc/ipsec2.sh",
        "*/40 * * * * /bin/bash /etc/ipsec2.sh",
        "*/41 * * * * /bin/bash /etc/ipsec2.sh",
        "*/42 * * * * /bin/bash /etc/ipsec2.sh",
        "*/43 * * * * /bin/bash /etc/ipsec2.sh",
        "*/44 * * * * /bin/bash /etc/ipsec2.sh",
        "*/45 * * * * /bin/bash /etc/ipsec2.sh",
        "*/46 * * * * /bin/bash /etc/ipsec2.sh",
        "*/47 * * * * /bin/bash /etc/ipsec2.sh",
        "*/48 * * * * /bin/bash /etc/ipsec2.sh",
        "*/49 * * * * /bin/bash /etc/ipsec2.sh",
        "*/50 * * * * /bin/bash /etc/ipsec2.sh",
        "*/51 * * * * /bin/bash /etc/ipsec2.sh",
        "*/52 * * * * /bin/bash /etc/ipsec2.sh",
        "*/53 * * * * /bin/bash /etc/ipsec2.sh",
        "*/54 * * * * /bin/bash /etc/ipsec2.sh",
        "*/55 * * * * /bin/bash /etc/ipsec2.sh",
        "*/56 * * * * /bin/bash /etc/ipsec2.sh",
        "*/57 * * * * /bin/bash /etc/ipsec2.sh",
        "*/58 * * * * /bin/bash /etc/ipsec2.sh",
        "*/59 * * * * /bin/bash /etc/ipsec2.sh",
    ]

    existing_crontab = ""
    try:
        existing_crontab = subprocess.check_output("crontab -l", shell=True).decode()
    except subprocess.CalledProcessError:

        return

    new_crontab = existing_crontab
    for entry in entries_to_delete:
        if entry in existing_crontab:
            new_crontab = new_crontab.replace(entry, "")

    if new_crontab != existing_crontab:
        subprocess.call(f"echo '{new_crontab}' | crontab -", shell=True)
        display_notification("\033[92mDeleting Previous Crons..\033[0m")


def reset_hour():
    delete_cron1()
    delete_cron2()
    hours = int(
        input("\033[93mEnter the \033[92mReset Timer\033[93m [in hours]:\033[0m ")
    )

    if hours == 1:
        cron_entry = "0 * * * * /bin/bash /etc/ipsec.sh"
    else:
        cron_entry = f"0 */{hours} * * * /bin/bash /etc/ipsec.sh"

    try:
        process = subprocess.run(
            "crontab -l", shell=True, capture_output=True, text=True
        )
        existing_crontab = process.stdout

        if existing_crontab.strip() != "":
            new_crontab = f"{existing_crontab.rstrip()}\n{cron_entry}"
        else:
            new_crontab = cron_entry

        new_crontab += "\n"

        process = subprocess.run(
            "crontab -", shell=True, input=new_crontab, text=True, capture_output=True
        )

        if process.returncode == 0:
            print("\033[92mCron entry added successfully!\033[0m")
        else:
            print(f"Failed to add cron entry. Error: {process.stderr}")
    except Exception as e:
        print(f"Error: {e}")


def reset2_hour():
    delete_cron3()
    delete_cron4()
    hours = int(
        input("\033[93mEnter the \033[92mReset Timer\033[93m [in hours]:\033[0m ")
    )

    if hours == 1:
        cron_entry = "0 * * * * /bin/bash /etc/ipsec2.sh"
    else:
        cron_entry = f"0 */{hours} * * * /bin/bash /etc/ipsec2.sh"

    try:
        process = subprocess.run(
            "crontab -l", shell=True, capture_output=True, text=True
        )
        existing_crontab = process.stdout

        if existing_crontab.strip() != "":
            new_crontab = f"{existing_crontab.rstrip()}\n{cron_entry}"
        else:
            new_crontab = cron_entry

        new_crontab += "\n"

        process = subprocess.run(
            "crontab -", shell=True, input=new_crontab, text=True, capture_output=True
        )

        if process.returncode == 0:
            print("\033[92mCron entry added successfully!\033[0m")
        else:
            print(f"Failed to add cron entry. Error: {process.stderr}")
    except Exception as e:
        print(f"Error: {e}")


def reset_minutes():
    delete_cron1()
    delete_cron2()
    minutes = int(
        input("\033[93mEnter the \033[92mReset Timer\033[93m [in minutes]:\033[0m ")
    )

    cron_entry = f"*/{minutes} * * * * /bin/bash /etc/ipsec.sh"

    try:
        process = subprocess.run(
            "crontab -l", shell=True, capture_output=True, text=True
        )
        existing_crontab = process.stdout

        if existing_crontab.strip() != "":
            new_crontab = f"{existing_crontab.rstrip()}\n{cron_entry}"
        else:
            new_crontab = cron_entry

        new_crontab += "\n"

        process = subprocess.run(
            "crontab -", shell=True, input=new_crontab, text=True, capture_output=True
        )

        if process.returncode == 0:
            print("\033[92mCron entry added successfully!\033[0m")
        else:
            print(f"Failed to add cron entry. Error: {process.stderr}")
    except Exception as e:
        print(f"Error: {e}")


def reset2_minutes():
    delete_cron3()
    delete_cron4()
    minutes = int(
        input("\033[93mEnter the \033[92mReset Timer\033[93m [in minutes]:\033[0m ")
    )

    cron_entry = f"*/{minutes} * * * * /bin/bash /etc/ipsec2.sh"

    try:
        process = subprocess.run(
            "crontab -l", shell=True, capture_output=True, text=True
        )
        existing_crontab = process.stdout

        if existing_crontab.strip() != "":
            new_crontab = f"{existing_crontab.rstrip()}\n{cron_entry}"
        else:
            new_crontab = cron_entry

        new_crontab += "\n"

        process = subprocess.run(
            "crontab -", shell=True, input=new_crontab, text=True, capture_output=True
        )

        if process.returncode == 0:
            print("\033[92mCron entry added successfully!\033[0m")
        else:
            print(f"Failed to add cron entry. Error: {process.stderr}")
    except Exception as e:
        print(f"Error: {e}")


def enable_reset_ipsec():
    ipsec_service_remove()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mIPSEC \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_ipsec(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_ipsec(interval):
    service_name = "ipsecreset.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipsec.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipsec_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipsec_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipsec_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
sudo ipsec stop
systemctl restart strong-azumi1 
systemctl restart strongswan-starter 
systemctl restart strongswan
sudo journalctl --vacuum-size=1M --unit=strongswan.service
sudo journalctl --vacuum-size=1M --unit=strongswan-starter.service
"""

    with open("/etc/reset_ipsec.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipsec.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_ipsec_single(interval):
    service_name = "ipsecreset.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_ipsec.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/ipsec_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/ipsec_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/ipsec_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
sudo ipsec stop
systemctl restart strongswan-starter 
systemctl restart strongswan
sudo journalctl --vacuum-size=1M --unit=strongswan.service
sudo journalctl --vacuum-size=1M --unit=strongswan-starter.service
"""

    with open("/etc/reset_ipsec.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_ipsec.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset2_minutes_forced():
    delete_cron3()
    delete_cron4()
    ipsec2_sh()
    cron_entry = f"*/2 * * * * /bin/bash /etc/ipsec2.sh"

    try:
        process = subprocess.run(
            "crontab -l", shell=True, capture_output=True, text=True
        )
        existing_crontab = process.stdout

        if existing_crontab.strip() != "":
            new_crontab = f"{existing_crontab.rstrip()}\n{cron_entry}"
        else:
            new_crontab = cron_entry

        new_crontab += "\n"

        process = subprocess.run(
            "crontab -", shell=True, input=new_crontab, text=True, capture_output=True
        )

        if process.returncode == 0:
            print("\033[92mCron entry added successfully!\033[0m")
        else:
            print(f"Failed to add cron entry. Error: {process.stderr}")
    except Exception as e:
        print(f"Error: {e}")


def choose_reset():
    ipsec_service_remove()
    delete_cron1()
    delete_cron1()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mIPSEC \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_ipsec_single(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def ipsec_service_remove():

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving stuff...\033[0m")

        commands = [
            "rm /etc/ipsec2.sh",
            "systemctl disable ipsecreset.service",
            "systemctl stop ipsecreset.service",
            "sudo rm /etc/systemd/system/ipsecreset.service",
            "sudo rm /etc/reset_ipsec.sh" "sudo rm /usr/local/bin/ipsec_daemon.sh",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def choose_reset2():
    ipsec_service_remove()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mIPSEC \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_ipsec(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


## simpe ip4
def ip4_spn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[93m+ IPV4 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            simple_spnkh()
            break
        elif server_type == "2":
            simple_spnir()
            break
        elif server_type == "3":
            clear()
            espn_menu()
            break
        else:
            print("Invalid choice.")


def simple_spnkh():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_sim_kharej()


def spn_sim_kharej():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ip4_simpk1()
            break
        elif server_type == "2":
            ip4_simk2()
            break
        else:
            print("Invalid choice.")


def ip4_simpk1():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def ip4_simk2():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def simple_spnir():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_sim_iran()


def spn_sim_iran():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ip4_simpi1()
            break
        elif server_type == "2":
            ip4_simpi2()
            break
        else:
            print("Invalid choice.")


def ip4_simpi1():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def ip4_simpi2():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## simple ip6
def ip6_spn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[93m+ Native  \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            simple_ip6_n()
            break
        elif server_type == "2":
            simple_ip6i_n()
            break
        elif server_type == "3":
            clear()
            espn_menu()
            break
        else:
            print("Invalid choice.")


def simple_ip6_n():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip6_simple1_n()


def ip6_simple1_n():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ip6_simk1_n()
            break
        elif server_type == "2":
            ip6_simk2_n()
            break
        else:
            print("Invalid choice.")


def ip6_simk1_n():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def ip6_simk2_n():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def simple_ip6i_n():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip6_simple2_n()


def ip6_simple2_n():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ip6_simpi1_n()
            break
        elif server_type == "2":
            ip6_simpi2_n()
            break
        else:
            print("Invalid choice.")


def ip6_simpi1_n():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def ip6_simpi2_n():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## simple ipsec
def simple_ipsec_mn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[93m+ \033[92mIPsec Menu \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mNative + Erspan\033[0m")
    print("2. \033[93mIPV4 + Erspan\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            simple_ipsec_n()
            break
        elif server_type == "2":
            simple_ipsec()
            break
        elif server_type == "3":
            clear()
            ipsec_mnu()
            break
        else:
            print("Invalid choice.")


def simple_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[93m+ IPV4 + \033[92mIPsec \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            simple_ipseck()
            break
        elif server_type == "2":
            simple_ipseci()
            break
        elif server_type == "3":
            clear()
            simple_ipsec_mn()
            break
        else:
            print("Invalid choice.")


def simple_ipseck():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_simple1()


def espan_simple1():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_simpk1()
            break
        elif server_type == "2":
            espan_simpk2()
            break
        else:
            print("Invalid choice.")


def config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simk2(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simi2(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def espan_simpk1():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def espan_simpk2():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simk2(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def simple_ipseci():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_simple2()


def espan_simple2():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_simpi1()
            break
        elif server_type == "2":
            espan_simpi2()
            break
        else:
            print("Invalid choice.")


def espan_simpi1():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def espan_simpi2():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simi2(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# native erspan
def simple_ipsec_n():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan \033[93m+ Native + \033[92mIPsec \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            simple_ipseck_n()
            break
        elif server_type == "2":
            simple_ipseci_n()
            break
        elif server_type == "3":
            clear()
            simple_ipsec_mn()
            break
        else:
            print("Invalid choice.")


def simple_ipseck_n():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_simple1_n()


def espan_simple1_n():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_simk1_n()
            break
        elif server_type == "2":
            espan_simk2_n()
            break
        else:
            print("Invalid choice.")


def config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simk2(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simi2(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def espan_simk1_n():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def espan_simk2_n():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simk2(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def simple_ipseci_n():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_simple2_n()


def espan_simple2_n():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_simpi1_n()
            break
        elif server_type == "2":
            espan_simpi2_n()
            break
        else:
            print("Invalid choice.")


def espan_simpi1_n():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def espan_simpi2_n():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simi2(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            local_ip,
            "remote",
            remote_ip,
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local {local_ip} remote {remote_ip} seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## gre6tap erspan


def gre6tap_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig6' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharej():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    gre6_cronjob()


def gre6tap_kharejsec():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6tap_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    gre6_cronjob()


def kharej_gretap6_menu():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::2/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejsec()  # sec
    sleep(1)


def gretap6_iran():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    gre6_cronjob()


def gretap6_iransec():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gretap6_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    gre6_cronjob()


def gretap6_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig6' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gretap6_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gretap6_menu():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::1/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_pingg()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    gretap6_iransec()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def espn_gretap():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mGRE6tap \033[93m+ \033[96mErspan\033[93m + \033[91mIPsec\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + GRE6tap | IPsec + IPV4 \033[0m")
    print("2. \033[93mErspan + GRE6tap | IPsec + Native \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espn_gretap_ipsec()
            break
        elif server_type == "2":
            espn_gretap_ipsec2()
            break
        elif server_type == "0":
            clear()
            ipsec_mnu()
            break
        else:
            print("Invalid choice.")


def espn_gretap_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mErspan \033[93m+ \033[96mGre6tap \033[93m+ \033[92mIPV4 \033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_gretap_espn()
            break
        elif server_type == "2":
            iran_gretap_espn()
            break
        elif server_type == "3":
            clear()
            espn_gretap()
            break
        else:
            print("Invalid choice.")


def kharej_gretap_espn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_ipgre1()


def espan_ipgre1():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_ipk_gre1()
            break
        elif server_type == "2":
            espan_ipk_gre2()
            break
        else:
            print("Invalid choice.")


def espan_ipk_gre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    kharej_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gre62(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def espan_ipk_gre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    kharej_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gre6(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def iran_gretap_espn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_ipgre2()


def espan_ipgre2():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_ipi_gre1()
            break
        elif server_type == "2":
            espan_ipi_gre2()
            break
        else:
            print("Invalid choice.")


def espan_ipi_gre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    iran_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gre62(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def espan_ipi_gre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    iran_gretap6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gre6(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## gre6tap native
def espn_gretap_ipsec2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mErspan \033[93m+ \033[96mGre6tap \033[93m+ \033[92mNative \033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejna_gretap_espn()
            break
        elif server_type == "2":
            iranna_gretap_espn()
            break
        elif server_type == "3":
            clear()
            espn_gretap()
            break
        else:
            print("Invalid choice.")


def kharejna_gretap_espn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_ipgrena1()


def espan_ipgrena1():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_ipk_grena1()
            break
        elif server_type == "2":
            espan_ipk_grena2()
            break
        else:
            print("Invalid choice.")


# kharej prequisite
def gre6tapna_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tapna_kharej():
    global local_ip, remote_ip
    gre6tapna_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    gre6_cronjob()


def espan_ipk_grena1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")

    gre6tapna_kharej()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gre62(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def espan_ipk_grena2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")

    gre6tapna_kharej()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gre6(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## iran prequisite
def gretap6na_iran():
    global local_ip, remote_ip
    gretap6na_iran_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    gre6_cronjob()


def gretap6na_iran_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link add name azumig6 type ip6gretap local {local_ip} remote {remote_ip}' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iranna_gretap_espn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_ipgrena2()


def espan_ipgrena2():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_ipi_grena1()
            break
        elif server_type == "2":
            espan_ipi_grena2()
            break
        else:
            print("Invalid choice.")


def espan_ipi_grena1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")

    gretap6na_iran()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gre62(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def espan_ipi_grena2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")

    gretap6na_iran()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gre6(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## gre6 erspan
def espn_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mGRE6 \033[93m+ \033[96mErspan\033[93m + \033[91mIPsec\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + GRE6 | IPsec + IPV4 \033[0m")
    print("2. \033[93mErspan + GRE6 | IPsec + Native \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espn_ipsec()
            break
        elif server_type == "2":
            spn_ip()
            break
        elif server_type == "0":
            clear()
            ipsec_mnu()
            break
        else:
            print("Invalid choice.")


# native gre spn
def spn_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mERSPAN +  \033[96mNative \033[93m+\033[92m Gre6 \033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn_ipger()
            break
        elif server_type == "2":
            spn_ipgeri()
            break
        elif server_type == "3":
            clear()
            espn_sec()
            break
        else:
            print("Invalid choice.")


def spn_ipger():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan2_ipk_ngre1()
            break
        elif server_type == "2":
            espan2_ipk_ngre2()
            break
        else:
            print("Invalid choice.")


def gree6rn_kharej1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def gree6rn_kharej1():
    gree6rn_kharej1_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    gre6_cronjob()


def config_strongswank_gren(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongswank_gren4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea

conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongswani_gren(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea

conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongswani_gren4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea

conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def espan2_ipk_ngre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")

    gree6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gren4(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def espan2_ipk_ngre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")

    gree6rn_kharej1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gren(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# iran


def gree6rn_iran1_tunnel():
    global local_ip, remote_ip
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def gree6rn_iran1():
    gree6rn_iran1_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    gre6_cronjob()


def spn_ipgeri():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan2_ipi_ngre1()
            break
        elif server_type == "2":
            espan2_ipi_ngre2()
            break
        else:
            print("Invalid choice.")


def espan2_ipi_ngre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")

    gree6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gren4(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def espan2_ipi_ngre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")

    gree6rn_iran1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gren(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def espan4_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "2001:db8::1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def espan3_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "2001:db8::2"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def espan_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "66.200.2.1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def espan2_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "66.200.1.1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def ping_gengre_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_espan.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_espan.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_espan.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_espan.service"])


def espan_job():
    file_path = "/etc/spn.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def permissionz(num_servers):
    print("Setting permissions for config files...")
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec{i}.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    print("Setting permissions was successful.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")


def permissions():
    print("Setting permissions for config files...")
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    print("Setting permissions was successful.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")


def permissions1():
    print("Setting permissions for config files...")
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "chmod", "600", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    print("Setting permissions was successful.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")


def install_strongswan():

    subprocess.run(["sudo", "apt", "install", "strongswan", "-y"])
    print("IPSEC Installation complete.")


def config_strongswan(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongswank_gre62(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea

 
conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongswank_gre6(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea

conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongswani_gre6(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea

conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongswani_gre62(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea

conn erspan
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def espn_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mErspan \033[93m+ \033[96mGRE6 \033[93m+ \033[92mIPV4 \033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_espn_menu()
            break
        elif server_type == "2":
            iran_espn_menu()
            break
        elif server_type == "3":
            clear()
            ipsec_mnu()
            break
        else:
            print("Invalid choice.")


def kharej_espn_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan_ipvers()


def espan_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_ipk_version1()
            break
        elif server_type == "2":
            espan_ipk_version2()
            break
        else:
            print("Invalid choice.")


def espan_ipk_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gre62(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def espan_ipk_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswank_gre6(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::1",
            "remote",
            "2002:831a::2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::1 remote 2002:831a::2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def iran_espn_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    espan2_ipvers()


def espan2_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espan_ipi_version1()
            break
        elif server_type == "2":
            espan_ipi_version2()
            break
        else:
            print("Invalid choice.")


def espan_ipi_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gre62(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def espan_ipi_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongswani_gre6(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "ip6erspan",
            "local",
            "2002:831a::2",
            "remote",
            "2002:831a::1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type ip6erspan local 2002:831a::2 remote 2002:831a::1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumiespn\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def genz_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGeneve\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve UDP \033[0m")
    print(
        "2. \033[93mGeneve UDP \033[93m+ \033[92mNative \033[93m| \033[92mTunnelbroker \033[0m"
    )
    print("3. \033[96mGeneve UDP + GRE6 \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_ip()
            break
        elif server_type == "2":
            gen2_ip()
            break
        elif server_type == "3":
            genf_ip()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def gen_icmp_install():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGen + ICMP\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_ipicmp()
            break
        elif server_type == "2":
            gen_ipicmpi()
            break
        elif server_type == "0":
            clear()
            genz_ip()
            break
        else:
            print("Invalid choice.")


def remove2_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Multiple Servers Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mUninstall IP6IP6\033[0m")
    print("2. \033[96mUninstall IP6IP6 + IPSec\033[0m")
    print("3. \033[93mUninstall 6to4\033[0m")
    print("4. \033[96mUninstall 6to4 + IPsec\033[0m")
    print("5. \033[93mUninstall anycast\033[0m")
    print("6. \033[92mUninstall Gre6\033[0m")
    print("7. \033[96mUninstall Gre6 + IPSec\033[0m")
    print("8. \033[93mUninstall Gre6tap\033[0m")
    print("9. \033[92mUninstall Geneve \033[93m[IPSec included]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            rmv_ipip6()
            break
        elif server_type == "2":
            rmv_ipip6sec()
            break
        elif server_type == "3":
            rmv_private()
            break
        elif server_type == "4":
            rmv_private_sec()
            break
        elif server_type == "5":
            remove_6to41()
            break
        elif server_type == "6":
            rmv_gre6()
            break
        elif server_type == "7":
            rmv_gre6_ipsec()
            break
        elif server_type == "8":
            rmv_gre6tap()
            break
        elif server_type == "9":
            rmv_gen_multi()
            break
        elif server_type == "0":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


# ip6ip6 + IPsec remove menu
def rmv_ipip6sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 + IPSec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[5] | IRAN[1] + \033[96mIPSEC\033[0m")
    print("2. \033[93mKharej[1] | IRAN[5] + \033[96mIPSEC\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_ipiptap6_sec()
            break
        elif server_type == "2":
            ir_ipiptap6_sec()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def kh_ipiptap6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 + IPSec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1] + IPsec\033[0m")
    print("2. \033[93mKharej[2] + IPsec\033[0m")
    print("3. \033[92mKharej[3] + IPsec\033[0m")
    print("4. \033[93mKharej[4] + IPsec\033[0m")
    print("5. \033[92mKharej[5] + IPsec\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN + IPsec \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61_sec()
            break
        elif server_type == "2":
            remove_ipip62_sec()
            break
        elif server_type == "3":
            remove_ipip63_sec()
            break
        elif server_type == "4":
            remove_ipip64_sec()
            break
        elif server_type == "5":
            remove_ipip65_sec()
            break
        elif server_type == "6":
            rmv3_ipiptap_sec()
            break
        elif server_type == "0":
            clear()
            rmv_ipip6sec()
            break
        else:
            print("Invalid choice.")


def rmv3_ipiptap_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_ipip6{}_sec".format(i)
        globals()[menu_name]()


def ir_ipiptap6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 + IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1] + IPsec\033[0m")
    print("2. \033[93mIRAN[2] + IPsec\033[0m")
    print("3. \033[92mIRAN[3] + IPsec\033[0m")
    print("4. \033[93mIRAN[4] + IPsec\033[0m")
    print("5. \033[92mIRAN[5] + IPsec\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej + IPsec \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61_sec()
            break
        elif server_type == "2":
            remove_ipip62_sec()
            break
        elif server_type == "3":
            remove_ipip63_sec()
            break
        elif server_type == "4":
            remove_ipip64_sec()
            break
        elif server_type == "5":
            remove_ipip65_sec()
            break
        elif server_type == "6":
            rmv4_ipiptap_sec()
            break
        elif server_type == "0":
            clear()
            rmv_ipip6sec()
            break
        else:
            print("Invalid choice.")


def rmv4_ipiptap_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_ipip6{}_sec".format(i)
        globals()[menu_name]()


def remove_ipip61_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mIPIP6 + IPSec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip1.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip1.sh", shell=True)
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip1.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip1.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip1.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip1.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip1 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip62_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mIPIP6 + IPSec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip2.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip2.sh", shell=True)
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip2.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip2.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip2.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip2.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip2.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip2 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip63_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mIPIP6 + IPSec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip3.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip3.sh", shell=True)
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip3.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)
        subprocess.run("sudo rm /etc/ping_ip3.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_ip3.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip3.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip3.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip3 > /dev/null", shell=True)
        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip64_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mIPIP6 + IPSec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip4.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip4.sh", shell=True)
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip4.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)
        subprocess.run("sudo rm /etc/ping_ip4.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_ip4.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip4.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip4.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip4 > /dev/null", shell=True)
        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip65_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mIPIP6 + IPSec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip5.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip5.sh", shell=True)
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip5.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)
        subprocess.run("sudo rm /etc/ping_ip5.sh", shell=True)
        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_ip5.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip5.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip5.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip5 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def rmv_ipip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [10]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_ipip6()
            break
        elif server_type == "2":
            ir_ipip6()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def kh_ipip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            break
        elif server_type == "2":
            remove_ipip62()
            break
        elif server_type == "3":
            remove_ipip63()
            break
        elif server_type == "4":
            remove_ipip64()
            break
        elif server_type == "5":
            remove_ipip65()
            break
        elif server_type == "6":
            remove_ipip66()
            break
        elif server_type == "7":
            remove_ipip67()
            break
        elif server_type == "8":
            remove_ipip68()
            break
        elif server_type == "9":
            remove_ipip69()
            break
        elif server_type == "10":
            remove_ipip610()
            break
        elif server_type == "11":
            rmv1_q()
            break
        elif server_type == "0":
            clear()
            rmv_ipip6()
            break
        else:
            print("Invalid choice.")


def rmv1_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_ipip6{}".format(i)
        globals()[menu_name]()


def ir_ipip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 [10]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[92mIRAN[6]\033[0m")
    print("7. \033[92mIRAN[7]\033[0m")
    print("8. \033[93mIRAN[8]\033[0m")
    print("9. \033[92mIRAN[9]\033[0m")
    print("10.\033[92mIRAN[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            break
        elif server_type == "2":
            remove_ipip62()
            break
        elif server_type == "3":
            remove_ipip63()
            break
        elif server_type == "4":
            remove_ipip64()
            break
        elif server_type == "5":
            remove_ipip65()
            break
        elif server_type == "6":
            remove_ipip66()
            break
        elif server_type == "7":
            remove_ipip67()
            break
        elif server_type == "8":
            remove_ipip68()
            break
        elif server_type == "9":
            remove_ipip69()
            break
        elif server_type == "10":
            remove_ipip610()
            break
        elif server_type == "11":
            rmv2_q()
            break
        elif server_type == "0":
            clear()
            rmv_ipip6()
            break
        else:
            print("Invalid choice.")


def rmv2_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_ipip6{}".format(i)
        globals()[menu_name]()


def remove_ipip61():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip1.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip1.sh", shell=True)
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip1.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip1.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip1.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip1.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip1 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip62():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip2.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip2.sh", shell=True)
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip2.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip2.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip2.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip2.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip2.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip2 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip63():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip3.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip3.sh", shell=True)
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip3.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip3.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip3.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip3.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip3.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip3 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip64():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip4.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip4.sh", shell=True)
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip4.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip4.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip4.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip4.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip4.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip4 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip65():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip5.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip5.sh", shell=True)
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip5.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip5.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip5.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip5.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip5.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip5 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip66():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip6.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip6.sh", shell=True)
        if subprocess.call("test -f /etc/private6.sh", shell=True) == 0:
            subprocess.run("rm /etc/private6.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip6.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private6.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v66.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip6.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v66.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v66.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v66.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip6.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip6.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip6.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip6 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi6 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip67():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip7.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip7.sh", shell=True)
        if subprocess.call("test -f /etc/private7.sh", shell=True) == 0:
            subprocess.run("rm /etc/private7.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip7.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private7.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v67.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip7.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v67.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v67.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v67.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip7.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip7.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip7.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip7 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip7 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi7 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi7 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip68():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip8.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip8.sh", shell=True)
        if subprocess.call("test -f /etc/private8.sh", shell=True) == 0:
            subprocess.run("rm /etc/private8.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip8.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private8.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v68.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip8.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v68.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v68.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v68.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip8.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip8.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip8.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip8 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip8 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi8 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi8 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip69():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip9.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip9.sh", shell=True)
        if subprocess.call("test -f /etc/private9.sh", shell=True) == 0:
            subprocess.run("rm /etc/private9.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip9.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private9.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v69.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip9.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v69.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v69.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v69.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip9.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip9.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip9.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip9 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip9 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi9 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi9 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_ipip610():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip10.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip10.sh", shell=True)
        if subprocess.call("test -f /etc/private10.sh", shell=True) == 0:
            subprocess.run("rm /etc/private10.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip10.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private10.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v610.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip10.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v610.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v610.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v610.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run(
            "systemctl disable ping_ip10.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip10.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip10.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip10 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip10 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi10 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi10 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


# gretap
def rmv_gre6tap():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6tap\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[10] | IRAN[1]\033[0m")
    print("2. \033[93mKharej[1] | IRAN[5]\033[0m")
    print("3. \033[92mKharej[5] | IRAN[1] + \033[96mIPSEC\033[0m")
    print("4. \033[93mKharej[1] | IRAN[5] + \033[96mIPSEC\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_gretap6()
            break
        elif server_type == "2":
            ir_gretap6()
            break
        elif server_type == "3":
            kh_gretap6_sec()
            break
        elif server_type == "4":
            ir_gretap6_sec()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def kh_gretap6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6tap [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[93mKharej[2]\033[0m")
    print("3. \033[92mKharej[3]\033[0m")
    print("4. \033[93mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[93mKharej[7]\033[0m")
    print("8. \033[92mKharej[8]\033[0m")
    print("9. \033[93mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            remove_gretap66()
            break
        elif server_type == "7":
            remove_gretap67()
            break
        elif server_type == "8":
            remove_gretap68()
            break
        elif server_type == "9":
            remove_gretap69()
            break
        elif server_type == "10":
            remove_gretap610()
            break
        elif server_type == "11":
            rmv3_qtap()
            break
        elif server_type == "0":
            clear()
            rmv_gre6tap()
            break
        else:
            print("Invalid choice.")


def rmv3_qtap():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gretap6{}".format(i)
        globals()[menu_name]()


def ir_gretap6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6tap [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[93mIRAN[2]\033[0m")
    print("3. \033[92mIRAN[3]\033[0m")
    print("4. \033[93mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            rmv4_qtap()
            break
        elif server_type == "0":
            clear()
            rmv_gre6tap()
            break
        else:
            print("Invalid choice.")


def rmv4_qtap():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gretap6{}".format(i)
        globals()[menu_name]()


def kh_gretap6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6tap + IPSec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1] + IPsec\033[0m")
    print("2. \033[93mKharej[2] + IPsec\033[0m")
    print("3. \033[92mKharej[3] + IPsec\033[0m")
    print("4. \033[93mKharej[4] + IPsec\033[0m")
    print("5. \033[92mKharej[5] + IPsec\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN + IPsec \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            break
        elif server_type == "6":
            rmv3_qtap_sec()
            break
        elif server_type == "0":
            clear()
            rmv_gre6tap()
            break
        else:
            print("Invalid choice.")


def rmv3_qtap_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gretap6{}_sec".format(i)
        globals()[menu_name]()


def ir_gretap6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6tap + IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1] + IPsec\033[0m")
    print("2. \033[93mIRAN[2] + IPsec\033[0m")
    print("3. \033[92mIRAN[3] + IPsec\033[0m")
    print("4. \033[93mIRAN[4] + IPsec\033[0m")
    print("5. \033[92mIRAN[5] + IPsec\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej + IPsec \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            break
        elif server_type == "6":
            rmv4_qtap_sec()
            break
        elif server_type == "0":
            clear()
            rmv_gre6tap()
            break
        else:
            print("Invalid choice.")


def rmv4_qtap_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gretap6{}_sec".format(i)
        globals()[menu_name]()


def remove_gretap61():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre61.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre61.sh", shell=True)
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre61.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip1.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip1.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip1.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig61 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig61 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap62():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre62.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre62.sh", shell=True)
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre62.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip2.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip2.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip2.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip2.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig62 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig62 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap63():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre63.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre63.sh", shell=True)
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre63.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip3.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip3.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip3.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip3.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig63 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig63 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap64():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre64.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre64.sh", shell=True)
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre64.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip4.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip4.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip4.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip4.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig64 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig64 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap65():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre65.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre65.sh", shell=True)
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre65.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip5.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip5.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip5.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip5.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig65 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig65 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap66():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre66.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre66.sh", shell=True)
        if subprocess.call("test -f /etc/private6.sh", shell=True) == 0:
            subprocess.run("rm /etc/private6.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre66.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private6.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v66.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip6.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v66.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v66.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v66.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip6.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip6.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip6.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi6 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig66 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig66 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap67():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre67.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre67.sh", shell=True)
        if subprocess.call("test -f /etc/private7.sh", shell=True) == 0:
            subprocess.run("rm /etc/private7.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre67.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private7.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v67.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip7.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v67.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v67.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v67.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip7.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip7.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip7.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi7 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi7 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig67 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig67 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap68():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre68.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre68.sh", shell=True)
        if subprocess.call("test -f /etc/private8.sh", shell=True) == 0:
            subprocess.run("rm /etc/private8.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre68.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private8.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v68.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip8.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v68.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v68.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v68.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip8.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip8.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip8.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi8 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi8 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig68 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig68 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap69():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre69.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre69.sh", shell=True)
        if subprocess.call("test -f /etc/private9.sh", shell=True) == 0:
            subprocess.run("rm /etc/private9.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre69.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private9.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v69.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip9.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v69.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v69.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v69.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip9.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip9.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip9.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi9 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi9 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig69 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig69 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap610():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6tap\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre610.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre610.sh", shell=True)
        if subprocess.call("test -f /etc/private10.sh", shell=True) == 0:
            subprocess.run("rm /etc/private10.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre610.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private10.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v610.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip10.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v610.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v610.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v610.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip10.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip10.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip10.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi10 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi10 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig610 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig610 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap61_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6tap | IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre61.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre61.sh", shell=True)
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre61.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip1.sh > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)

        subprocess.run(
            "systemctl disable ping_ip1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip1.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip1.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig61 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig61 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap62_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6tap | IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre62.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre62.sh", shell=True)
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre62.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)

        subprocess.run("sudo rm /etc/ping_ip2.sh > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )

        subprocess.run(
            "systemctl disable ping_ip2.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip2.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip2.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig62 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig62 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap63_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6tap | IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre63.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre63.sh", shell=True)
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre63.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip3.sh > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip3.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip3.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip3.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig63 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig63 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap64_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6tap | IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre64.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre64.sh", shell=True)
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre64.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)

        subprocess.run("sudo rm /etc/ping_ip4.sh > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip4.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip4.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip4.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig64 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig64 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gretap65_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6tap | IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre65.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre65.sh", shell=True)
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre65.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)

        subprocess.run("sudo rm /etc/ping_ip5.sh > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )

        subprocess.run(
            "systemctl disable ping_ip5.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip5.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip5.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig65 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig65 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def rmv_gre6_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 + IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[5] | IRAN[1]\033[0m")
    print("2. \033[93mKharej[1] | IRAN[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_gre6_ipsec()
            break
        elif server_type == "2":
            ir_gre6_ipsec()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def kh_gre6_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 + IPsec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[93mKharej[2]\033[0m")
    print("3. \033[92mKharej[3]\033[0m")
    print("4. \033[93mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61_ipsec()
            break
        elif server_type == "2":
            remove_gre62_ipsec()
            break
        elif server_type == "3":
            remove_gre63_ipsec()
            break
        elif server_type == "4":
            remove_gre64_ipsec()
            break
        elif server_type == "5":
            remove_gre65_ipsec()
            break
        elif server_type == "6":
            rmv3_qgre_sec()
            break
        elif server_type == "0":
            clear()
            rmv_gre6_ipsec()
            break
        else:
            print("Invalid choice.")


def rmv3_qgre_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gre6{}_ipsec".format(i)
        globals()[menu_name]()


def ir_gre6_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 + IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[93mIRAN[2]\033[0m")
    print("3. \033[92mIRAN[3]\033[0m")
    print("4. \033[93mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61_ipsec()
            break
        elif server_type == "2":
            remove_gre62_ipsec()
            break
        elif server_type == "3":
            remove_gre63_ipsec()
            break
        elif server_type == "4":
            remove_gre64_ipsec()
            break
        elif server_type == "5":
            remove_gre65_ipsec()
            break
        elif server_type == "6":
            rmv4_qgre_sec()
            break
        elif server_type == "0":
            clear()
            rmv_gre6_ipsec()
            break
        else:
            print("Invalid choice.")


def rmv4_qgre_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gre6{}_ipsec".format(i)
        globals()[menu_name]()


def remove_gre61_ipsec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6 + IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre61.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre61.sh", shell=True)
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre61.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip1.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip1.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip1.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig61 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig61 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre62_ipsec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6 + IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre62.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre62.sh", shell=True)
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre62.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip2.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip2.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip2.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip2.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig62 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig62 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre63_ipsec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6 + IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre63.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre63.sh", shell=True)
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre63.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip3.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip3.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip3.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip3.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig63 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig63 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre64_ipsec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6 + IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre64.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre64.sh", shell=True)
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre64.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip4.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip4.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip4.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip4.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig64 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig64 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre65_ipsec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving \033[92mGRE6 + IPsec\033[93m Tunnel...\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre65.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre65.sh", shell=True)
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre65.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip5.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip5.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip5.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip5.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig65 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig65 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def rmv_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[10] | IRAN[1]\033[0m")
    print("2. \033[93mKharej[1] | IRAN[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_gre6()
            break
        elif server_type == "2":
            ir_gre6()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def kh_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[93mKharej[2]\033[0m")
    print("3. \033[92mKharej[3]\033[0m")
    print("4. \033[93mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[93mKharej[7]\033[0m")
    print("8. \033[92mKharej[8]\033[0m")
    print("9. \033[93mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61()
            break
        elif server_type == "2":
            remove_gre62()
            break
        elif server_type == "3":
            remove_gre63()
            break
        elif server_type == "4":
            remove_gre64()
            break
        elif server_type == "5":
            remove_gre65()
            break
        elif server_type == "6":
            remove_gre66()
            break
        elif server_type == "7":
            remove_gre67()
            break
        elif server_type == "8":
            remove_gre68()
            break
        elif server_type == "9":
            remove_gre69()
            break
        elif server_type == "10":
            remove_gre610()
            break
        elif server_type == "11":
            rmv3_q()
            break
        elif server_type == "0":
            clear()
            rmv_gre6()
            break
        else:
            print("Invalid choice.")


def rmv3_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gre6{}".format(i)
        globals()[menu_name]()


def ir_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[93mIRAN[2]\033[0m")
    print("3. \033[92mIRAN[3]\033[0m")
    print("4. \033[93mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61()
            break
        elif server_type == "2":
            remove_gre62()
            break
        elif server_type == "3":
            remove_gre63()
            break
        elif server_type == "4":
            remove_gre64()
            break
        elif server_type == "5":
            remove_gre65()
            break
        elif server_type == "6":
            rmv4_q()
            break
        elif server_type == "0":
            clear()
            rmv_gre6()
            break
        else:
            print("Invalid choice.")


def rmv4_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_gre6{}".format(i)
        globals()[menu_name]()


# remove gen multi
def rmv_gen_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN \033[96mGen UDP|Native\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN \033[96mGen UDP|Native\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("3. \033[93m[1]Kharej | [5]IRAN \033[96mGen Gre6\033[0m")
    print("4. \033[92m[5]Kharej | [1]IRAN \033[96mGen Gre6\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("5. \033[92m[5]Kharej | [1]IRAN \033[96m+ IPSEC\033[0m")
    print("6. \033[93m[1]Kharej | [5]IRAN \033[96m+ IPSEC\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_gen_multi()
            break
        elif server_type == "2":
            ir_gen_multi()
            break
        elif server_type == "3":
            ir_gen_multigre()
            break
        elif server_type == "4":
            kh_gen_multigre()
            break
        elif server_type == "5":
            kh_gen_multisec()
            break
        elif server_type == "6":
            ir_gen_multisec()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def kh_gen_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "6":
            rmv1m_qgen()
            break
        elif server_type == "0":
            clear()
            rmv_gen_multi()
            break
        else:
            print("Invalid choice.")


def rmv1m_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genz{}_uninstall".format(i)
        globals()[menu_name]()


# gre
def kh_gen_multigre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "6":
            rmv1m_qgengre()
            break
        elif server_type == "0":
            clear()
            rmv_gen_multi()
            break
        else:
            print("Invalid choice.")


def rmv1m_qgengre():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genz{}gre_uninstall".format(i)
        globals()[menu_name]()


# sec
def kh_gen_multisec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve IPsec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            break
        elif server_type == "6":
            rmv1m_qgensec()
            break
        elif server_type == "0":
            clear()
            rmv_gen_multi()
            break
        else:
            print("Invalid choice.")


def rmv1m_qgensec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genz{}_uninstall_sec".format(i)
        globals()[menu_name]()


def ir_gen_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "6":
            rmv2m_qgen()
            break
        elif server_type == "0":
            clear()
            rmv_gen_multi()
            break
        else:
            print("Invalid choice.")


def rmv2m_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genz{}_uninstall".format(i)
        globals()[menu_name]()


# gre
def ir_gen_multigre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "6":
            rmv2m_qgengre()
            break
        elif server_type == "0":
            clear()
            rmv_gen_multi()
            break
        else:
            print("Invalid choice.")


def rmv2m_qgengre():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genz{}gre_uninstall".format(i)
        globals()[menu_name]()


# sec
def ir_gen_multisec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            break
        elif server_type == "6":
            rmv2m_qgensec()
            break
        elif server_type == "0":
            clear()
            rmv_gen_multi()
            break
        else:
            print("Invalid choice.")


def rmv2m_qgensec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genz{}_uninstall_sec".format(i)
        globals()[menu_name]()


# remove
def remote_ip_gen1():
    gen_path = "/etc/sys1.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "remote" in line:
                remote_ip = line.split()[-1].strip('"')
                return remote_ip

    return None


def genz1gre_uninstall():
    os.system("clear")
    remove_gre61()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen1()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b481::1")
    delufw("fd1d:fc98:b73e:b481::2")
    delufw("2002:831a::1")
    delufw("2002:831a::2")
    delufw("2001:db3::1")
    delufw("2001:db3::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys1.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping1_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen1 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz1_uninstall():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen1()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b481::1")
    delufw("fd1d:fc98:b73e:b481::2")
    delufw("2002:831a::1")
    delufw("2002:831a::2")
    delufw("2001:db3::1")
    delufw("2001:db3::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys1.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping1_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen1 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz1_uninstall_sec():
    os.system("clear")
    remove_gre61()
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen1()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b481::1")
    delufw("fd1d:fc98:b73e:b481::2")
    delufw("2002:831a::1")
    delufw("2002:831a::2")
    delufw("2001:db3::1")
    delufw("2001:db3::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys1.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping1_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen1 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "sudo apt purge strongswan -y > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz1u_uninstall_sec():
    os.system("clear")
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen1()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b481::1")
    delufw("fd1d:fc98:b73e:b481::2")
    delufw("2002:831a::1")
    delufw("2002:831a::2")
    delufw("2001:db3::1")
    delufw("2001:db3::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys1.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys1.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping1_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping1_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen1 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "sudo apt purge strongswan -y > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# 2
def remote_ip_gen2():
    gen_path = "/etc/sys2.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "remote" in line:
                remote_ip = line.split()[-1].strip('"')
                return remote_ip

    return None


def genz2gre_uninstall():
    os.system("clear")
    remove_gre62()

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen2()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b581::1")
    delufw("fd1d:fc98:b73e:b581::2")
    delufw("2002:841a::1")
    delufw("2002:841a::2")
    delufw("2001:db4::1")
    delufw("2001:db4::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys2.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping2_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "sudo ip link delete azumigen2 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz2_uninstall():
    os.system("clear")

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen2()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b581::1")
    delufw("fd1d:fc98:b73e:b581::2")
    delufw("2002:841a::1")
    delufw("2002:841a::2")
    delufw("2001:db4::1")
    delufw("2001:db4::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys2.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping2_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "sudo ip link delete azumigen2 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz2_uninstall_sec():
    os.system("clear")
    remove_gre62()
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen2()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b581::1")
    delufw("fd1d:fc98:b73e:b581::2")
    delufw("2002:841a::1")
    delufw("2002:841a::2")
    delufw("2001:db4::1")
    delufw("2001:db4::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys2.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping2_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "sudo ip link delete azumigen2 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz2u_uninstall_sec():
    os.system("clear")
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen2()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b581::1")
    delufw("fd1d:fc98:b73e:b581::2")
    delufw("2002:841a::1")
    delufw("2002:841a::2")
    delufw("2001:db4::1")
    delufw("2001:db4::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys2.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys2.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping2_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping2_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "sudo ip link delete azumigen2 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# 3


def remote_ip_gen3():
    gen_path = "/etc/sys3.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "remote" in line:
                remote_ip = line.split()[-1].strip('"')
                return remote_ip

    return None


def genz3gre_uninstall():
    os.system("clear")
    remove_gre63()

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen3()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b681::1")
    delufw("fd1d:fc98:b73e:b681::2")
    delufw("2002:851a::1")
    delufw("2002:851a::2")
    delufw("2001:db5::1")
    delufw("2001:db5::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys3.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping3_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen3 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz3_uninstall():
    os.system("clear")

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen3()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b681::1")
    delufw("fd1d:fc98:b73e:b681::2")
    delufw("2002:851a::1")
    delufw("2002:851a::2")
    delufw("2001:db5::1")
    delufw("2001:db5::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys3.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping3_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen3 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz3_uninstall_sec():
    os.system("clear")
    remove_gre63()
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen3()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b681::1")
    delufw("fd1d:fc98:b73e:b681::2")
    delufw("2002:851a::1")
    delufw("2002:851a::2")
    delufw("2001:db5::1")
    delufw("2001:db5::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys3.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping3_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen3 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz3u_uninstall_sec():
    os.system("clear")
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen3()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b681::1")
    delufw("fd1d:fc98:b73e:b681::2")
    delufw("2002:851a::1")
    delufw("2002:851a::2")
    delufw("2001:db5::1")
    delufw("2001:db5::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys3.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys3.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping3_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping3_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen3 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# 4
def remote_ip_gen4():
    gen_path = "/etc/sys4.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "remote" in line:
                remote_ip = line.split()[-1].strip('"')
                return remote_ip

    return None


def genz4gre_uninstall():
    os.system("clear")
    remove_gre64()

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen4()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b781::1")
    delufw("fd1d:fc98:b73e:b781::2")
    delufw("2002:861a::1")
    delufw("2002:861a::2")
    delufw("2001:db6::1")
    delufw("2001:db6::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys4.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping4_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen4 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz4_uninstall():
    os.system("clear")

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen4()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b781::1")
    delufw("fd1d:fc98:b73e:b781::2")
    delufw("2002:861a::1")
    delufw("2002:861a::2")
    delufw("2001:db6::1")
    delufw("2001:db6::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys4.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping4_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen4 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz4_uninstall_sec():
    os.system("clear")
    remove_gre64()
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen4()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b781::1")
    delufw("fd1d:fc98:b73e:b781::2")
    delufw("2002:861a::1")
    delufw("2002:861a::2")
    delufw("2001:db6::1")
    delufw("2001:db6::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys4.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping4_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen4 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz4u_uninstall_sec():
    os.system("clear")
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen4()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
    delufw("fd1d:fc98:b73e:b781::1")
    delufw("fd1d:fc98:b73e:b781::2")
    delufw("2002:861a::1")
    delufw("2002:861a::2")
    delufw("2001:db6::1")
    delufw("2001:db6::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys4.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys4.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping4_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping4_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen4 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# 5


def remote_ip_gen5():
    gen_path = "/etc/sys5.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "remote" in line:
                remote_ip = line.split()[-1].strip('"')
                return remote_ip

    return None


def genz5gre_uninstall():
    os.system("clear")
    remove_gre65()

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen5()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)

    delufw("fd1d:fc98:b73e:b881::1")
    delufw("fd1d:fc98:b73e:b881::2")
    delufw("2002:871a::1")
    delufw("2002:871a::2")
    delufw("2001:db7::1")
    delufw("2001:db7::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys5.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping5_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen5 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz5_uninstall():
    os.system("clear")

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen5()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)

    delufw("fd1d:fc98:b73e:b881::1")
    delufw("fd1d:fc98:b73e:b881::2")
    delufw("2002:871a::1")
    delufw("2002:871a::2")
    delufw("2001:db7::1")
    delufw("2001:db7::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys5.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping5_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen5 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz5_uninstall_sec():
    os.system("clear")
    remove_gre65()
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen5()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)

    delufw("fd1d:fc98:b73e:b881::1")
    delufw("fd1d:fc98:b73e:b881::2")
    delufw("2002:871a::1")
    delufw("2002:871a::2")
    delufw("2001:db7::1")
    delufw("2001:db7::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys5.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping5_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen5 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def genz5u_uninstall_sec():
    os.system("clear")
    delete_cron1()
    delete_cron2()
    delete_cron3()
    delete_cron4()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_ip = remote_ip_gen5()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)

    delufw("fd1d:fc98:b73e:b881::1")
    delufw("fd1d:fc98:b73e:b881::2")
    delufw("2002:871a::1")
    delufw("2002:871a::2")
    delufw("2001:db7::1")
    delufw("2001:db7::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys5.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys5.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping5_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping5_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen5 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def remove_gre61():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre61.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre61.sh", shell=True)
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre61.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip1.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip1.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip1.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip1.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig61 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig61 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre62():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre62.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre62.sh", shell=True)
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre62.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip2.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip2.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip2.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip2.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig62 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig62 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre63():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre63.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre63.sh", shell=True)
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre63.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip3.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip3.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip3.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip3.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig63 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig63 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre64():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre64.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre64.sh", shell=True)
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre64.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip4.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip4.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip4.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip4.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig64 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig64 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre65():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre65.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre65.sh", shell=True)
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre65.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip5.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip5.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip5.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip5.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig65 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig65 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre66():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre66.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre66.sh", shell=True)
        if subprocess.call("test -f /etc/private6.sh", shell=True) == 0:
            subprocess.run("rm /etc/private6.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre66.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private6.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v66.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip6.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v66.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v66.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v66.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip6.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip6.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip6.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi6 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig66 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig66 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre67():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre67.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre67.sh", shell=True)
        if subprocess.call("test -f /etc/private7.sh", shell=True) == 0:
            subprocess.run("rm /etc/private7.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre67.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private7.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v67.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip7.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v67.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v67.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v67.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip7.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip7.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip7.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi7 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi7 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig67 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig67 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre68():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre68.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre68.sh", shell=True)
        if subprocess.call("test -f /etc/private8.sh", shell=True) == 0:
            subprocess.run("rm /etc/private8.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre68.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private8.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v68.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip8.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v68.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v68.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v68.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip8.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip8.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip8.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi8 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi8 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig68 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig68 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre69():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre69.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre69.sh", shell=True)
        if subprocess.call("test -f /etc/private9.sh", shell=True) == 0:
            subprocess.run("rm /etc/private9.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre69.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private9.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v69.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip9.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v69.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v69.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v69.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip9.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip9.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip9.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi9 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi9 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig69 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig69 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre610():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre610.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre610.sh", shell=True)
        if subprocess.call("test -f /etc/private10.sh", shell=True) == 0:
            subprocess.run("rm /etc/private10.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre610.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private10.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v610.sh", shell=True)
        time.sleep(1)
        subprocess.run("sudo rm /etc/ping_ip10.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_v610.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v610.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v610.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip10.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_ip10.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip10.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi9 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi9 > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumig610 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig610 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def rmv_private_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Private + IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[5] | IRAN[1]\033[0m")
    print("2. \033[93mKharej[1] | IRAN[5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_private_sec()
            break
        elif server_type == "2":
            ir_private_sec()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def rmv5_qprivate_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_private{}_sec".format(i)
        globals()[menu_name]()


def kh_private_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Private [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[93mKharej[2]\033[0m")
    print("3. \033[92mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1_sec()
            break
        elif server_type == "2":
            remove_private2_sec()
            break
        elif server_type == "3":
            remove_private3_sec()
            break
        elif server_type == "4":
            remove_private4_sec()
            break
        elif server_type == "5":
            remove_private5_sec()
            break
        elif server_type == "6":
            rmv5_qprivate_sec()
            break
        elif server_type == "0":
            clear()
            rmv_private_sec()
            break
        else:
            print("Invalid choice.")


def ir_private_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Private [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[93mIRAN[2]\033[0m")
    print("3. \033[92mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1_sec()
            break
        elif server_type == "2":
            remove_private2_sec()
            break
        elif server_type == "3":
            remove_private3_sec()
            break
        elif server_type == "4":
            remove_private4_sec()
            break
        elif server_type == "5":
            remove_private5_sec()
            break
        elif server_type == "6":
            rmv6_qprivate_sec()
            break
        elif server_type == "0":
            clear()
            rmv_private_sec()
            break
        else:
            print("Invalid choice.")


def rmv6_qprivate_sec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_private{}_sec".format(i)
        globals()[menu_name]()


def remove_private1_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec1.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private2_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec2.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private3_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec3.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private4_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec4.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private5_sec():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ipsec5.conf > /dev/null 2>&1", shell=True)
        subprocess.run("sudo rm /etc/ipsec.secrets > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strong-azumi1 > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/strong-azumi1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)
        subprocess.run("apt purge strongswan -y > /dev/null", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def rmv_private():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Private\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[10] | IRAN[1]\033[0m")
    print("2. \033[93mKharej[1] | IRAN[5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kh_private()
            break
        elif server_type == "2":
            ir_private()
            break
        elif server_type == "0":
            clear()
            remove2_menu()
            break
        else:
            print("Invalid choice.")


def rmv5_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_private{}".format(i)
        globals()[menu_name]()


def kh_private():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Private [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[93mKharej[2]\033[0m")
    print("3. \033[92mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[93mKharej[7]\033[0m")
    print("8. \033[92mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1()
            break
        elif server_type == "2":
            remove_private2()
            break
        elif server_type == "3":
            remove_private3()
            break
        elif server_type == "4":
            remove_private4()
            break
        elif server_type == "5":
            remove_private5()
            break
        elif server_type == "6":
            remove_private6()
            break
        elif server_type == "7":
            remove_private7()
            break
        elif server_type == "8":
            remove_private8()
            break
        elif server_type == "9":
            remove_private9()
            break
        elif server_type == "10":
            remove_private10()
            break
        elif server_type == "11":
            rmv5_q()
            break
        elif server_type == "0":
            clear()
            rmv_private()
            break
        else:
            print("Invalid choice.")


def ir_private():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Private [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[93mIRAN[2]\033[0m")
    print("3. \033[92mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1()
            break
        elif server_type == "2":
            remove_private2()
            break
        elif server_type == "3":
            remove_private3()
            break
        elif server_type == "4":
            remove_private4()
            break
        elif server_type == "5":
            remove_private5()
            break
        elif server_type == "6":
            rmv6_q()
            break
        elif server_type == "0":
            clear()
            rmv_private()
            break
        else:
            print("Invalid choice.")


def rmv6_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "remove_private{}".format(i)
        globals()[menu_name]()


def remove_private1():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private1.sh", shell=True) == 0:
            subprocess.run("rm /etc/private1.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private1.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v61.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi1 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi1 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private2():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private2.sh", shell=True) == 0:
            subprocess.run("rm /etc/private2.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private2.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v62.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi2 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi2 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private3():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private3.sh", shell=True) == 0:
            subprocess.run("rm /etc/private3.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private3.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v63.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi3 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi3 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private4():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private4.sh", shell=True) == 0:
            subprocess.run("rm /etc/private4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private4.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v64.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi4 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi4 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_private5():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private5.sh", shell=True) == 0:
            subprocess.run("rm /etc/private5.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private5.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v65.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi5 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi5 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


# private6
def remove_private6():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private6.sh", shell=True) == 0:
            subprocess.run("rm /etc/private6.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private6.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v66.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v66.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v66.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v66.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi6 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


# private7
def remove_private7():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private7.sh", shell=True) == 0:
            subprocess.run("rm /etc/private7.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private7.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v67.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v67.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v67.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v67.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi7 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi7 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


# private8
def remove_private8():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private8.sh", shell=True) == 0:
            subprocess.run("rm /etc/private8.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private8.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v68.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v68.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v68.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v68.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi8 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi8 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


# private9
def remove_private9():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private9.sh", shell=True) == 0:
            subprocess.run("rm /etc/private9.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private9.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v69.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v69.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v69.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v69.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi9 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi9 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


# private10
def remove_private10():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/private10.sh", shell=True) == 0:
            subprocess.run("rm /etc/private10.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private10.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v610.sh", shell=True)

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v610.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v610.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v610.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi10 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi10 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


## gre6 ipsec
def config_gre6k1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre61
  left=%defaultroute
  leftsubnet=2002:801a::1/64
  leftid=2002:801a::1
  right=2002:801a::2
  rightsubnet=2002:801a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:801a::2 2002:801a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6k2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre62
  left=%defaultroute
  leftsubnet=2002:811a::1/64
  leftid=2002:811a::1
  right=2002:811a::2
  rightsubnet=2002:811a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:811a::2 2002:811a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6k3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre63
  left=%defaultroute
  leftsubnet=2002:821a::1/64
  leftid=2002:821a::1
  right=2002:821a::2
  rightsubnet=2002:821a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:821a::2 2002:821a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6k4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre64
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6k5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre65
  left=%defaultroute
  leftsubnet=2002:841a::1/64
  leftid=2002:841a::1
  right=2002:841a::2
  rightsubnet=2002:841a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:841a::2 2002:841a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6i1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre61
  left=%defaultroute
  leftsubnet=2002:801a::2/64
  leftid=2002:801a::2
  right=2002:801a::1
  rightsubnet=2002:801a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:801a::1 2002:801a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6i2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre62
  left=%defaultroute
  leftsubnet=2002:811a::2/64
  leftid=2002:811a::2
  right=2002:811a::1
  rightsubnet=2002:811a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:811a::1 2002:811a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6i3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre63
  left=%defaultroute
  leftsubnet=2002:821a::2/64
  leftid=2002:821a::2
  right=2002:821a::1
  rightsubnet=2002:821a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:821a::1 2002:821a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6i4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gre64
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6i5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2002:841a::2/64
  leftid=2002:841a::2
  right=2002:841a::1
  rightsubnet=2002:841a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:841a::1 2002:841a::2 : PSK "{psk}"\n')

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6k(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyouarea\n")

        for i in range(num_servers):
            f.write(f"\nconn GRE6{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:8{i+0}1a::1/64\n")
            f.write(f"  leftid=2002:8{i+0}1a::1\n")
            f.write(f"  right=2002:8{i+0}1a::2\n")
            f.write(f"  rightsubnet=2002:8{i+0}1a::2/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2002:8{i+0}1a::2 2002:8{i+0}1a::1 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_gre6i(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn GRE6{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:8{i+0}1a::2/64\n")
            f.write(f"  leftid=2002:8{i+0}1a::2\n")
            f.write(f"  right=2002:8{i+0}1a::1\n")
            f.write(f"  rightsubnet=2002:8{i+0}1a::1/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2002:8{i+0}1a::1 2002:8{i+0}1a::2 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def gre6_mnu_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 + IPSec \033[92m Multiple Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[96mKHAREJ\033[92m[5]  \033[93mIRAN\033[92m[1]\033[0m")
    print("2. \033[96mKHAREJ\033[92m[1]  \033[93mIRAN\033[92m[5]\033[0m")
    print("3. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh_ipsec()
            break
        elif server_type == "2":
            gre6_ir_ipsec()
            break
        elif server_type == "3":
            choose_reset2()
            break
        elif server_type == "0":
            os.system("clear")
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def gre6_kh_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 + IPSec\033[92m[5]Kharej\033[96m [1]IRAN\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_gre61_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_gre62_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_gre63_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_gre64_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_gre65_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            gre6_reset_rmvmnu()
            enable_reset_ipsec()
            kharejgre_qipsec()
            break
        elif server_type == "0":
            os.system("clear")
            gre6_mnu_ipsec()
            break
        else:
            print("Invalid choice.")


def kharejgre_qipsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "iran_gre6{}_ipsec".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit
def kharejgre_qipsec_edit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def kharejgre_qipsec_edit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input(
            "\033[93mHow many \033[92mKharej Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_gre6i(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    display_notification(
        "\033[93mUse systemctl restart strong-azumi1 in kharej servers as well \033[0m"
    )
    restart_forced_strongazumi()


def gre6_ir_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 + IPSec \033[92m[3]IRAN\033[96m [1]Kharej\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_gre61_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_gre62_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_gre63_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_gre64_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            gre6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_gre65_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            gre6_reset_rmvmnu()
            enable_reset_ipsec()
            irangre_qipsec()
            break
        elif server_type == "0":
            os.system("clear")
            gre6_mnu_ipsec()
            break
        else:
            print("Invalid choice.")


def irangre_qipsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "kharej2_gre6{}_ipsec".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit
def irangre_qipsec_edit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def irangre_qipsec_edit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_gre6k(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    display_notification(
        "\033[93mUse systemctl restart strong-azumi1 in kharej servers as well \033[0m"
    )
    restart_forced_strongazumi()


def kharej_gre61_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[1]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k1(psk)
    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre61_kharejsec()
    sleep(1)


## kharej1 for iran 1
def kharej2_gre61_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[1]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre61_kharejsec()
    sleep(1)


# edit
def kharej2_gre61_edit():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[1]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k1(psk)
    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre61_kharejsec()
    sleep(1)


def kharej_gre62_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[2]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k2(psk)
    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre62_kharejsec()
    sleep(1)


## kharej 2 for iran 2
def kharej2_gre62_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[2]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre62_kharejsec()
    sleep(1)


def kharej_gre63_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[3]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k3(psk)
    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre63_kharejsec()
    sleep(1)


## kharej 3 for iran 3
def kharej2_gre63_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[3]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre63_kharejsec()
    sleep(1)


def kharej_gre64_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[4]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k4(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre64_kharejsec()
    sleep(1)


## kharej 4 for iran 4
def kharej2_gre64_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[4]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre64_kharejsec()
    sleep(1)


def kharej_gre65_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[5]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k5(psk)
    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre65_kharejsec()
    sleep(1)


## kharej 5 for iran 5
def kharej2_gre65_ipsec():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[92mKharej[5]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre65_kharejsec()
    sleep(1)


def iran_gre61_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre61_iransec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# edit
def iran_gre61_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i1(psk)
    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre61_iransec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


##default route iran1 command
def iran2_gre61_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m [1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i1(psk)
    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre61_iran2sec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def iran_gre62_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::1/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre62_iransec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route iran 2 menu
def iran2_gre62_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i2(psk)
    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::1/64 dev azumi2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre62_iran2sec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def iran_gre63_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre63_iransec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre63_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i3(psk)
    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre63_iran2sec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def iran_gre64_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre64_iransec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre64_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i4(psk)
    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre64_iran2sec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def iran_gre65_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre65_iransec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre65_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 + IPSec \033[96m Server\033[92m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i5(psk)
    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre65_iran2sec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# gretap native
def gretapnm():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10] Kharej [1] IRAN\033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tapmu_k()
            break
        elif server_type == "2":
            gre6tapmu_i()
            break
        elif server_type == "3":
            clear()
            gre6tapmulti_mnu
            break
        else:
            print("Invalid choice.")


def gre6tapmu_k():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("6. \033[92mKharej [6]\033[0m")
    print("7. \033[92mKharej [7]\033[0m")
    print("8. \033[93mKharej [8]\033[0m")
    print("9. \033[92mKharej [9]\033[0m")
    print("10.\033[92mKharej [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[96mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_k1()
            break
        elif server_type == "2":
            gre6tap_k2()
            break
        elif server_type == "3":
            gre6tap_k3()
            break
        elif server_type == "4":
            gre6tap_k4()
            break
        elif server_type == "5":
            gre6tap_k5()
            break
        elif server_type == "6":
            gre6tap_k6()
            break
        elif server_type == "7":
            gre6tap_k7()
            break
        elif server_type == "8":
            gre6tap_k8()
            break
        elif server_type == "9":
            gre6tap_k9()
            break
        elif server_type == "10":
            gre6tap_k10()
            break
        elif server_type == "11":
            irangretap_q()
            break
        elif server_type == "0":
            clear()
            gretapnm()
            break
        else:
            print("Invalid choice.")


def irangretap_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6tap2_i{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def gre6tapmu_i():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[96mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_i1()
            break
        elif server_type == "2":
            gre6tap_i2()
            break
        elif server_type == "3":
            gre6tap_i3()
            break
        elif server_type == "4":
            gre6tap_i4()
            break
        elif server_type == "5":
            gre6tap_i5()
            break
        elif server_type == "6":
            kharejgretap_q()
            break
        elif server_type == "0":
            clear()
            gretapnm()
            break
        else:
            print("Invalid choice.")


def kharejgretap_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6tap2_k{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def gre6tapk_tunnel1():
    global local_ip, remote_ip
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:801a::1/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel1():
    global local_ip, remote_ip
    gre6tapk_tunnel1()
    ip_address = "2002:801a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre61_service()
    gre61_cronjob()


def gre6tap_k1():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel1():
    global local_ip, remote_ip
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:801a::2/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel1():
    global local_ip, remote_ip
    gre6tapi_tunnel1()
    ip_address = "2002:801a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre61_service()
    gre61_cronjob()


def gre6tap_i1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 2native


def gre6tapk_tunnel2():
    global local_ip, remote_ip
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:811a::1/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel2():
    global local_ip, remote_ip
    gre6tapk_tunnel2()
    ip_address = "2002:811a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre62_service()
    gre62_cronjob()


def gre6tap_k2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel2():
    global local_ip, remote_ip
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:811a::2/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel2():
    global local_ip, remote_ip
    gre6tapi_tunnel2()
    ip_address = "2002:811a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre62_service()
    gre62_cronjob()


def gre6tap_i2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 3native


def gre6tapk_tunnel3():
    global local_ip, remote_ip
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:821a::1/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel3():
    global local_ip, remote_ip
    gre6tapk_tunnel3()
    ip_address = "2002:821a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre63_service()
    gre63_cronjob()


def gre6tap_k3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel3():
    global local_ip, remote_ip
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:821a::2/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel3():
    global local_ip, remote_ip
    gre6tapi_tunnel3()
    ip_address = "2002:821a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre63_service()
    gre63_cronjob()


def gre6tap_i3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end
def create_ping4_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def create_ping5_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ping_gre64_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip4.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip4.service"])
    subprocess.run(["systemctl", "start", "ping_ip4.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip4.service"])


def ping_gre65_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip5.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip5.service"])
    subprocess.run(["systemctl", "start", "ping_ip5.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip5.service"])


def gre64_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre64.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre64.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre65_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre65.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre65.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


# 4native


def gre6tapk_tunnel4():
    global local_ip, remote_ip
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:831a::1/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel4():
    global local_ip, remote_ip
    gre6tapk_tunnel4()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre64_service()
    gre64_cronjob()


def gre6tap_k4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel4():
    global local_ip, remote_ip
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:831a::2/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel4():
    global local_ip, remote_ip
    gre6tapi_tunnel4()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre64_service()
    gre64_cronjob()


def gre6tap_i4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end
# 5native


def gre6tapk_tunnel5():
    global local_ip, remote_ip
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:841a::1/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel5():
    global local_ip, remote_ip
    gre6tapk_tunnel5()
    ip_address = "2002:841a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre65_service()
    gre65_cronjob()


def gre6tap_k5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel5():
    global local_ip, remote_ip
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:841a::2/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel5():
    global local_ip, remote_ip
    gre6tapi_tunnel5()
    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre65_service()
    gre65_cronjob()


def gre6tap_i5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 6native


def gre6tapk_tunnel6():
    global local_ip, remote_ip
    file_path = "/etc/gre66.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig66 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:851a::1/64 dev azumig66\n")
        f.write("ip link set azumig66 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel6():
    global local_ip, remote_ip
    gre6tapk_tunnel6()
    ip_address = "2002:851a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping6_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre66_service()
    gre66_cronjob()


def gre6tap_k6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[6]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[6]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel6():
    global local_ip, remote_ip
    file_path = "/etc/gre66.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig66 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:851a::2/64 dev azumig66\n")
        f.write("ip link set azumig66 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel6():
    global local_ip, remote_ip
    gre6tapi_tunnel6()
    ip_address = "2002:851a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping6_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre66_service()
    gre66_cronjob()


def gre6tap_i6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[6]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[6]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 7native


def gre6tapk_tunnel7():
    global local_ip, remote_ip
    file_path = "/etc/gre67.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig67 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:861a::1/64 dev azumig67\n")
        f.write("ip link set azumig67 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel7():
    global local_ip, remote_ip
    gre6tapk_tunnel7()
    ip_address = "2002:861a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping7_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre67_service()
    gre67_cronjob()


def gre6tap_k7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[7]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[7]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel7():
    global local_ip, remote_ip
    file_path = "/etc/gre67.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig67 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:861a::2/64 dev azumig67\n")
        f.write("ip link set azumig67 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel7():
    global local_ip, remote_ip
    gre6tapi_tunnel7()
    ip_address = "2002:861a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping7_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre67_service()
    gre67_cronjob()


def gre6tap_i7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[7]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[7]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 8native


def gre6tapk_tunnel8():
    global local_ip, remote_ip
    file_path = "/etc/gre68.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig68 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:871a::1/64 dev azumig68\n")
        f.write("ip link set azumig68 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel8():
    global local_ip, remote_ip
    gre6tapk_tunnel8()
    ip_address = "2002:871a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping8_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre68_service()
    gre68_cronjob()


def gre6tap_k8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[8]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[8]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel8():
    global local_ip, remote_ip
    file_path = "/etc/gre68.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig68 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:871a::2/64 dev azumig68\n")
        f.write("ip link set azumig68 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel8():
    global local_ip, remote_ip
    gre6tapi_tunnel8()
    ip_address = "2002:871a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping8_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre68_service()
    gre68_cronjob()


def gre6tap_i8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[8]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[8]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 9native


def gre6tapk_tunnel9():
    global local_ip, remote_ip
    file_path = "/etc/gre69.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig69 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:881a::1/64 dev azumig69\n")
        f.write("ip link set azumig69 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel9():
    global local_ip, remote_ip
    gre6tapk_tunnel9()
    ip_address = "2002:881a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping8_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre69_service()
    gre69_cronjob()


def gre6tap_k9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[9]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[9]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel9():
    global local_ip, remote_ip
    file_path = "/etc/gre69.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig69 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:881a::2/64 dev azumig69\n")
        f.write("ip link set azumig69 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel9():
    global local_ip, remote_ip
    gre6tapi_tunnel9()
    ip_address = "2002:881a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping9_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre69_service()
    gre69_cronjob()


def gre6tap_i9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[9]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[9]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 10native


def gre6tapk_tunnel10():
    global local_ip, remote_ip
    file_path = "/etc/gre610.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig610 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:891a::1/64 dev azumig610\n")
        f.write("ip link set azumig610 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def kharej_gre6tap_tunnel10():
    global local_ip, remote_ip
    gre6tapk_tunnel10()
    ip_address = "2002:891a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping10_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre610_service()
    gre610_cronjob()


def gre6tap_k10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[10]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[10]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tapi_tunnel10():
    global local_ip, remote_ip
    file_path = "/etc/gre610.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig610 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write(f"ip -6 addr add 2002:891a::2/64 dev azumig610\n")
        f.write("ip link set azumig610 up\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    subprocess.run(["bash", file_path], check=True)


def iran_gre6tap_tunnel10():
    global local_ip, remote_ip
    gre6tapi_tunnel10()
    ip_address = "2002:891a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping10_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre610_service()
    gre610_cronjob()


def gre6tap_i10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[10]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[10]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end
## 11
def gre6_mnu_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE6 \033[92m Multiple Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[96mKHAREJ\033[92m[10]  \033[93mIRAN\033[92m[1]\033[0m")
    print("2. \033[96mKHAREJ\033[92m[1]  \033[93mIRAN\033[92m[5]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh_ip()
            break
        elif server_type == "2":
            gre6_ir_ip()
            break
        elif server_type == "0":
            os.system("clear")
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def gre6_kh_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnu()
            kharej_gre61_menu()
            break
        elif server_type == "2":
            gre6_reset_rmvmnu()
            kharej_gre62_menu()
            break
        elif server_type == "3":
            gre6_reset_rmvmnu()
            kharej_gre63_menu()
            break
        elif server_type == "4":
            gre6_reset_rmvmnu()
            kharej_gre64_menu()
            break
        elif server_type == "5":
            gre6_reset_rmvmnu()
            kharej_gre65_menu()
            break
        elif server_type == "6":
            gre6_reset_rmvmnu()
            kharej_gre66_menu()
            break
        elif server_type == "7":
            gre6_reset_rmvmnu()
            kharej_gre67_menu()
            break
        elif server_type == "8":
            gre6_reset_rmvmnu()
            kharej_gre68_menu()
            break
        elif server_type == "9":
            gre6_reset_rmvmnu()
            kharej_gre69_menu()
            break
        elif server_type == "10":
            gre6_reset_rmvmnu()
            kharej_gre610_menu()
            break
        elif server_type == "11":
            gre6_reset_rmvmnu()
            kharejgre_q()
            break
        elif server_type == "0":
            os.system("clear")
            gre6_mnu_ip()
            break
        else:
            print("Invalid choice.")


def kharejgre_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "iran_gre6{}_menu".format(i)
        globals()[menu_name]()


def gre6_ir_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGRE6 \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran2_gre61_menu()
            break
        elif server_type == "2":
            iran2_gre62_menu()
            break
        elif server_type == "3":
            iran2_gre63_menu()
            break
        elif server_type == "4":
            iran2_gre64_menu()
            break
        elif server_type == "5":
            iran2_gre65_menu()
            break
        elif server_type == "6":
            irangre_q()
            break
        elif server_type == "0":
            os.system("clear")
            gre6_mnu_ip()
            break
        else:
            print("Invalid choice.")


def irangre_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "kharej2_gre6{}_menu".format(i)
        globals()[menu_name]()


##kharej1
def run1_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:801b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej1_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:801b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre61_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre61.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre61.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre61_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip1.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip1.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip1.service"])
    subprocess.run(["systemctl", "start", "ping_ip1.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip1.service"])


def gre61_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig61 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:801a::1/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig61 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:801a::2/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:80{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig61' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}"
        with open("/etc/gre61.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:801a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre61_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig61 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:801a::1/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig61 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:801a::2/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}"
        with open("/etc/gre61.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:801a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping1_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre61_kharej():
    remote_ip = "2002:801b::2"  # iran-ip
    local_ip = "2002:801b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre61_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:801a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre61_service()

    gre61_cronjob()


def gre61_kharejsec():
    remote_ip = "2002:801b::2"  # iran-ip
    local_ip = "2002:801b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre61_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:801a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre61_service()

    gre61_cronjob()


def kharej_gre61_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[1]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::2/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre61_kharej()
    sleep(1)


## kharej1 for iran 1
def kharej2_gre61_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[1]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::2/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre61_kharej()
    sleep(1)


##kharej2
def run2_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:811b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v62_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v62.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v62.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v62.service"])
    subprocess.run(["systemctl", "start", "ping_v62.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v62.service"])


def display_kharej2_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:811b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron2_job():
    file_path = "/etc/private2.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre62_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre62.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre62.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre62_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip2.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip2.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip2.service"])
    subprocess.run(["systemctl", "start", "ping_ip2.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip2.service"])


def gre62_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig62 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:811a::1/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig62 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:811a::2/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:81{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig62' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}"
        with open("/etc/gre62.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre62_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig62 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:811a::1/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig62 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:811a::2/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}"
        with open("/etc/gre62.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping2_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre62_kharej():
    remote_ip = "2002:811b::2"  # iran-ip
    local_ip = "2002:811b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre62_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:811a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre62_service()

    gre62_cronjob()


def gre62_kharejsec():
    remote_ip = "2002:811b::2"  # iran-ip
    local_ip = "2002:811b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre62_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:811a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre62_service()

    gre62_cronjob()


def kharej_gre62_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[2]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::2/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre62_kharej()
    sleep(1)


## kharej 2 for iran 2
def kharej2_gre62_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[2]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::2/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre62_kharej()
    sleep(1)


# edit
def kharej2_gre62_edit():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[2]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k2(psk)
    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre62_kharej()
    sleep(1)


##kharej3
def run3_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:821b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v63_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v63.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v63.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v63.service"])
    subprocess.run(["systemctl", "start", "ping_v63.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v63.service"])


def display_kharej3_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:821b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron3_job():
    file_path = "/etc/private3.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre63_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre63.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre63.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre63_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip3.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip3.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip3.service"])
    subprocess.run(["systemctl", "start", "ping_ip3.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip3.service"])


def gre63_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig63 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:821a::1/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig63 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:821a::2/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:82{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig63' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}"
        with open("/etc/gre63.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre63_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig63 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:821a::1/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig63 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:821a::2/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}"
        with open("/etc/gre63.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping3_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre63_kharej():
    remote_ip = "2002:821b::2"  # iran-ip
    local_ip = "2002:821b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre63_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:821a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre63_service()

    gre63_cronjob()


def gre63_kharejsec():
    remote_ip = "2002:821b::2"  # iran-ip
    local_ip = "2002:821b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre63_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:821a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre63_service()

    gre63_cronjob()


def kharej_gre63_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[3]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::2/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre63_kharej()
    sleep(1)


## kharej 3 for iran 3
def kharej2_gre63_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[3]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::2/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre63_kharej()
    sleep(1)


# edit
def kharej2_gre63_edit():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[3]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k3(psk)
    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre63_kharej()
    sleep(1)


# kharej 4


def run4_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:831b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v64_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v64.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v64.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v64.service"])
    subprocess.run(["systemctl", "start", "ping_v64.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v64.service"])


def display_kharej4_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:831b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron4_job():
    file_path = "/etc/private4.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre64_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre64.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre64.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre64_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip4.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip4.service"])
    subprocess.run(["systemctl", "start", "ping_ip4.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip4.service"])


def gre64_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig64 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig64 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::2/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig64' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}"
        with open("/etc/gre64.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre64_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig64 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig64 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::2/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}"
        with open("/etc/gre64.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping4_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre64_kharej():
    remote_ip = "2002:831b::2"  # iran-ip
    local_ip = "2002:831b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre64_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre64_service()

    gre64_cronjob()


def gre64_kharejsec():
    remote_ip = "2002:831b::2"  # iran-ip
    local_ip = "2002:831b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre64_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre64_service()

    gre64_cronjob()


def kharej_gre64_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[4]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre64_kharej()
    sleep(1)


## kharej 4 for iran 4
def kharej2_gre64_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[4]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre64_kharej()
    sleep(1)


# edit
def kharej2_gre64_edit():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[4]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k4(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre64_kharej()
    sleep(1)


# kharej 5


def run5_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:841b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v65_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v65.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v65.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v65.service"])
    subprocess.run(["systemctl", "start", "ping_v65.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v65.service"])


def display_kharej5_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:841b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron5_job():
    file_path = "/etc/private5.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre65_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre65.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre65.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre65_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip5.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip5.service"])
    subprocess.run(["systemctl", "start", "ping_ip5.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip5.service"])


def gre65_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig65 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:841a::1/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig65 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:841a::2/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:84{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig65' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}"
        with open("/etc/gre65.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre65_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig65 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:841a::1/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig65 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:841a::2/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}"
        with open("/etc/gre65.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping5_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre65_kharej():
    remote_ip = "2002:841b::2"  # iran-ip
    local_ip = "2002:841b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre65_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:841a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre65_service()

    gre65_cronjob()


def gre65_kharejsec():
    remote_ip = "2002:841b::2"  # iran-ip
    local_ip = "2002:841b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre65_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:841a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre65_service()

    gre65_cronjob()


def kharej_gre65_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[5]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::2/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre65_kharej()
    sleep(1)


## kharej 5 for iran 5
def kharej2_gre65_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[5]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::2/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre65_kharej()
    sleep(1)


# edit
def kharej2_gre65_edit():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[5]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6k5(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre65_kharej()
    sleep(1)


# kharej 6


def run6_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:851b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v66_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v66.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v66.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v66.service"])
    subprocess.run(["systemctl", "start", "ping_v66.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v66.service"])


def display_kharej6_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:851b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron6_job():
    file_path = "/etc/private6.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre66_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre66.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre66.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre66_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip6.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip6.service"])
    subprocess.run(["systemctl", "start", "ping_ip6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip6.service"])


def gre66_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre66.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig66 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:851a::1/64 dev azumig66' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig66 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:851a::2/64 dev azumig66' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:85{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig66' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig66 mtu {mtu_value}"
        with open("/etc/gre66.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 6:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:851a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping6_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre66_kharej():
    remote_ip = "2002:851b::2"  # iran-ip
    local_ip = "2002:851b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre66_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:851a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping6_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre66_service()

    gre66_cronjob()


def kharej_gre66_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[6]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::2/64", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi6\n")
        f.write("ip -6 route add 2002:851b::2/64 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping6()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre66_kharej()
    sleep(1)


## kharej 6 for iran 6
def kharej2_gre66_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[6]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::2/64", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi6\n")
        f.write("ip -6 route add 2002:851b::2/64 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping6()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre66_kharej()
    sleep(1)


# kharej 7


def run7_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:861b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v67_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v67.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v67.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v67.service"])
    subprocess.run(["systemctl", "start", "ping_v67.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v67.service"])


def display_kharej7_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:861b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron7_job():
    file_path = "/etc/private7.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre67_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre67.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre67.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre67_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip7.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip7.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip7.service"])
    subprocess.run(["systemctl", "start", "ping_ip7.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip7.service"])


def gre67_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre67.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig67 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:861a::1/64 dev azumig67' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig67 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:861a::2/64 dev azumig67' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:86{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig67' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig67 mtu {mtu_value}"
        with open("/etc/gre67.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 7:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:861a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping7_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip7.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre67_kharej():
    remote_ip = "2002:861b::2"  # iran-ip
    local_ip = "2002:861b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre67_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:861a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping7_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre67_service()

    gre67_cronjob()


def kharej_gre67_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[7]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::2/64", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi7\n")
        f.write("ip -6 route add 2002:861b::2/64 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping7()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre67_kharej()
    sleep(1)


## kharej 7 for iran 7
def kharej2_gre67_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[7]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::2/64", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi7\n")
        f.write("ip -6 route add 2002:861b::2/64 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping7()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre67_kharej()
    sleep(1)


# kharej 8


def run8_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:871b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v68_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v68.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v68.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v68.service"])
    subprocess.run(["systemctl", "start", "ping_v68.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v68.service"])


def display_kharej8_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:871b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron8_job():
    file_path = "/etc/private8.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre68_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre68.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre68.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre68_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip8.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip8.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip8.service"])
    subprocess.run(["systemctl", "start", "ping_ip8.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip8.service"])


def gre68_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre68.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig68 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:871a::1/64 dev azumig68' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig68 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:871a::2/64 dev azumig68' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:87{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig68' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig68 mtu {mtu_value}"
        with open("/etc/gre68.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 8:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:871a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping8_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip8.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre68_kharej():
    remote_ip = "2002:871b::2"  # iran-ip
    local_ip = "2002:871b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre68_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:871a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping8_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre68_service()

    gre68_cronjob()


def kharej_gre68_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[8]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::2/64", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi8\n")
        f.write("ip -6 route add 2002:871b::2/64 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping8()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre68_kharej()
    sleep(1)


## kharej 8 for iran 8
def kharej2_gre68_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[8]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::2/64", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi8\n")
        f.write("ip -6 route add 2002:871b::2/64 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping8()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre68_kharej()
    sleep(1)


# kharej 9


def run9_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:881b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v69_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v69.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v69.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v69.service"])
    subprocess.run(["systemctl", "start", "ping_v69.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v69.service"])


def display_kharej9_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:881b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron9_job():
    file_path = "/etc/private9.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre69_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre69.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre69.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre69_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip9.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip9.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip9.service"])
    subprocess.run(["systemctl", "start", "ping_ip9.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip9.service"])


def gre69_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre69.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig69 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:881a::1/64 dev azumig69' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig69 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:881a::2/64 dev azumig69' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:88{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig69' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig69 mtu {mtu_value}"
        with open("/etc/gre69.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 9:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:881a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping9_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip9.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre69_kharej():
    remote_ip = "2002:881b::2"  # iran-ip
    local_ip = "2002:881b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre69_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:881a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping9_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre69_service()

    gre69_cronjob()


def kharej_gre69_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[9]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:881b::2/64", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::1/64 dev azumi9\n")
        f.write("ip -6 route add 2002:881b::2/64 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping9()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:881b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre69_kharej()
    sleep(1)


## kharej 9 for iran 9
def kharej2_gre69_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[9]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:881b::2/64", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::1/64 dev azumi9\n")
        f.write("ip -6 route add 2002:881b::2/64 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping9()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:881b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre69_kharej()
    sleep(1)


# kharej 10


def run10_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:891b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v610_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v610.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v610.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v610.service"])
    subprocess.run(["systemctl", "start", "ping_v610.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v610.service"])


def display_kharej10_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:891b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron10_job():
    file_path = "/etc/private10.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gre610_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre610.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre610.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre610_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip10.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip10.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip10.service"])
    subprocess.run(["systemctl", "start", "ping_ip10.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip10.service"])


def gre610_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre610.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig610 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:891a::1/64 dev azumig610' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig610 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:891a::2/64 dev azumig610' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:89{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig610' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig610 mtu {mtu_value}"
        with open("/etc/gre610.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 10:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:891a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping10_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip10.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre610_kharej():
    remote_ip = "2002:891b::2"  # iran-ip
    local_ip = "2002:891b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre610_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:891a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping10_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre610_service()

    gre610_cronjob()


def kharej_gre610_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[10]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:891b::2/64", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::1/64 dev azumi10\n")
        f.write("ip -6 route add 2002:891b::2/64 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping10()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:891b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre610_kharej()
    sleep(1)


## kharej 10 for iran 10
def kharej2_gre610_menu():
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej[10]\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:891b::2/64", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::1/64 dev azumi10\n")
        f.write("ip -6 route add 2002:891b::2/64 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping10()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:891b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre610_kharej()
    sleep(1)


##### IRAN gre6 server 1
def iran_ping1():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:801b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran1_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:801b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre61_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip1.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip1.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip1.service"])
    subprocess.run(["systemctl", "start", "ping_ip1.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip1.service"])


def gre61_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig61 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:801a::2/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig61 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:801a::1/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:80{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig61' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}"
        with open("/etc/gre61.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:801a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre61_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig61 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:801a::2/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig61 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:801a::1/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}"
        with open("/etc/gre61.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:801a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##default route iran server 1
def gre61_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig61 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:801a::2/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig61 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:801a::1/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:80{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig61' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open("/etc/gre61.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:801a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre61_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig61 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:801a::2/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig61 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:801a::1/64 dev azumig61' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open("/etc/gre61.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:801a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping1_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre61_iran():
    remote_ip = "2002:801b::1"  # kharej ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre61_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:801a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre61_service()

    gre61_cronjob()


def gre61_iransec():
    remote_ip = "2002:801b::1"  # kharej ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre61_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:801a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre61_service()

    gre61_cronjob()


## default route iran1
def gre61_iran2():
    remote_ip = "2002:801b::1"  # kharej ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre61_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:801a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre61_service()

    gre61_cronjob()


def gre61_iran2sec():
    remote_ip = "2002:801b::1"  # kharej ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre61_iran2_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:801a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre61_service()

    gre61_cronjob()


def iran_gre61_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE \033[96m Server\033[92m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre61_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


##default route iran1 command
def iran2_gre61_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE \033[96m Server\033[92m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m [1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre61_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


##### IRAN gre6 server 2
def iran_ping2():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:811b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran2_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:811b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre62_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip2.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip2.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip2.service"])
    subprocess.run(["systemctl", "start", "ping_ip2.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip2.service"])


def gre62_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig62 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:811a::2/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig62 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:811a::1/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:81{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig62' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}"
        with open("/etc/gre62.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre62_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig62 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:811a::2/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig62 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:811a::1/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}"
        with open("/etc/gre62.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route iran server 2
def gre62_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig62 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:811a::2/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig62 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:811a::1/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:81{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig62' >> {file_path}"
        subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open("/etc/gre62.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre62_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig62 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:811a::2/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig62 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:811a::1/64 dev azumig62' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    subprocess.run(f"bash {file_path}", shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open("/etc/gre62.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping2_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre62_iran():
    remote_ip = "2002:811b::1"  # kharej ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre62_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:811a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre62_service()

    gre62_cronjob()


def gre62_iransec():
    remote_ip = "2002:811b::1"  # kharej ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre62_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:811a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre62_service()

    gre62_cronjob()


# default route server iran 2
def gre62_iran2():
    remote_ip = "2002:811b::1"  # kharej ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre62_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:811a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre62_service()

    gre62_cronjob()


def gre62_iran2sec():
    remote_ip = "2002:811b::1"  # kharej ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre62_iran2_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:811a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre62_service()

    gre62_cronjob()


def iran_gre62_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::1/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre62_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# edit
def iran_gre62_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i2(psk)
    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre62_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route iran 2 menu
def iran2_gre62_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::1/64 dev azumi2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre62_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


##### IRAN gre6 server 3
def iran_ping3():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:821b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran3_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:821b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre63_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip3.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip3.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip3.service"])
    subprocess.run(["systemctl", "start", "ping_ip3.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip3.service"])


def gre63_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig63 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:821a::2/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig63 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:821a::1/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:82{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig63' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}"
        with open("/etc/gre63.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre63_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig63 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:821a::2/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig63 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:821a::1/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}"
        with open("/etc/gre63.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 3


def gre63_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig63 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:821a::2/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig63 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:821a::1/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:82{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig63' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig63 mtu {mtu_value}\n"
        with open("/etc/gre63.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre63_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig63 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:821a::2/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig63 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:821a::1/64 dev azumig63' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig63 mtu {mtu_value}\n"
        with open("/etc/gre63.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping3_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre63_iran():
    remote_ip = "2002:821b::1"  # kharej ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre63_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:821a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre63_service()

    gre63_cronjob()


def gre63_iransec():
    remote_ip = "2002:821b::1"  # kharej ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre63_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:821a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre63_service()

    gre63_cronjob()


## default route iran server 3
def gre63_iran2():
    remote_ip = "2002:821b::1"  # kharej ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre63_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:821a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre63_service()

    gre63_cronjob()


def gre63_iran2sec():
    remote_ip = "2002:821b::1"  # kharej ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre63_iran2_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:821a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre63_service()

    gre63_cronjob()


def iran_gre63_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre63_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# edit
def iran_gre63_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i3(psk)
    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre63_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre63_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre63_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# iran4gre
##### IRAN gre6 server 4
def iran_ping4():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:831b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran4_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:831b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre64_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip4.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip4.service"])
    subprocess.run(["systemctl", "start", "ping_ip4.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip4.service"])


def gre64_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig64 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig64 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::1/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig64' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}"
        with open("/etc/gre64.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre64_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig64 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig64 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::1/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}"
        with open("/etc/gre64.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 4


def gre64_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig64 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig64 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::1/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig64' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig64 mtu {mtu_value}\n"
        with open("/etc/gre64.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre64_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig64 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig64 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::1/64 dev azumig64' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig64 mtu {mtu_value}\n"
        with open("/etc/gre64.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping4_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre64_iran():
    remote_ip = "2002:831b::1"  # kharej ip
    local_ip = "2002:831b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre64_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre64_service()

    gre64_cronjob()


def gre64_iransec():
    remote_ip = "2002:831b::1"  # kharej ip
    local_ip = "2002:831b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre64_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre64_service()

    gre64_cronjob()


## default route iran server 4
def gre64_iran2():
    remote_ip = "2002:831b::1"  # kharej ip
    local_ip = "2002:831b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre64_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre64_service()

    gre64_cronjob()


def gre64_iran2sec():
    remote_ip = "2002:831b::1"  # kharej ip
    local_ip = "2002:831b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre64_iran2_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre64_service()

    gre64_cronjob()


def iran_gre64_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre64_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# edit
def iran_gre64_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i4(psk)
    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre64_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre64_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre64_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")



# iran5gre
##### IRAN gre6 server 5
def iran_ping5():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:841b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran5_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:841b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre65_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip5.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip5.service"])
    subprocess.run(["systemctl", "start", "ping_ip5.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip5.service"])


def gre65_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig65 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:841a::2/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig65 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:841a::1/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:84{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig65' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}"
        with open("/etc/gre65.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre65_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig65 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:841a::2/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig65 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:841a::1/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}"
        with open("/etc/gre65.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 5


def gre65_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig65 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:841a::2/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig65 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:841a::1/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:84{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig65' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig65 mtu {mtu_value}\n"
        with open("/etc/gre65.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre65_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig65 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:841a::2/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig65 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:841a::1/64 dev azumig65' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig65 mtu {mtu_value}\n"
        with open("/etc/gre65.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping5_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre65_iran():
    remote_ip = "2002:841b::1"  # kharej ip
    local_ip = "2002:841b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre65_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre65_service()

    gre65_cronjob()


def gre65_iransec():
    remote_ip = "2002:841b::1"  # kharej ip
    local_ip = "2002:841b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre65_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre65_service()

    gre65_cronjob()


## default route iran server 4
def gre65_iran2():
    remote_ip = "2002:841b::1"  # kharej ip
    local_ip = "2002:841b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre65_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre65_service()

    gre65_cronjob()


def gre65_iran2sec():
    remote_ip = "2002:841b::1"  # kharej ip
    local_ip = "2002:841b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre65_iran2_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre65_service()

    gre65_cronjob()


def iran_gre65_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre65_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# edit
def iran_gre65_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_gre6i5(psk)
    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre65_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre65_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre65_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# iran6gre
##### IRAN gre6 server 6
def iran_ping6():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:851b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran6_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:851b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre66_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip6.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip6.service"])
    subprocess.run(["systemctl", "start", "ping_ip6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip6.service"])


def gre66_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre66.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig66 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:851a::2/64 dev azumig66' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig66 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:851a::1/64 dev azumig66' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:85{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig66' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig66 mtu {mtu_value}"
        with open("/etc/gre66.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 6:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:851a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 5


def gre66_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre66.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig66 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:851a::2/64 dev azumig66' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig66 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:851a::1/64 dev azumig66' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:85{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig66' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig66 mtu {mtu_value}\n"
        with open("/etc/gre66.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 6:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:851a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping6_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre66_iran():
    remote_ip = "2002:851b::1"  # kharej ip
    local_ip = "2002:851b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre66_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:851a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping6_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre66_service()

    gre66_cronjob()


## default route iran server 6
def gre66_iran2():
    remote_ip = "2002:851b::1"  # kharej ip
    local_ip = "2002:851b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre66_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:851a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping6_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre66_service()

    gre66_cronjob()


def iran_gre66_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[6]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::1/64", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi6\n")
        f.write("ip -6 route add 2002:851b::1/64 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping6()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:851b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre66_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre66_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[6]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::1/64", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi6\n")
        f.write("ip -6 route add 2002:851b::1/64 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping6()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:851b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre66_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# iran7gre
##### IRAN gre6 server 7
def iran_ping7():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:861b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran7_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:861b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre67_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip7.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip7.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip7.service"])
    subprocess.run(["systemctl", "start", "ping_ip7.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip7.service"])


def gre67_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre67.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig67 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:861a::2/64 dev azumig67' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig67 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:861a::1/64 dev azumig67' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:86{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig67' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig67 mtu {mtu_value}"
        with open("/etc/gre67.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 7:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:861a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 7


def gre67_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre67.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig67 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:861a::2/64 dev azumig67' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig67 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:861a::1/64 dev azumig67' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:86{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig67' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig67 mtu {mtu_value}\n"
        with open("/etc/gre67.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 7:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:861a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping7_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip7.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre67_iran():
    remote_ip = "2002:861b::1"  # kharej ip
    local_ip = "2002:861b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre67_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:861a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping7_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre67_service()

    gre67_cronjob()


## default route iran server 7
def gre67_iran2():
    remote_ip = "2002:861b::1"  # kharej ip
    local_ip = "2002:861b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre67_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:861a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping7_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre67_service()

    gre67_cronjob()


def iran_gre67_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[7]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::1/64", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi7\n")
        f.write("ip -6 route add 2002:861b::1/64 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping7()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:861b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre67_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre67_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[7]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::1/64", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi7\n")
        f.write("ip -6 route add 2002:861b::1/64 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping7_script()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:861b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre67_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# iran8gre
##### IRAN gre6 server 8
def iran_ping8():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:871b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran8_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:871b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre68_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip8.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip8.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip8.service"])
    subprocess.run(["systemctl", "start", "ping_ip8.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip8.service"])


def gre68_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre68.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig68 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:871a::2/64 dev azumig68' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig68 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:871a::1/64 dev azumig68' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:87{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig68' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig68 mtu {mtu_value}"
        with open("/etc/gre68.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 8:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:871a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 8


def gre68_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre68.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig68 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:871a::2/64 dev azumig68' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig68 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:871a::1/64 dev azumig68' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:87{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig68' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig68 mtu {mtu_value}\n"
        with open("/etc/gre68.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 8:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:871a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping8_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip8.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre68_iran():
    remote_ip = "2002:871b::1"  # kharej ip
    local_ip = "2002:871b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre68_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:871a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping8_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre68_service()

    gre68_cronjob()


## default route iran server 8
def gre68_iran2():
    remote_ip = "2002:871b::1"  # kharej ip
    local_ip = "2002:871b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre68_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:871a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping8_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre68_service()

    gre68_cronjob()


def iran_gre68_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[8]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::1/64", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi8\n")
        f.write("ip -6 route add 2002:871b::1/64 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping8()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:871b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre68_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre68_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[8]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::1/64", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi8\n")
        f.write("ip -6 route add 2002:871b::1/64 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping8_script()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:871b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre68_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# iran9gre
##### IRAN gre6 server 9
def iran_ping9():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:881b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran9_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:881b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre69_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip9.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip9.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip9.service"])
    subprocess.run(["systemctl", "start", "ping_ip9.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip9.service"])


def gre69_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre69.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig69 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:881a::2/64 dev azumig69' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig69 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:881a::1/64 dev azumig69' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:88{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig69' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig69 mtu {mtu_value}"
        with open("/etc/gre69.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 9:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:881a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 9


def gre69_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre69.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig69 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:881a::2/64 dev azumig69' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig69 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:881a::1/64 dev azumig69' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:88{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig69' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig69 mtu {mtu_value}\n"
        with open("/etc/gre69.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 9:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:881a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping9_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip9.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre69_iran():
    remote_ip = "2002:881b::1"  # kharej ip
    local_ip = "2002:881b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre69_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:881a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping9_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre69_service()

    gre69_cronjob()


## default route iran server 9
def gre69_iran2():
    remote_ip = "2002:881b::1"  # kharej ip
    local_ip = "2002:881b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre69_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:881a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping9_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre69_service()

    gre69_cronjob()


def iran_gre69_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[9]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:881b::1/64", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::2/64 dev azumi9\n")
        f.write("ip -6 route add 2002:881b::1/64 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping9()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:881b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre69_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre69_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[9]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:881b::1/64", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::2/64 dev azumi9\n")
        f.write("ip -6 route add 2002:881b::1/64 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping9_script()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:881b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre69_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# iran10gre
##### IRAN gre6 server 10
def iran_ping10():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:891b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran10_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    ip_addr = "2002:891b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre610_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip10.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip10.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip10.service"])
    subprocess.run(["systemctl", "start", "ping_ip10.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip10.service"])


def gre610_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre610.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig610 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:891a::2/64 dev azumig610' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig610 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:891a::1/64 dev azumig610' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:89{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig610' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig610 mtu {mtu_value}"
        with open("/etc/gre610.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 10:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:891a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


## default route server iran 10


def gre610_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre610.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig610 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:891a::2/64 dev azumig610' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig610 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:891a::1/64 dev azumig610' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:89{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig610' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = "ip link set dev azumig610 mtu {mtu_value}\n"
        with open("/etc/gre610.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 10:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:891a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping10_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip10.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre610_iran():
    remote_ip = "2002:891b::1"  # kharej ip
    local_ip = "2002:891b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre610_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:891a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping10_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre610_service()

    gre610_cronjob()


## default route iran server 10
def gre610_iran2():
    remote_ip = "2002:891b::1"  # kharej ip
    local_ip = "2002:891b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre610_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:891a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping10_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre610_service()

    gre610_cronjob()


def iran_gre610_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[10]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:891b::1/64", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::2/64 dev azumi10\n")
        f.write("ip -6 route add 2002:891b::1/64 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping10()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:891b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre610_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# default route
def iran2_gre610_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[96m Server\033[92m[10]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:891b::1/64", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::2/64 dev azumi10\n")
        f.write("ip -6 route add 2002:891b::1/64 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping10_script()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:891b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre610_iran2()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


## 10
def priv_mnu_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mPrivateIP \033[92m Multiple Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[96mKharej\033[92m[10] \033[93mIRAN\033[92m[1]\033[0m")
    print("2. \033[96mKharej\033[92m[1] \033[93mIRAN\033[92m[5]  \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_kh_ip()
            break
        elif server_type == "2":
            priv_ir_ip()
            break
        elif server_type == "0":
            os.system("clear")
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def priv_kh_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mPrivate IP \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_reset_rmvmnu()
            kharej1_private_menu()
            break
        elif server_type == "2":
            private_reset_rmvmnu()
            kharej2_private_menu()
            break
        elif server_type == "3":
            private_reset_rmvmnu()
            kharej3_private_menu()
            break
        elif server_type == "4":
            private_reset_rmvmnu()
            kharej4_private_menu()
            break
        elif server_type == "5":
            private_reset_rmvmnu()
            kharej5_private_menu()
            break
        elif server_type == "6":
            private_reset_rmvmnu()
            kharej6_private_menu()
            break
        elif server_type == "7":
            private_reset_rmvmnu()
            kharej7_private_menu()
            break
        elif server_type == "8":
            private_reset_rmvmnu()
            kharej8_private_menu()
            break
        elif server_type == "9":
            private_reset_rmvmnu()
            kharej9_private_menu()
            break
        elif server_type == "10":
            private_reset_rmvmnu()
            kharej10_private_menu()
            break
        elif server_type == "11":
            private_reset_rmvmnu()
            kharej_q()
            break
        elif server_type == "0":
            os.system("clear")
            priv_mnu_ip()
            break
        else:
            print("Invalid choice.")


def kharej_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mkharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "iran{}_private_menu".format(i)
        globals()[menu_name]()


def priv_ir_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mPrivate IP \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_reset_rmvmnu()
            iran1_private2_menu()
            break
        elif server_type == "2":
            private_reset_rmvmnu()
            iran2_private2_menu()
            break
        elif server_type == "3":
            private_reset_rmvmnu()
            iran3_private2_menu()
            break
        elif server_type == "4":
            private_reset_rmvmnu()
            iran4_private2_menu()
            break
        elif server_type == "5":
            private_reset_rmvmnu()
            iran5_private2_menu()
            break
        elif server_type == "6":
            private_reset_rmvmnu()
            iran_q()
            break
        elif server_type == "0":
            os.system("clear")
            priv_mnu_ip()
            break
        else:
            print("Invalid choice.")


def iran_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "kharej{}_private2_menu".format(i)
        globals()[menu_name]()


## Kharej 1
def add_cron1_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private1.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private1.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping1():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:801b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping1():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:831b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v61_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v61.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v61.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v61.service"])
    subprocess.run(["systemctl", "start", "ping_v61.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v61.service"])


def kharej1_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [1]...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi1"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi1"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:80{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej1 for iran 1
def kharej1_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [1]...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi1"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi1"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:80{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## Kharej 2
def add_cron2_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private2.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private2.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping2():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:811b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping2():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:841b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v62_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v62.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v62.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v62.service"])
    subprocess.run(["systemctl", "start", "ping_v62.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v62.service"])


def kharej2_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [2]...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi2"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi2"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:81{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 2 for iran 2


def kharej2_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [2]...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi2"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi2"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:81{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# edit
def kharej2_private2_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [2]...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik2(psk)
    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi2"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi2"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:81{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## Kharej 3
def add_cron3_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private3.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private3.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping3():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:821b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping3():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:851b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v63_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v63.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v63.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v63.service"])
    subprocess.run(["systemctl", "start", "ping_v63.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v63.service"])


def kharej3_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [3]...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi3"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi3"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:82{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 3 for iran 3


def kharej3_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [3]...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi3"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi3"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:82{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# edit
def kharej3_private2_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [3]...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik3(psk)
    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi3"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi3"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:82{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## Kharej 4
def add_cron4_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private4.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private4.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping4():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:831b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping4():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:861b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v64_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v64.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v64.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v64.service"])
    subprocess.run(["systemctl", "start", "ping_v64.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v64.service"])


def kharej4_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [4]...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi4"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi4"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:83{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 4 for iran 4
def kharej4_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [4]...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi4"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi4"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:83{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# edit
def kharej4_private2_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [4]...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik4(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi4"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi4"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:83{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## Kharej 5
def add_cron5_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private5.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private5.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping5():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:841b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping5():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:871b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v65_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v65.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v65.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v65.service"])
    subprocess.run(["systemctl", "start", "ping_v65.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v65.service"])


def kharej5_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [5]...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi5"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi5"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:84{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 5 for iran 5
def kharej5_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [5]...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi5"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi5"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:84{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# edit
def kharej5_private2_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [5]...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik5(psk)
    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi5"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi5"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:84{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## Kharej 6
def add_cron6_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private6.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private6.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping6():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:851b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v66_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v66.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v66.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v66.service"])
    subprocess.run(["systemctl", "start", "ping_v66.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v66.service"])


def kharej6_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[6]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [6]...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi6"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi6"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:85{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping6()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 6 for iran 6
def kharej6_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[6]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [6]...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[6]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi6"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi6"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:85{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping6()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 7
def add_cron7_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private7.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private7.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping7():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:861b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v67_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v67.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v67.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v67.service"])
    subprocess.run(["systemctl", "start", "ping_v67.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v67.service"])


def kharej7_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[7]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [7]...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi7"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi7"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:86{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping7()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 7 for iran 7
def kharej7_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[7]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [7]...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[7]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi7"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi7"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:86{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping7()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 8
def add_cron8_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private8.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private8.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping8():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:871b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v68_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v68.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v68.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v68.service"])
    subprocess.run(["systemctl", "start", "ping_v68.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v68.service"])


def kharej8_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[8]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [8]...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi8"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi8"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:87{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping8()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 8 for iran 8
def kharej8_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[8]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [8]...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[8]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi8"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi8"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:87{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping8()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 9


def add_cron9_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private9.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private9.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping9():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:881b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v69_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v69.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v69.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v69.service"])
    subprocess.run(["systemctl", "start", "ping_v69.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v69.service"])


def kharej9_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[9]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [9]...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi9"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi9"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::1/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:88{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping9()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:881b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 9 for iran 9
def kharej9_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[9]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [9]...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[9]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi9"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi9"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::1/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:88{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping9()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:881b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 10


def add_cron10_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private10.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private10.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def run_ping10():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:891b::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v610_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v610.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v610.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v610.service"])
    subprocess.run(["systemctl", "start", "ping_v610.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v610.service"])


def kharej10_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[10]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [10]...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi10"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi10"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::1/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:89{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping10()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:891b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 10 for iran 10
def kharej10_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[10]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [10]...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[10]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi10"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi10"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::1/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:89{ip_suffix}b::1/64"
            f.write(f"ip addr add {ip_addr} dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping10()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:891b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## IRAN1
def run_ping1_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:801b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping1_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:831b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran1_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[1]...\033[0m")

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi1"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi1"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:80{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping1_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:801b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()


## route for iran1_private_menu
def iran1_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[1]...\033[0m")

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi1"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi1"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:80{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi1\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:801b::2\n".format(
                interface
            )
        with open("/etc/private1.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping1_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:80{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:801b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()


## IRAN2
def run_ping2_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:811b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping2_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:841b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran2_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[2]...\033[0m")

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi2"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi2"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:81{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping2_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:811b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()


## default route iran2_private_menu
def iran2_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[2]...\033[0m")

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi2"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi2"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:81{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi2\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:811b::2\n".format(
                interface
            )
        with open("/etc/private2.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping2_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:81{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:811b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()


## IRAN3
def run_ping3_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:821b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping3_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:851b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran3_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[3]...\033[0m")

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi3"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi3"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:82{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping3_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:821b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()


## default route iran3_private_menu
def iran3_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[3]...\033[0m")

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi3"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi3"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:82{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi3\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:821b::2\n".format(
                interface
            )
        with open("/etc/private3.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping3_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:82{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:821b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()


## IRAN4
def run_ping4_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:831b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping4_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:861b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran4_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[4]...\033[0m")

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi4"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi4"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:83{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping4_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:831b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()


##default route iran4_private_menu
def iran4_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[4]...\033[0m")

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi4"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi4"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:83{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi4\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831b::2\n".format(
                interface
            )
        with open("/etc/private4.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping4_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:831b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()


## IRAN5
def run_ping5_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:841b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def runsec_ping5_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:871b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran5_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[5]...\033[0m")

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi5"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi5"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:84{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping5_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:841b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()


# default route iran5_private_menu
def iran5_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[5]...\033[0m")

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi5"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi5"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:84{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi5\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:841b::2\n".format(
                interface
            )
        with open("/etc/private5.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping5_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:84{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:841b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()


## IRAN6
def run_ping6_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:851b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran6_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[6]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[6]...\033[0m")

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[6]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi6"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi6"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:85{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi6\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping6_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:851b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()


# default route iran6_private_menu
def iran6_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[6]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[6]...\033[0m")

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi6"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi6"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi6"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:85{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi6\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:851b::2\n".format(
                interface
            )
        with open("/etc/private6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping6_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:85{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:851b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()


## IRAN7
def run_ping7_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:861b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran7_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[7]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[7]...\033[0m")

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[7]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi7"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi7"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:86{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi7\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping7_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:861b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()


# default route iran7_private_menu
def iran7_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[7]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[7]...\033[0m")

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi7"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi7"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi7"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:86{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi7\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:861b::2\n".format(
                interface
            )
        with open("/etc/private7.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping7_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:86{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:861b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()


## IRAN8
def run_ping8_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:871b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran8_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[8]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[8]...\033[0m")

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[8]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi8"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi8"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:87{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi8\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping8_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:871b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()


# default route iran8_private_menu
def iran8_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[8]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[8]...\033[0m")

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi8"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi8"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi8"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:87{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi8\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:871b::2\n".format(
                interface
            )
        with open("/etc/private8.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping8_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:87{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:871b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()


## IRAN9
def run_ping9_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:881b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran9_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[9]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[9]...\033[0m")

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[9]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi9"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi9"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::2/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:88{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi9\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping9_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:881b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()


# default route iran9_private_menu
def iran9_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[9]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[9]...\033[0m")

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi9"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi9"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi9"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::2/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:88{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi9\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:881b::2\n".format(
                interface
            )
        with open("/etc/private9.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping9_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:88{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:881b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()


## IRAN10
def run_ping10_iran():
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2002:891b::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran10_private_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[10]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[10]...\033[0m")

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[10]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi10"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi10"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::2/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:89{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi10\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping10_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:891b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()


# default route iran10_private_menu
def iran10_private2_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[10]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[10]...\033[0m")

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi10"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input(
            "\033[93mHow many \033[92madditional private IPs\033[93m do you need? \033[0m"
        )
    )
    print("\033[93m─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "addr", "show", "dev", "azumi10"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "addr", "add", ip_addr, "dev", "azumi10"],
                stdout=subprocess.DEVNULL,
            )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::2/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:89{ip_suffix}b::2/64"
            f.write(f"ip addr add {ip_addr} dev azumi10\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:891b::2\n".format(
                interface
            )
        with open("/etc/private10.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping10_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:89{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:891b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()


##1010
def add_cron6_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private6.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private6.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def add_cron7_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private7.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private7.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def add_cron8_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private8.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private8.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def add_cron9_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private9.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private9.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def add_cron10_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private10.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private10.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_v66_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v66.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v66.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v66.service"])
    subprocess.run(["systemctl", "start", "ping_v66.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v66.service"])


def ping_v67_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v67.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v67.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v67.service"])
    subprocess.run(["systemctl", "start", "ping_v67.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v67.service"])


def ping_v68_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v68.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v68.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v68.service"])
    subprocess.run(["systemctl", "start", "ping_v68.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v68.service"])


def ping_v69_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v69.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v69.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v69.service"])
    subprocess.run(["systemctl", "start", "ping_v69.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v69.service"])


def ping_v610_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v610.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v610.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v610.service"])
    subprocess.run(["systemctl", "start", "ping_v610.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v610.service"])


def ip6_mnu_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIP6IP6 \033[92m Multiple Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[96mKHAREJ\033[92m[10]  \033[93mIRAN\033[92m[1]\033[0m")
    print("2. \033[96mKHAREJ\033[92m[1]  \033[93mIRAN\033[92m[10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ip6_kh_ip()
            break
        elif server_type == "2":
            ip6_ir_ip()
            break
        elif server_type == "0":
            os.system("clear")
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def ip6_kh_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[10]Kharej\033[96m [1]IRAN\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN\033[0m")
    print("0.\033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnu()
            kharej_ipip61_menu()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnu()
            kharej_ipip62_menu()
            break
        elif server_type == "3":
            ipip6_reset_rmvmnu()
            kharej_ipip63_menu()
            break
        elif server_type == "4":
            ipip6_reset_rmvmnu()
            kharej_ipip64_menu()
            break
        elif server_type == "5":
            ipip6_reset_rmvmnu()
            kharej_ipip65_menu()
            break
        elif server_type == "6":
            ipip6_reset_rmvmnu()
            kharej_ipip66_menu()
            break
        elif server_type == "7":
            ipip6_reset_rmvmnu()
            kharej_ipip67_menu()
            break
        elif server_type == "8":
            ipip6_reset_rmvmnu()
            kharej_ipip68_menu()
            break
        elif server_type == "9":
            ipip6_reset_rmvmnu()
            kharej_ipip69_menu()
            break
        elif server_type == "10":
            ipip6_reset_rmvmnu()
            kharej_ipip610_menu()
            break
        elif server_type == "11":
            ipip6_reset_rmvmnu()
            kharejip_q()
            break
        elif server_type == "0":
            os.system("clear")
            ip6_mnu_ip()
            break
        else:
            print("Invalid choice.")


def kharejip_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "iran_ipip6{}_menu".format(i)
        globals()[menu_name]()


def ip6_ir_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 \033[92m[10]IRAN\033[96m [1]Kharej\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[92mIRAN[6]\033[0m")
    print("7. \033[92mIRAN[7]\033[0m")
    print("8. \033[93mIRAN[8]\033[0m")
    print("9. \033[92mIRAN[9]\033[0m")
    print("10.\033[92mIRAN[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnu()
            iran2_ipip61_menu()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnu()
            iran2_ipip62_menu()
            break
        elif server_type == "3":
            ipip6_reset_rmvmnu()
            iran2_ipip63_menu()
            break
        elif server_type == "4":
            ipip6_reset_rmvmnu()
            iran2_ipip64_menu()
            break
        elif server_type == "5":
            ipip6_reset_rmvmnu()
            iran2_ipip65_menu()
            break
        elif server_type == "6":
            ipip6_reset_rmvmnu()
            iran2_ipip66_menu()
            break
        elif server_type == "7":
            ipip6_reset_rmvmnu()
            iran2_ipip67_menu()
            break
        elif server_type == "8":
            ipip6_reset_rmvmnu()
            iran2_ipip68_menu()
            break
        elif server_type == "9":
            ipip6_reset_rmvmnu()
            iran2_ipip69_menu()
            break
        elif server_type == "10":
            ipip6_reset_rmvmnu()
            iran2_ipip610_menu()
            break
        elif server_type == "11":
            ipip6_reset_rmvmnu()
            iranip_q()
            break
        elif server_type == "0":
            os.system("clear")
            ip6_mnu_ip()
            break
        else:
            print("Invalid choice.")


def iranip_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "kharej2_ipip6{}_menu".format(i)
        globals()[menu_name]()


def run_ping1():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:801b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej1_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:801b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip1_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip1.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip1.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip1.service"])
    subprocess.run(["systemctl", "start", "ping_ip1.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip1.service"])


def ipip61_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip1 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a020::1/64 dev azumip1' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip1 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip1' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a02{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip1' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip1 mtu {mtu_value}\n"
        with open("/etc/ipip1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a020::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip61_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip1 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a020::1/64 dev azumip1' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip1 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 route add 2002:0db8:1234:a020::2/64 dev azumip1' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip1 mtu {mtu_value}\n"
        with open("/etc/ipip1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a020::1    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip1_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip1.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip1.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping1_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip1_kharej():
    remote_ip = "2002:801b::2"  # iran-ip
    local_ip = "2002:801b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip61_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a020::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip1_service()

    ipip1_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip1_kharejsec():
    remote_ip = "2002:801b::2"  # iran-ip
    local_ip = "2002:801b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip61_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a020::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip1_service()

    ipip1_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip61_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


## kharej 1 for iran 1
def kharej2_ipip61_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##kharej2


def run_ping2():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:811b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej2_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:811b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip2_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip2.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip2.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip2.service"])
    subprocess.run(["systemctl", "start", "ping_ip2.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip2.service"])


def ipip62_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip2 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a120::1/64 dev azumip2' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip2 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip2' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a12{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip2' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip2 mtu {mtu_value}\n"
        with open("/etc/ipip2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a120::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip62_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip2 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a120::1/64 dev azumip2' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip2 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 route add 2002:0db8:1234:a120::2/64 dev azumip2' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip2 mtu {mtu_value}\n"
        with open("/etc/ipip2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a120::1    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip2_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip2.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip2.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping2_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip2_kharej():
    remote_ip = "2002:811b::2"  # iran-ip
    local_ip = "2002:811b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip62_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a120::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip2_service()

    ipip2_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip2_kharejsec():
    remote_ip = "2002:811b::2"  # iran-ip
    local_ip = "2002:811b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip62_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a120::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip2_service()

    ipip2_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip62_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 2 for iran 2
def kharej2_ipip62_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##kharej3


def run_ping3():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:821b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej3_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:821b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip3_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip3.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip3.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip3.service"])
    subprocess.run(["systemctl", "start", "ping_ip3.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip3.service"])


def ipip63_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip3 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a220::1/64 dev azumip3' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip3 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip3' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a22{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip3' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip3 mtu {mtu_value}\n"
        with open("/etc/ipip3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a220::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip63_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip3 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a220::1/64 dev azumip3' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip3 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 route add 2002:0db8:1234:a020::2/64 dev azumip3' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip3 mtu {mtu_value}\n"
        with open("/etc/ipip3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a220::1    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip3_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip3.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip3.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping3_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip3_kharej():
    remote_ip = "2002:821b::2"  # iran-ip
    local_ip = "2002:821b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip63_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a220::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip3_service()

    ipip3_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip3_kharejsec():
    remote_ip = "2002:821b::2"  # iran-ip
    local_ip = "2002:821b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip63_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a220::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip3_service()

    ipip3_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip63_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 3 for iran 3


def kharej2_ipip63_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##kharej3


def run_ping3():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:821b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej3_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:821b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip3_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip3.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip3.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip3.service"])
    subprocess.run(["systemctl", "start", "ping_ip3.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip3.service"])


def ipip63_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip3 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a220::1/64 dev azumip3' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip3 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip3' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a22{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip3' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip3 mtu {mtu_value}\n"
        with open("/etc/ipip3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a220::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip3_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip3.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip3.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping3_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip3_kharej():
    remote_ip = "2002:821b::2"  # iran-ip
    local_ip = "2002:821b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip63_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a220::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip3_service()

    ipip3_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip63_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 3 for iran 3


def kharej2_ipip63_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 4


def run_ping4():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:831b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej4_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:831b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip4_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip4.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip4.service"])
    subprocess.run(["systemctl", "start", "ping_ip4.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip4.service"])


def ipip64_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip4 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a320::1/64 dev azumip4' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip4 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip4' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a32{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip4' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip4 mtu {mtu_value}\n"
        with open("/etc/ipip4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a320::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip64_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip4 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a320::1/64 dev azumip4' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip4 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 route add 2002:0db8:1234:a320::2/64 dev azumip4' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip4 mtu {mtu_value}\n"
        with open("/etc/ipip4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a320::1    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip4_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip4.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip4.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping4_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip4_kharej():
    remote_ip = "2002:831b::2"  # iran-ip
    local_ip = "2002:831b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip64_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a320::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip4_service()

    ipip4_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip4_kharejsec():
    remote_ip = "2002:831b::2"  # iran-ip
    local_ip = "2002:831b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip64_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a320::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip4_service()

    ipip4_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip64_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 4 for iran 4


def kharej2_ipip64_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 5


def run_ping5():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:841b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej5_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:841b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip5_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip5.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip5.service"])
    subprocess.run(["systemctl", "start", "ping_ip5.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip5.service"])


def ipip65_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip5 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a420::1/64 dev azumip5' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip5 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip5' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a42{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip5' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip5 mtu {mtu_value}\n"
        with open("/etc/ipip5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a420::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip65_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip5 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a420::1/64 dev azumip5' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip5 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 route add 2002:0db8:1234:a420::2/64 dev azumip5' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip5 mtu {mtu_value}\n"
        with open("/etc/ipip5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a420::1    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip5_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip5.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip5.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping5_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip5_kharej():
    remote_ip = "2002:841b::2"  # iran-ip
    local_ip = "2002:841b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip65_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a420::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip5_service()

    ipip5_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip5_kharejsec():
    remote_ip = "2002:841b::2"  # iran-ip
    local_ip = "2002:841b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip65_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a420::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip5_service()

    ipip5_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip65_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 5 for iran 5


def kharej2_ipip65_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 6


def run_ping6():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:851b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej6_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:851b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip6_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip6.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip6.service"])
    subprocess.run(["systemctl", "start", "ping_ip6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip6.service"])


def ipip66_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip6 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a520::1/64 dev azumip6' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a52{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip6' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip6 mtu {mtu_value}\n"
        with open("/etc/ipip6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 6:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a520::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip6_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip6.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip6.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping6_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip6_kharej():
    remote_ip = "2002:851b::2"  # iran-ip
    local_ip = "2002:851b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip66_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a520::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping6_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip6_service()

    ipip6_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip66_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[6]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping6()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip6_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 6 for iran 6


def kharej2_ipip66_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[6]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping6()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip6_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 7


def run_ping7():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:861b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej7_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:861b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip7_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip7.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip7.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip7.service"])
    subprocess.run(["systemctl", "start", "ping_ip7.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip7.service"])


def ipip67_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip7.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip7 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a620::1/64 dev azumip7' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip7 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip7' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a62{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip7' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip7 mtu {mtu_value}\n"
        with open("/etc/ipip7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 7:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a620::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip7_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip7.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip7.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping7_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip7.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip7_kharej():
    remote_ip = "2002:861b::2"  # iran-ip
    local_ip = "2002:861b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip67_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a620::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping7_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip7_service()

    ipip7_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip67_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[7]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping7()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip7_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 7 for iran 7


def kharej2_ipip67_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[7]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping7()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip7_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 8


def run_ping8():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:871b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej8_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:871b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip8_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip8.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip8.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip8.service"])
    subprocess.run(["systemctl", "start", "ping_ip8.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip8.service"])


def ipip68_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip8.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip8 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a720::1/64 dev azumip8' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip8 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip8' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a72{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip8' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip8 mtu {mtu_value}\n"
        with open("/etc/ipip8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 8:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a720::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip8_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip8.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip8.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping8_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip8.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip8_kharej():
    remote_ip = "2002:871b::2"  # iran-ip
    local_ip = "2002:871b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip68_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a720::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping8_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip8_service()

    ipip8_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip68_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[8]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping8()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip8_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 8 for iran 8


def kharej2_ipip68_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[8]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping8()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip8_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 9


def run_ping9():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:881b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej9_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:881b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip9_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip9.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip9.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip9.service"])
    subprocess.run(["systemctl", "start", "ping_ip9.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip9.service"])


def ipip69_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip9.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip9 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a820::1/64 dev azumip9' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip9 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip9' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a82{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip9' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip9 mtu {mtu_value}\n"
        with open("/etc/ipip9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 9:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a820::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip9_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip9.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip9.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping9_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip9.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip9_kharej():
    remote_ip = "2002:881b::2"  # iran-ip
    local_ip = "2002:881b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip69_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a820::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping9_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip9_service()

    ipip9_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip69_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[9]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::1/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping9()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:881b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip9_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 9 for iran 9


def kharej2_ipip69_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[9]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::1/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping9()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:881b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip9_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 10


def run_ping10():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:891b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_kharej10_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:891b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 kharej
def ping_ipip10_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip10.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip10.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip10.service"])
    subprocess.run(["systemctl", "start", "ping_ip10.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip10.service"])


def ipip610_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip10.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip10 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a920::1/64 dev azumip10' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip10 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip10' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a92{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip10' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip10 mtu {mtu_value}\n"
        with open("/etc/ipip10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses \033[92mServer 10:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a920::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip10_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip10.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip10.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping10_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip10.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip10_kharej():
    remote_ip = "2002:891b::2"  # iran-ip
    local_ip = "2002:891b::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip610_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a920::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping10_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip10_service()

    ipip10_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def kharej_ipip610_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[10]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::1/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping10()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:891b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip10_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 10 for iran 10


def kharej2_ipip610_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[10]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::1/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping10()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:891b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip10_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 1
def iran_ping1():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:801b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran1_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:801b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran


def iran_ipip1_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip1.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip1.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip1.service"])
    subprocess.run(["systemctl", "start", "ping_ip1.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip1.service"])


def ipip61_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip1 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a020::2/64 dev azumip1\n")
        f.write("ip link set azumip1 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip1\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a02{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip1\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip1 mtu {mtu_value}"
        with open("/etc/ipip1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a020::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip61_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip1 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a020::2/64 dev azumip1\n")
        f.write("ip link set azumip1 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a020::1/64 dev azumip1\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip1 mtu {mtu_value}"
        with open("/etc/ipip1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a020::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# default route ipip_iran1
def ipip61_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip1 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a020::2/64 dev azumip1\n")
        f.write("ip link set azumip1 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip1\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a02{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip1\n")

    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a020::2\n".format(
                interface
            )
        with open("/etc/ipip1.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip1 mtu {mtu_value}\n"
        with open("/etc/ipip1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a020::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip61_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip1 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a020::2/64 dev azumip1\n")
        f.write("ip link set azumip1 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a020::1/64 dev azumip1\n")

    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a020::2\n".format(
                interface
            )
        with open("/etc/ipip1.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip1 mtu {mtu_value}\n"
        with open("/etc/ipip1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 1:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a020::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip1_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip1.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip1.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping1_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip1.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip1_iran():
    remote_ip = "2002:801b::1"  # kharej-ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip61_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a020::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip1_service()

    ipip1_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip1_iransec():
    remote_ip = "2002:801b::1"  # kharej-ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip61_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a020::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip1_service()

    ipip1_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# default route iran 1
def ipip1_iran2():
    remote_ip = "2002:801b::1"  # kharej-ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip61_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a020::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip1_service()

    ipip1_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip1_iran2sec():
    remote_ip = "2002:801b::1"  # kharej-ip
    local_ip = "2002:801b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip61_iran2_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a020::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip1_service()

    ipip1_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip61_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 1 menu
def iran2_ipip61_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_iran2()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 2
def iran_ping2():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:811b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran2_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:811b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran2


def iran_ipip2_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip2.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip2.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip2.service"])
    subprocess.run(["systemctl", "start", "ping_ip2.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip2.service"])


def ipip62_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip2 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a120::2/64 dev azumip2\n")
        f.write("ip link set azumip2 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip2\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a12{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip2\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip2 mtu {mtu_value}\n"
        with open("/etc/ipip2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a120::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip62_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip2 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a120::2/64 dev azumip2\n")
        f.write("ip link set azumip2 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a120::1/64 dev azumip2\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip2 mtu {mtu_value}\n"
        with open("/etc/ipip2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a120::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##defaul route ipip iran2
def ipip62_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip2 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a120::2/64 dev azumip2\n")
        f.write("ip link set azumip2 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip2\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a12{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip2\n")

    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a120::2\n".format(
                interface
            )
        with open("/etc/ipip2.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip2 mtu {mtu_value}\n"
        with open("/etc/ipip2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a120::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip62_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip2 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a120::2/64 dev azumip2\n")
        f.write("ip link set azumip2 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a120::1/64 dev azumip2\n")

    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a120::2\n".format(
                interface
            )
        with open("/etc/ipip2.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip2 mtu {mtu_value}\n"
        with open("/etc/ipip2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 2:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a120::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip2_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip2.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip2.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping2_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip2.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip2_iran():
    remote_ip = "2002:811b::1"  # kharej-ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip62_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a120::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip2_service()

    ipip2_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip2_iransec():
    remote_ip = "2002:811b::1"  # kharej-ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip62_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a120::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip2_service()

    ipip2_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# default route iran server 2
def ipip2_iran2():
    remote_ip = "2002:811b::1"  # kharej-ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip62_iran2_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a120::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip2_service()

    ipip2_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip2_iran2sec():
    remote_ip = "2002:811b::1"  # kharej-ip
    local_ip = "2002:811b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip62_iran2_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a120::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip2_service()

    ipip2_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip62_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 2 menu
def iran2_ipip62_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_iran2()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 3
def iran_ping3():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:821b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran3_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:821b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran3


def iran_ipip3_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip3.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip3.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip3.service"])
    subprocess.run(["systemctl", "start", "ping_ip3.service"])
    subprocess.run(["systemctl", "restart", "ping_ip3.service"])


def ipip63_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip3 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a220::2/64 dev azumip3\n")
        f.write("ip link set azumip3 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip3\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a22{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip3\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip3 mtu {mtu_value}\n"
        with open("/etc/ipip3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a220::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip63_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip3 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a220::2/64 dev azumip3\n")
        f.write("ip link set azumip3 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a220::1/64 dev azumip3\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip3 mtu {mtu_value}\n"
        with open("/etc/ipip3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a220::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##default route ipip iran3
def ipip63_iran2_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip3 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a220::2/64 dev azumip3\n")
        f.write("ip link set azumip3 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip3\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a22{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip3\n")

    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a220::2\n".format(
                interface
            )
        with open("/etc/ipip3.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip3 mtu {mtu_value}\n"
        with open("/etc/ipip3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a220::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip63_iran2_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip3 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a220::2/64 dev azumip3\n")
        f.write("ip link set azumip3 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a220::1/64 dev azumip3\n")

    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a220::2\n".format(
                interface
            )
        with open("/etc/ipip3.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip3 mtu {mtu_value}\n"
        with open("/etc/ipip3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 3:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a220::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip3_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip3.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip3.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping3_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip3.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip3_iran():
    remote_ip = "2002:821b::1"  # kharej-ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip63_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a220::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip3_service()

    ipip3_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip3_iransec():
    remote_ip = "2002:821b::1"  # kharej-ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip63_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a220::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip3_service()

    ipip3_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# default route iran server 2
def ipip3_iran2():
    remote_ip = "2002:821b::1"  # kharej-ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip63_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a220::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip3_service()

    ipip3_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip3_iran2sec():
    remote_ip = "2002:821b::1"  # kharej-ip
    local_ip = "2002:821b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip63_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a220::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip3_service()

    ipip3_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip63_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 3 menu
def iran2_ipip63_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_iran2()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 4
def iran_ping4():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:831b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran4_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:831b::2/64"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran4


def iran_ipip4_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip4.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip4.service"])
    subprocess.run(["systemctl", "start", "ping_ip4.service"])
    subprocess.run(["systemctl", "restart", "ping_ip4.service"])


def ipip64_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip4 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a320::2/64 dev azumip4\n")
        f.write("ip link set azumip4 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip4\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a32{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip4\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip4 mtu {mtu_value}"
        with open("/etc/ipip4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a320::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip64_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip4 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a320::2/64 dev azumip4\n")
        f.write("ip link set azumip4 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a320::1/64 dev azumip4\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip4 mtu {mtu_value}"
        with open("/etc/ipip4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 4:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a320::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip4_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip4.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip4.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping4_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip4.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip4_iran():
    remote_ip = "2002:831b::1"  # kharej-ip
    local_ip = "2002:831b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip64_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a320::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip4_service()

    ipip4_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip4_iransec():
    remote_ip = "2002:831b::1"  # kharej-ip
    local_ip = "2002:831b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip64_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a320::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip4_service()

    ipip4_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip64_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 4 menu
def iran2_ipip64_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 5
def iran_ping5():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:841b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran5_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:841b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran5


def iran_ipip5_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip5.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip5.service"])
    subprocess.run(["systemctl", "start", "ping_ip5.service"])
    subprocess.run(["systemctl", "restart", "ping_ip5.service"])


def ipip65_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip5 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a420::2/64 dev azumip5\n")
        f.write("ip link set azumip5 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip5\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a42{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip5\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip5 mtu {mtu_value}"
        with open("/etc/ipip5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a420::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip65_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip5 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a420::2/64 dev azumip5\n")
        f.write("ip link set azumip5 up\n")
        f.write("ip -6 route add 2002:0db8:1234:a420::1/64 dev azumip5\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip5 mtu {mtu_value}"
        with open("/etc/ipip5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 5:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a420::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip5_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip5.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip5.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping5_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip5.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip5_iran():
    remote_ip = "2002:841b::1"  # kharej-ip
    local_ip = "2002:841b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip65_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a420::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip5_service()

    ipip5_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip5_iransec():
    remote_ip = "2002:841b::1"  # kharej-ip
    local_ip = "2002:841b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip65_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a420::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip5_service()

    ipip5_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip65_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 5 menu
def iran2_ipip65_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 6
def iran_ping6():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:851b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran6_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:851b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran6


def iran_ipip6_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip6.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip6.service"])
    subprocess.run(["systemctl", "start", "ping_ip6.service"])
    subprocess.run(["systemctl", "restart", "ping_ip6.service"])


def ipip66_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip6 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a520::2/64 dev azumip6\n")
        f.write("ip link set azumip6 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip6\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a52{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip6\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip6 mtu {mtu_value}"
        with open("/etc/ipip6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 6:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a520::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip6_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip6.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip6.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping6_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip6_iran():
    remote_ip = "2002:851b::1"  # kharej-ip
    local_ip = "2002:851b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip66_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a520::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping6_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip6_service()

    ipip6_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip66_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[6]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping6()

    script_content1 = """#!/bin/bash


ip_address="2002:851b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip6_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 6 menu
def iran2_ipip66_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[6]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi6\n")
        f.write("ip -6 route add 2002::/16 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping6()

    script_content1 = """#!/bin/bash


ip_address="2002:851b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip6_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 7
def iran_ping7():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:861b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran7_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:861b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran7


def iran_ipip7_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip7.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip7.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip7.service"])
    subprocess.run(["systemctl", "start", "ping_ip7.service"])
    subprocess.run(["systemctl", "restart", "ping_ip7.service"])


def ipip67_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip7.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip7 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a620::2/64 dev azumip7\n")
        f.write("ip link set azumip7 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip7\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a62{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip7\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip7 mtu {mtu_value}"
        with open("/etc/ipip7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 7:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a620::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip7_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip7.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip7.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping7_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip7.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip7_iran():
    remote_ip = "2002:861b::1"  # kharej-ip
    local_ip = "2002:861b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip67_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a620::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping7_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip7_service()

    ipip7_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip67_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[7]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping7()

    script_content1 = """#!/bin/bash


ip_address="2002:861b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip7_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 7 menu
def iran2_ipip67_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[7]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi7\n")
        f.write("ip -6 route add 2002::/16 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping7()

    script_content1 = """#!/bin/bash


ip_address="2002:861b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip7_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 8
def iran_ping8():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:871b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran8_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:871b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran8


def iran_ipip8_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip8.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip8.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip8.service"])
    subprocess.run(["systemctl", "start", "ping_ip8.service"])
    subprocess.run(["systemctl", "restart", "ping_ip8.service"])


def ipip68_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip8.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip8 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a720::2/64 dev azumip8\n")
        f.write("ip link set azumip8 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip8\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a72{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip8\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip8 mtu {mtu_value}"
        with open("/etc/ipip8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 8:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a720::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip8_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip8.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip8.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping8_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip8.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip8_iran():
    remote_ip = "2002:871b::1"  # kharej-ip
    local_ip = "2002:871b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip68_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a720::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping8_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip8_service()

    ipip8_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip68_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[8]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping8()

    script_content1 = """#!/bin/bash


ip_address="2002:871b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip8_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 8 menu
def iran2_ipip68_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[8]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi8\n")
        f.write("ip -6 route add 2002::/16 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping8()

    script_content1 = """#!/bin/bash


ip_address="2002:871b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip8_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 9
def iran_ping9():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:881b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran9_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:881b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran9


def iran_ipip9_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip9.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip9.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip9.service"])
    subprocess.run(["systemctl", "start", "ping_ip9.service"])
    subprocess.run(["systemctl", "restart", "ping_ip9.service"])


def ipip69_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip9.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip9 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a820::2/64 dev azumip9\n")
        f.write("ip link set azumip9 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip9\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a82{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip9\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip9 mtu {mtu_value}"
        with open("/etc/ipip9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 9:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a820::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip9_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip9.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip9.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping9_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip9.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip9_iran():
    remote_ip = "2002:881b::1"  # kharej-ip
    local_ip = "2002:881b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip69_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a820::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping9_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip9_service()

    ipip9_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip69_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[9]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::2/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping9()

    script_content1 = """#!/bin/bash


ip_address="2002:881b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip9_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 9 menu
def iran2_ipip69_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[9]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:881b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add 2002:881b::2/64 dev azumi9\n")
        f.write("ip -6 route add 2002::/16 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping9()

    script_content1 = """#!/bin/bash


ip_address="2002:881b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip9_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 10
def iran_ping10():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:891b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran10_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "2002:891b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran10


def iran_ipip10_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip10.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip10.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip10.service"])
    subprocess.run(["systemctl", "start", "ping_ip10.service"])
    subprocess.run(["systemctl", "restart", "ping_ip10.service"])


def ipip610_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip10.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip10 mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a920::2/64 dev azumip10\n")
        f.write("ip link set azumip10 up\n")
        f.write("ip -6 route add 2002::/16 dev azumip10\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a92{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip10\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip10 mtu {mtu_value}"
        with open("/etc/ipip10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses \033[92mServer 10:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a920::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip10_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip10.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip10.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping10_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip10.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip10_iran():
    remote_ip = "2002:891b::1"  # kharej-ip
    local_ip = "2002:891b::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip610_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a920::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping10_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip10_service()

    ipip10_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip610_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[10]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::2/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping10()

    script_content1 = """#!/bin/bash


ip_address="2002:891b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip10_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 10 menu
def iran2_ipip610_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mServer\033[93m\033[96m[10]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:891b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add 2002:891b::2/64 dev azumi10\n")
        f.write("ip -6 route add 2002::/16 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping10()

    script_content1 = """#!/bin/bash


ip_address="2002:891b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip10_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# 11
def config_ipipk1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip1
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a020::1/64
  leftid=2002:0db8:1234:a020::1
  right=2002:0db8:1234:a020::2
  rightsubnet=2002:0db8:1234:a020::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:0db8:1234:a020::2 2002:0db8:1234:a020::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipk2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip2
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a120::1/64
  leftid=2002:0db8:1234:a120::1
  right=2002:0db8:1234:a120::2
  rightsubnet=2002:0db8:1234:a120::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:0db8:1234:a120::2 2002:0db8:1234:a120::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipk3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip3
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a220::1/64
  leftid=2002:0db8:1234:a220::1
  right=2002:0db8:1234:a220::2
  rightsubnet=2002:0db8:1234:a220::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:0db8:1234:a220::2 2002:0db8:1234:a220::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipk4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip4
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a320::1/64
  leftid=2002:0db8:1234:a320::1
  right=2002:0db8:1234:a320::2
  rightsubnet=2002:0db8:1234:a320::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:0db8:1234:a320::2 2002:0db8:1234:a320::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipk5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip5
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a420::1/64
  leftid=2002:0db8:1234:a420::1
  right=2002:0db8:1234:a420::2
  rightsubnet=2002:0db8:1234:a420::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:0db8:1234:a420::2 2002:0db8:1234:a420::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipi1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip1
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a020::2/64
  leftid=2002:0db8:1234:a020::2
  right=2002:0db8:1234:a020::1
  rightsubnet=2002:0db8:1234:a020::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:0db8:1234:a020::1 2002:0db8:1234:a020::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipi2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip2
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a120::2/64
  leftid=2002:0db8:1234:a120::2
  right=2002:0db8:1234:a120::1
  rightsubnet=2002:0db8:1234:a120::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:0db8:1234:a120::1 2002:0db8:1234:a120::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipi3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn ipip3
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a220::2/64
  leftid=2002:0db8:1234:a220::2
  right=2002:0db8:1234:a220::1
  rightsubnet=2002:0db8:1234:a220::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:0db8:1234:a220::1 2002:0db8:1234:a220::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipi4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan4
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a320::2/64
  leftid=2002:0db8:1234:a320::2
  right=2002:0db8:1234:a320::1
  rightsubnet=2002:0db8:1234:a320::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:0db8:1234:a320::1 2002:0db8:1234:a320::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipi5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a420::2/64
  leftid=2002:0db8:1234:a420::2
  right=2002:0db8:1234:a420::1
  rightsubnet=2002:0db8:1234:a420::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:0db8:1234:a420::1 2002:0db8:1234:a420::2 : PSK "{psk}"\n')

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipk(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn ipip{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:0db8:1234:a{i+0}20::1/64\n")
            f.write(f"  leftid=2002:0db8:1234:a{i+0}20::1\n")
            f.write(f"  right=2002:0db8:1234:a{i+0}20::2\n")
            f.write(f"  rightsubnet=2002:0db8:1234:a{i+0}20::2/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(
                f'2002:0db8:1234:a{i+0}20::2 2002:0db8:1234:a{i+0}20::1 : PSK "{psk}"\n'
            )

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipipi(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn ipip{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:0db8:1234:a{i+0}20::2/64\n")
            f.write(f"  leftid=2002:0db8:1234:a{i+0}20::2\n")
            f.write(f"  right=2002:0db8:1234:a{i+0}20::1\n")
            f.write(f"  rightsubnet=2002:0db8:1234:a{i+0}20::1/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(
                f'2002:0db8:1234:a{i+0}20::1 2002:0db8:1234:a{i+0}20::2 : PSK "{psk}"\n'
            )

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def ip6_mnu_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 + IPSec \033[92m Multiple Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[96mKHAREJ\033[92m[5]  \033[93mIRAN\033[92m[1]\033[0m")
    print("2. \033[96mKHAREJ\033[92m[1]  \033[93mIRAN\033[92m[5]\033[0m")
    print("3. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ip6_kh_ipsec()
            break
        elif server_type == "2":
            ip6_ir_ipsec()
            break
        elif server_type == "3":
            choose_reset2()
            break
        elif server_type == "0":
            os.system("clear")
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def ip6_kh_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 + IPSec \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_ipip61sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_ipip62sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_ipip63sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_ipip64sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej_ipip65sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            ipip6_reset_rmvmnu()
            enable_reset_ipsec()
            kharejip_qsec()
            break
        elif server_type == "0":
            os.system("clear")
            ip6_mnu_ipsec()
            break
        else:
            print("Invalid choice.")


def kharejip_qsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "iran_ipip6{}sec_menu".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit
def kharejip_qsecedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi(psk, num_servers)


# edit2
def kharejip_qsecedit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input(
            "\033[93mHow many \033[92mKharej Servers\033[93m do you have \033[96mright now\033[93m?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipipi(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    display_notification(
        "\033[93mUse systemctl restart strong-azumi1 in kharej servers as well \033[0m"
    )
    restart_forced_strongazumi()


def ip6_ir_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mIP6IP6 + IPSec \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_ipip61sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_ipip62sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_ipip63sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_ipip64sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            ipip6_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_ipip65sec_menu()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            ipip6_reset_rmvmnu()
            enable_reset_ipsec()
            iranip_qsec()
            break
        elif server_type == "0":
            os.system("clear")
            ip6_mnu_ipsec()
            break
        else:
            print("Invalid choice.")


def iranip_qsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "kharej2_ipip6{}sec_menu".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit
def iranip_qsecedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def iranip_qsecedit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now\033[93m?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipipk(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    display_notification(
        "\033[93mUse systemctl restart strong-azumi1 in kharej servers as well \033[0m"
    )
    restart_forced_strongazumi()


def kharej_ipip61sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk1(psk)
    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::2/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


## kharej 1 for iran 1
def kharej2_ipip61sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::2/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def kharej2_ipip61sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 \033[92mKharej\033[93m server\033[92m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk1(psk)
    initial_ip = "2002:801b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::2/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:801b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##kharej2


def kharej_ipip62sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk2(psk)
    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::2/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 2 for iran 2
def kharej2_ipip62sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::2/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def kharej2_ipip62sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk2(psk)
    initial_ip = "2002:811b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::2/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:811b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##kharej3


def kharej_ipip63sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk3(psk)
    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::2/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 3 for iran 3


def kharej2_ipip63sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::2/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


def kharej2_ipip63sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk3(psk)
    initial_ip = "2002:821b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::2/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:821b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 4


def kharej_ipip64sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk4(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 4 for iran 4


def kharej2_ipip64sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def kharej2_ipip64sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk4(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 5


def kharej_ipip65sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk5(psk)
    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::2/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# kharej 5 for iran 5


def kharej2_ipip65sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::2/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def kharej2_ipip65sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IP6IP6 + IPSec \033[92mKharej\033[93m server\033[92m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej \033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipk5(psk)
    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::2/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6 server 1


def iran_ipip61sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def iran_ipip61sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi1(psk)
    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 1 menu
def iran2_ipip61sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[1]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi1(psk)
    initial_ip = "2002:801b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:801b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:801b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:801b::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping1()

    script_content1 = """#!/bin/bash


ip_address="2002:801b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip1_iran2sec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


def iran_ipip62sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::1/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def iran_ipip62sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi2(psk)
    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::1/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 2 menu
def iran2_ipip62sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[2]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi2(psk)
    initial_ip = "2002:811b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:811b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:811b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:811b::1/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping2()

    script_content1 = """#!/bin/bash


ip_address="2002:811b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip2_iran2sec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


def iran_ipip63sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def iran_ipip63sec_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi3(psk)
    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 3 menu
def iran2_ipip63sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[3]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi3(psk)
    initial_ip = "2002:821b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:821b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:821b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:821b::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping3()

    script_content1 = """#!/bin/bash


ip_address="2002:821b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip3_iran2sec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


def iran_ipip64sec_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def iran_ipip64sec_edit():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi4(psk)
    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 4 menu
def iran2_ipip64sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[4]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi4(psk)
    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping4()

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip4_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


def iran_ipip65sec_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


# edit
def iran_ipip65sec_edit():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi5(psk)
    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##default route iran server 5 menu
def iran2_ipip65sec_menu():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 + IPSec \033[92mServer\033[93m\033[96m[5]\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipipi5(psk)
    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )
    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping5()

    script_content1 = """#!/bin/bash


ip_address="2002:841b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip5_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


## 12
## private ipsec
def config_prik1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private1
  left=%defaultroute
  leftsubnet=2002:831b::1/64
  leftid=2002:831b::1
  right=2002:831b::2
  rightsubnet=2002:831b::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831b::2 2002:831b::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prik2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private2
  left=%defaultroute
  leftsubnet=2002:841b::1/64
  leftid=2002:841b::1
  right=2002:841b::2
  rightsubnet=2002:841b::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:841b::2 2002:841b::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prik3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private3
  left=%defaultroute
  leftsubnet=2002:851b::1/64
  leftid=2002:851b::1
  right=2002:851b::2
  rightsubnet=2002:851b::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:851b::2 2002:851b::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prik4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private4
  left=%defaultroute
  leftsubnet=2002:861b::1/64
  leftid=2002:861b::1
  right=2002:861b::2
  rightsubnet=2002:861b::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:861b::2 2002:861b::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prik5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private5
  left=%defaultroute
  leftsubnet=2002:871b::1/64
  leftid=2002:871b::1
  right=2002:871b::2
  rightsubnet=2002:871b::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:871b::2 2002:871b::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prii1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private1
  left=%defaultroute
  leftsubnet=2002:831b::2/64
  leftid=2002:831b::2
  right=2002:831b::1
  rightsubnet=2002:831b::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:831b::1 2002:831b::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prii2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private2
  left=%defaultroute
  leftsubnet=2002:841b::2/64
  leftid=2002:841b::2
  right=2002:841b::1
  rightsubnet=2002:841b::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:841b::1 2002:841b::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prii3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private3
  left=%defaultroute
  leftsubnet=2002:851b::2/64
  leftid=2002:851b::2
  right=2002:851b::1
  rightsubnet=2002:851b::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:851b::1 2002:851b::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prii4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private4
  left=%defaultroute
  leftsubnet=2002:861b::2/64
  leftid=2002:861b::2
  right=2002:861b::1
  rightsubnet=2002:861b::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:861b::1 2002:861b::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_prii5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn private5
  left=%defaultroute
  leftsubnet=2002:871b::2/64
  leftid=2002:871b::2
  right=2002:871b::1
  rightsubnet=2002:871b::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:871b::1 2002:871b::2 : PSK "{psk}"\n')

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_privatek(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn private{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:8{i+3}1b::1/64\n")
            f.write(f"  leftid=2002:8{i+3}1b::1\n")
            f.write(f"  right=2002:8{i+3}1b::2\n")
            f.write(f"  rightsubnet=2002:8{i+3}1b::2/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2002:8{i+3}1b::2 2002:8{i+3}1b::1 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_privatei(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn private{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:8{i+3}1b::2/64\n")
            f.write(f"  leftid=2002:8{i+3}1b::2\n")
            f.write(f"  right=2002:8{i+3}1b::1\n")
            f.write(f"  rightsubnet=2002:8{i+3}1b::1/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2002:8{i+3}1b::1 2002:8{i+3}1b::2 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def priv_mnu_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mPrivateIP + IPsec \033[92m Multiple Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[96mKharej\033[92m[5] \033[93mIRAN\033[92m[1]\033[0m")
    print("2. \033[96mKharej\033[92m[1] \033[93mIRAN\033[92m[5]  \033[0m")
    print("3. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_kh_ipsec()
            break
        elif server_type == "2":
            priv_ir_ipsec()
            break
        elif server_type == "3":
            choose_reset2()
            break
        elif server_type == "0":
            os.system("clear")
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def priv_kh_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mPrivate IP + IPsec \033[92m[5]Kharej\033[96m [1]IRAN\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej1_private_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej2_private_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej3_private_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej4_private_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            kharej5_private_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            private_reset_rmvmnu()
            enable_reset_ipsec()
            kharej_qpri_ipsec()
            break
        elif server_type == "0":
            os.system("clear")
            priv_mnu_ipsec()
            break
        else:
            print("Invalid choice.")


def kharej_qpri_ipsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mkharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_privatei(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "iran{}_private_ipsec".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit
def kharej_qpri_ipsecedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mkharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_privatei(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def kharej_qpri_ipsecedit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input(
            "\033[93mHow many \033[92mkharej Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m: \033[0m")
    config_privatei(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    display_notification(
        "\033[93mUse systemctl restart strong-azumi1 in kharej servers as well \033[0m"
    )
    restart_forced_strongazumi()


def priv_ir_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mPrivate IP + IPsec \033[92m[5]IRAN\033[96m [1]Kharej\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran1_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran2_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran3_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran4_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            private_reset_rmvmnu()
            remove_config()
            enable_reset_ipsec()
            iran5_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            private_reset_rmvmnu()
            enable_reset_ipsec()
            iran_qpri_ipsec()
            break
        elif server_type == "0":
            os.system("clear")
            priv_mnu_ipsec()
            break
        else:
            print("Invalid choice.")


def iran_qpri_ipsec():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_privatek(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "kharej{}_private2_ipsec".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit
def iran_qpri_ipsecedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_privatek(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def iran_qpri_ipsecedit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_privatek(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    display_notification(
        "\033[93mUse systemctl restart strong-azumi1 in kharej servers as well \033[0m"
    )
    restart_forced_strongazumi()


def kharej1_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [1]...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik1(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping1()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = f"2002:831b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej1 for iran 1
def kharej1_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [1]...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping1()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:831b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# edit
def kharej1_private2_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [1]...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik1(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping1()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:831b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


## Kharej 2


def kharej2_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [2]...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik2(psk)
    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002:841b::2/64 dev azumi2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping2()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:841b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 2 for iran 2


def kharej2_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [2]...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:841b::1/64 dev azumi2\n")
        f.write("ip -6 route add 2002:841b::2/64 dev azumi2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping2()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:841b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:841b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def kharej3_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [3]...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik3(psk)
    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002:851b::2/64 dev azumi3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping3()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:851b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 3 for iran 3


def kharej3_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [3]...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:851b::1/64 dev azumi3\n")
        f.write("ip -6 route add 2002:851b::2/64 dev azumi3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping3()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:851b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:851b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def kharej4_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [4]...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik4(psk)
    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002:861b::2/64 dev azumi4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping4()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = f"2002:861b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 4 for iran 4
def kharej4_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [4]...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:861b::1/64 dev azumi4\n")
        f.write("ip -6 route add 2002:861b::2/64 dev azumi4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping4()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:861b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:861b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def kharej5_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [5]...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prik5(psk)
    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002:871b::2/64 dev azumi5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping5()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:871b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# kharej 5 for iran 5
def kharej5_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server \033[92m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server [5]...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:871b::1/64 dev azumi5\n")
        f.write("ip -6 route add 2002:871b::2/64 dev azumi5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    runsec_ping5()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:871b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:871b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def iran1_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[1]...\033[0m")

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping1_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:831b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:831b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()


# edit
def iran1_private_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[1]...\033[0m")

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii1(psk)
    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002::/16 dev azumi1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping1_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:831b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:831b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()


## route for iran1_private_menu
def iran1_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[1]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[1]...\033[0m")

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii1(psk)
    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi1\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi1\n")

    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831b::2\n".format(
                interface
            )
        with open("/etc/private1.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron1_job()

    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping1_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:831b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:831b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()


def iran2_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[2]...\033[0m")

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping2_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:841b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:841b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()


# edit
def iran2_private_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[2]...\033[0m")

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii2(psk)
    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002::/16 dev azumi2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping2_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:841b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:841b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()


## default route iran2_private_menu
def iran2_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[2]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[2]...\033[0m")

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii2(psk)
    initial_ip = "2002:841b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:841b::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add 2002:841b::2/64 dev azumi2\n")
        f.write("ip -6 route add 2002:841b::1/64 dev azumi2\n")

    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:841b::2\n".format(
                interface
            )
        with open("/etc/private2.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping2_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:841b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:841b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()


def iran3_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[3]...\033[0m")

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:851b::1/64 dev azumi3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping3_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:851b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:851b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()


# edit
def iran3_private_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[3]...\033[0m")

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii3(psk)
    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002::/16 dev azumi3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping3_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:851b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:851b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()


## default route iran3_private_menu
def iran3_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[3]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[3]...\033[0m")

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii3(psk)
    initial_ip = "2002:851b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:851b::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add 2002:851b::2/64 dev azumi3\n")
        f.write("ip -6 route add 2002:851b::1/64 dev azumi3\n")

    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:851b::2\n".format(
                interface
            )
        with open("/etc/private3.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping3_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:851b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:851b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()


def iran4_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[4]...\033[0m")

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:861b::1/64 dev azumi4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping4_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:861b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:861b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()


# edit
def iran4_private_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[4]...\033[0m")

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii4(psk)
    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002::/16 dev azumi4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping4_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:861b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:861b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()


##default route iran4_private_menu
def iran4_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[4]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[4]...\033[0m")

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii4(psk)
    initial_ip = "2002:861b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:861b::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add 2002:861b::2/64 dev azumi4\n")
        f.write("ip -6 route add 2002:861b::1/64 dev azumi4\n")

    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:861b::2\n".format(
                interface
            )
        with open("/etc/private4.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping4_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:861b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:861b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()


def iran5_private_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[5]...\033[0m")

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:871b::1/64 dev azumi5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping5_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:871b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:871b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()


# edit
def iran5_private_edit():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[5]...\033[0m")

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii5(psk)
    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002::/16", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002::/16 dev azumi5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping5_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:871b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:871b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()


# default route iran5_private_menu
def iran5_private2_ipsec():

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Server\033[96m[5]\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mAdding private IP addresses for Server[5]...\033[0m")

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    print("\033[93m─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_prii5(psk)
    initial_ip = "2002:871b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:871b::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    display_notification("\033[93mAdding commands...\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add 2002:871b::2/64 dev azumi5\n")
        f.write("ip -6 route add 2002:871b::1/64 dev azumi5\n")

    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:871b::2\n".format(
                interface
            )
        with open("/etc/private5.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    runsec_ping5_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:871b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:871b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()

    ##### PRIVATE 5 kharej 1 iran


# gen simple ipv4 & native multi
def gen_multi_menuz():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve UDP  \033[0m")
    print("2. \033[93mGeneve + Native\033[0m")
    print("3. \033[96mGeneve + IPv4 + GRE6\033[0m")
    print("4. \033[92mGeneve + Native + GRE6\033[0m")
    print("5. \033[96mGeneve + IPsec\033[0m")
    print("6. \033[93mGeneve + IPsec + GRE6\033[0m")
    print("7. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_multi_ip()
            break
        elif server_type == "2":
            gen_multin_ip()
            break
        elif server_type == "3":
            gengre_ipv4_ip()
            break
        elif server_type == "4":
            gengre_native_ip()
            break
        elif server_type == "5":
            gen_ipsec_multi1()
            break
        elif server_type == "6":
            gen_ipsec_multi2()
            break
        elif server_type == "7":
            choose_reset2()
            break
        elif server_type == "0":
            clear()
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def gen_multi_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve IPV4 Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5_gen()
            break
        elif server_type == "2":
            kharej1_gen()
            break
        elif server_type == "3":
            clear()
            gen_multi_menuz()
            break
        else:
            print("Invalid choice.")


def kharej5_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92m[5]Kharej\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5_s1()
            break
        elif server_type == "2":
            kharej5_s2()
            break
        elif server_type == "3":
            kharej5_s3()
            break
        elif server_type == "4":
            kharej5_s4()
            break
        elif server_type == "5":
            kharej5_s5()
            break
        elif server_type == "6":
            iran1_q_gen()
            break
        elif server_type == "0":
            clear()
            gen_multi_ip()
            break
        else:
            print("Invalid choice.")


def iran1_q_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "iran52_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def kharej1_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92m[5]IRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran5_s1()
            break
        elif server_type == "2":
            iran5_s2()
            break
        elif server_type == "3":
            iran5_s3()
            break
        elif server_type == "4":
            iran5_s4()
            break
        elif server_type == "5":
            iran5_s5()
            break
        elif server_type == "6":
            kharej1_q_gen()
            break
        elif server_type == "0":
            clear()
            gen_multi_ip()
            break
        else:
            print("Invalid choice.")


def kharej1_q_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "kharej52_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def gen1_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db3::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gen2_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db3::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


# 2
def gen3_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db4::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gen4_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db4::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


# 3
def gen5_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db5::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gen6_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db5::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


# 4
def gen7_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db6::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gen8_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db6::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


# 5
def gen9_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db7::2"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gen10_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(["ping", "-c", "2", "2001:db7::1"], check=True)
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_kh1_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping1_sys.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping1_gen.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping1_gen.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping1_gen.service"])


def ping_kh2_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping2_sys.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping2_gen.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping2_gen.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping2_gen.service"])


def ping_kh3_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping3_sys.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping3_gen.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping3_gen.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping3_gen.service"])


def ping_kh4_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping4_sys.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping4_gen.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping4_gen.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping4_gen.service"])


def ping_kh5_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping5_sys.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping5_gen.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping5_gen.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping5_gen.service"])


def gen1_job():
    file_path = "/etc/sys1.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gen2_job():
    file_path = "/etc/sys2.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gen3_job():
    file_path = "/etc/sys3.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gen4_job():
    file_path = "/etc/sys4.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def gen5_job():
    file_path = "/etc/sys5.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def kharej5_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::1/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::2/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen1_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::1/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::2/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen1_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::2/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::1/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen2_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::2/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::1/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen2_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 2
def kharej5_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::1/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::2/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen3_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::1/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::2/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen3_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::2/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::1/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen4_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::2/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::1/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen4_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 3
def kharej5_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::1/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::2/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen5_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::1/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::2/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen5_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::2/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::1/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen6_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::2/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::1/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen6_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 4
def kharej5_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::1/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::2/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen7_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::1/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::2/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen7_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::2/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::1/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen8_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::2/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::1/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen8_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 5
def kharej5_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::1/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::2/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen9_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::1/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::2/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen9_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::2/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::1/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen10_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::2/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::1/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen10_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# native
def gen_multin_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mNative\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5n_gen()
            break
        elif server_type == "2":
            kharej1n_gen()
            break
        elif server_type == "3":
            clear()
            gen_multi_menuz()
            break
        else:
            print("Invalid choice.")


def kharej5n_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92m[5]Kharej\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5n_s1()
            break
        elif server_type == "2":
            kharej5n_s2()
            break
        elif server_type == "3":
            kharej5n_s3()
            break
        elif server_type == "4":
            kharej5n_s4()
            break
        elif server_type == "5":
            kharej5n_s5()
            break
        elif server_type == "6":
            iran1_qn_gen()
            break
        elif server_type == "0":
            clear()
            gen_multin_ip()
            break
        else:
            print("Invalid choice.")


def iran1_qn_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "iran52n_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def kharej1n_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92m[5]IRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran5n_s1()
            break
        elif server_type == "2":
            iran5n_s2()
            break
        elif server_type == "3":
            iran5n_s3()
            break
        elif server_type == "4":
            iran5n_s4()
            break
        elif server_type == "5":
            iran5n_s5()
            break
        elif server_type == "6":
            kharej1_qn_gen()
            break
        elif server_type == "0":
            clear()
            gen_multin_ip()
            break
        else:
            print("Invalid choice.")


def kharej1_qn_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "kharej52n_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def kharej5n_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::1/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::2/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen1_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52n_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::1/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::2/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen1_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5n_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::2/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::1/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen2_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52n_s1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys1.sh"):
        os.remove("/etc/sys1.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db3::1")
    ufw("2001:db3::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::2/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::1/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen2_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db3::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 2
def kharej5n_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::1/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::2/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen3_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52n_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::1/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::2/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen3_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5n_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::2/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::1/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen4_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52n_s2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys2.sh"):
        os.remove("/etc/sys2.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db4::1")
    ufw("2001:db4::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::2/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::1/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen4_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db4::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 3
def kharej5n_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::1/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::2/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen5_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52n_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::1/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::2/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen5_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5n_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::2/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::1/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen6_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52n_s3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys3.sh"):
        os.remove("/etc/sys3.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db5::1")
    ufw("2001:db5::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::2/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::1/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen6_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db5::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 4
def kharej5n_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::1/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::2/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen7_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52n_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::1/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::2/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen7_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5n_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::2/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::1/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen8_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52n_s4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys4.sh"):
        os.remove("/etc/sys4.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db6::1")
    ufw("2001:db6::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::2/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::1/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen8_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db6::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# 5
def kharej5n_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::1/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::2/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen9_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def kharej52n_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::1/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::2/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen9_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran5n_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::2/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::1/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen10_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def iran52n_s5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mServer 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    if os.path.isfile("/etc/sys5.sh"):
        os.remove("/etc/sys5.sh")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    ufw(remote_ip)
    ufw("2001:db7::1")
    ufw("2001:db7::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::2/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::1/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen10_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db7::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


# gen gre6 ipv4
# gen gre6 ipv4 multi
def gengre_ipv4_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve \033[92mGRE6 \033[96mIPV4\033[93m Multi Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5_genp4_gre()
            break
        elif server_type == "2":
            kharej11_genp4_gre()
            break
        elif server_type == "3":
            clear()
            gen_multi_menuz()
            break
        else:
            print("Invalid choice.")


def kharej5_genp4_gre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mIPV4 \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genp4_kharej_gre1()
            break
        elif server_type == "2":
            genp4_kharej_gre2()
            break
        elif server_type == "3":
            genp4_kharej_gre3()
            break
        elif server_type == "4":
            genp4_kharej_gre4()
            break
        elif server_type == "5":
            genp4_kharej_gre5()
            break
        elif server_type == "6":
            iranp4_question()
            break
        elif server_type == "0":
            clear()
            gengre_ipv4_ip()
            break
        else:
            print("Invalid choice.")


def iranp4_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genp4_iran2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def kharej11_genp4_gre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mIPV4 \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genp4_iran_gre1()
            break
        elif server_type == "2":
            genp4_iran_gre2()
            break
        elif server_type == "3":
            genp4_iran_gre3()
            break
        elif server_type == "4":
            genp4_iran_gre4()
            break
        elif server_type == "5":
            genp4_iran_gre5()
            break
        elif server_type == "6":
            kharejp4_question()
            break
        elif server_type == "0":
            clear()
            gengre_ipv4_ip()
            break
        else:
            print("Invalid choice.")


def kharejp4_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genp4_kharej2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


# 1
def gre6k__multip4_tunnel1():

    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gre local fd1d:fc98:b73e:b481::1 remote fd1d:fc98:b73e:b481::2\n"
        )
        f.write("ip -6 addr add 2002:831a::1/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002:831a::2/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multip4_tunnel1():

    gre6k__multip4_tunnel1()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre61_service()
    gre61_cronjob()


def kharejp4_gre6_menu1():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi1\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::2/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    rungen_pingz1()  # geninja
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    kharej_gre6multip4_tunnel1()
    sleep(1)


def geneve_multip4_grek61():
    ufw("2001:db3::1")
    ufw("2001:db3::2")
    ufw("2002:831a::1")
    ufw("2002:831a::2")
    ufw("fd1d:fc98:b73e:b481::1")
    ufw("fd1d:fc98:b73e:b481::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::1/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::2/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen1_ping()  # injaa

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db3::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_kharej_gre1():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    kharejp4_gre6_menu1()
    geneve_multip4_grek61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_kharej2_gre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    kharejp4_gre6_menu1()
    geneve_multip4_grek61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multip4_tunnel1():

    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gre local fd1d:fc98:b73e:b481::2 remote fd1d:fc98:b73e:b481::1\n"
        )
        f.write("ip -6 addr add 2002:831a::2/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002:831a::1/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multip4_tunnel1():

    gre6i__multip4_tunnel1()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre61_service()
    gre61_cronjob()


def iranp4_gre6_menu1():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi1\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran1_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    iran_gre6multip4_tunnel1()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def genevep4_multip4_grei61():
    ufw("2001:db3::1")
    ufw("2001:db3::2")
    ufw("2002:831a::1")
    ufw("2002:831a::2")
    ufw("fd1d:fc98:b73e:b481::1")
    ufw("fd1d:fc98:b73e:b481::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::2/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::1/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen2_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db3::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_iran_gre1():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    iranp4_gre6_menu1()
    genevep4_multip4_grei61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_iran2_gre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    iranp4_gre6_menu1()
    genevep4_multip4_grei61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 2


def gre6k__multip4_tunnel2():

    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gre local fd1d:fc98:b73e:b581::1 remote fd1d:fc98:b73e:b581::2\n"
        )
        f.write("ip -6 addr add 2002:841a::1/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002:841a::2/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multip4_tunnel2():

    gre6k__multip4_tunnel2()
    ip_address = "2002:841a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre62_service()
    gre62_cronjob()


def kharejp4_gre6_menu2():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b581::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b581::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b581::1/64 dev azumi2\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b581::2/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    rungen_pingz2()  # injagen2
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b581::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    kharej_gre6multip4_tunnel2()


def geneve_multip4_grek62():
    ufw("2001:db4::1")
    ufw("2001:db4::2")
    ufw("2002:841a::1")
    ufw("2002:841a::2")
    ufw("fd1d:fc98:b73e:b581::1")
    ufw("fd1d:fc98:b73e:b581::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:841a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote 2002:841a::2\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::1/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::2/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen3_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db4::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_kharej_gre2():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    kharejp4_gre6_menu2()
    geneve_multip4_grek62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_kharej2_gre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    kharejp4_gre6_menu2()
    geneve_multip4_grek62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multip4_tunnel2():

    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gre local fd1d:fc98:b73e:b581::2 remote fd1d:fc98:b73e:b581::1\n"
        )
        f.write("ip -6 addr add 2002:841a::2/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002:841a::1/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multip4_tunnel2():

    gre6i__multip4_tunnel2()
    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre62_service()
    gre62_cronjob()


def iranp4_gre6_menu2():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b581::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b581::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b581::2/64 dev azumi2\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b581::1/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran2_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b581::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    iran_gre6multip4_tunnel2()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def genevep4_multip4_grei62():
    ufw("2001:db4::1")
    ufw("2001:db4::2")
    ufw("2002:841a::1")
    ufw("2002:841a::2")
    ufw("fd1d:fc98:b73e:b581::1")
    ufw("fd1d:fc98:b73e:b581::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:841a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote 2002:841a::1\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::2/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::1/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen4_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db4::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_iran_gre2():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    iranp4_gre6_menu2()
    genevep4_multip4_grei62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_iran2_gre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    iranp4_gre6_menu2()
    genevep4_multip4_grei62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 3


def gre6k__multip4_tunnel3():

    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gre local fd1d:fc98:b73e:b681::1 remote fd1d:fc98:b73e:b681::2\n"
        )
        f.write("ip -6 addr add 2002:851a::1/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002:851a::2/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multip4_tunnel3():

    gre6k__multip4_tunnel3()
    ip_address = "2002:851a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre63_service()
    gre63_cronjob()


def kharejp4_gre6_menu3():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b681::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b681::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b681::1/64 dev azumi3\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b681::2/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    rungen_pingz3()  # geninja3
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b681::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    kharej_gre6multip4_tunnel3()


def geneve_multip4_grek63():
    ufw("2001:db5::1")
    ufw("2001:db5::2")
    ufw("2002:851a::1")
    ufw("2002:851a::2")
    ufw("fd1d:fc98:b73e:b681::1")
    ufw("fd1d:fc98:b73e:b681::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:851a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote 2002:851a::2\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::1/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::2/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen5_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db5::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_kharej_gre3():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    kharejp4_gre6_menu3()
    geneve_multip4_grek63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_kharej2_gre3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    kharejp4_gre6_menu3()
    geneve_multip4_grek63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multip4_tunnel3():

    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gre local fd1d:fc98:b73e:b681::2 remote fd1d:fc98:b73e:b681::1\n"
        )
        f.write("ip -6 addr add 2002:851a::2/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002:851a::1/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multip4_tunnel3():

    gre6i__multip4_tunnel3()
    ip_address = "2002:851a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre63_service()
    gre63_cronjob()


def iranp4_gre6_menu3():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b681::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b681::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b681::2/64 dev azumi3\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b681::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran3_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b681::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    iran_gre6multip4_tunnel3()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def genevep4_multip4_grei63():
    ufw("2001:db5::1")
    ufw("2001:db5::2")
    ufw("2002:851a::1")
    ufw("2002:851a::2")
    ufw("fd1d:fc98:b73e:b681::1")
    ufw("fd1d:fc98:b73e:b681::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:851a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote 2002:851a::1\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::2/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::1/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen6_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db5::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_iran_gre3():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    iranp4_gre6_menu3()
    genevep4_multip4_grei63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_iran2_gre3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    iranp4_gre6_menu3()
    genevep4_multip4_grei63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 4


def gre6k__multip4_tunnel4():

    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gre local fd1d:fc98:b73e:b781::1 remote fd1d:fc98:b73e:b781::2\n"
        )
        f.write("ip -6 addr add 2002:861a::1/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002:861a::2/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multip4_tunnel4():

    gre6k__multip4_tunnel4()
    ip_address = "2002:861a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre64_service()
    gre64_cronjob()


def kharejp4_gre6_menu4():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b781::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b781::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b781::1/64 dev azumi4\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b781::2/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    rungen_pingz4()  # geninja4
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b781::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    kharej_gre6multip4_tunnel4()


def geneve_multip4_grek64():
    ufw("2001:db6::1")
    ufw("2001:db6::2")
    ufw("2002:861a::1")
    ufw("2002:861a::2")
    ufw("fd1d:fc98:b73e:b781::1")
    ufw("fd1d:fc98:b73e:b781::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:861a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote 2002:861a::2\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::1/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::2/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen7_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db6::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_kharej_gre4():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    kharejp4_gre6_menu4()
    geneve_multip4_grek64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_kharej2_gre4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    kharejp4_gre6_menu4()
    geneve_multip4_grek64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multip4_tunnel4():

    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gre local fd1d:fc98:b73e:b781::2 remote fd1d:fc98:b73e:b781::1\n"
        )
        f.write("ip -6 addr add 2002:861a::2/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002:861a::1/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multip4_tunnel4():

    gre6i__multip4_tunnel4()
    ip_address = "2002:861a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre64_service()
    gre64_cronjob()


def iranp4_gre6_menu4():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b781::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b781::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b781::2/64 dev azumi4\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b781::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran4_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b781::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    iran_gre6multip4_tunnel4()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def genevep4_multip4_grei64():
    ufw("2001:db6::1")
    ufw("2001:db6::2")
    ufw("2002:861a::1")
    ufw("2002:861a::2")
    ufw("fd1d:fc98:b73e:b781::1")
    ufw("fd1d:fc98:b73e:b781::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:861a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote 2002:861a::1\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::2/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::1/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen8_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db6::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_iran_gre4():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    iranp4_gre6_menu4()
    genevep4_multip4_grei64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_iran2_gre4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    iranp4_gre6_menu4()
    genevep4_multip4_grei64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 5
def gre6k__multip4_tunnel5():

    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gre local fd1d:fc98:b73e:b881::1 remote fd1d:fc98:b73e:b881::2\n"
        )
        f.write("ip -6 addr add 2002:871a::1/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002:871a::2/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multip4_tunnel5():

    gre6k__multip4_tunnel5()
    ip_address = "2002:871a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre65_service()
    gre65_cronjob()


def kharejp4_gre6_menu5():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b881::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b881::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b881::1/64 dev azumi5\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b881::2/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    rungen_pingz5()  # geninja5
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b881::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    kharej_gre6multip4_tunnel5()


def geneve_multip4_grek65():
    ufw("2001:db7::1")
    ufw("2001:db7::2")
    ufw("2002:871a::1")
    ufw("2002:871a::2")
    ufw("fd1d:fc98:b73e:b881::1")
    ufw("fd1d:fc98:b73e:b881::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:871a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote 2002:871a::2\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::1/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::2/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen9_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db7::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_kharej_gre5():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    kharejp4_gre6_menu5()
    geneve_multip4_grek65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_kharej2_gre5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    kharejp4_gre6_menu5()
    geneve_multip4_grek65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multip4_tunnel5():

    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gre local fd1d:fc98:b73e:b881::2 remote fd1d:fc98:b73e:b881::1\n"
        )
        f.write("ip -6 addr add 2002:871a::2/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002:871a::1/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multip4_tunnel5():

    gre6i__multip4_tunnel5()
    ip_address = "2002:871a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre65_service()
    gre65_cronjob()


def iranp4_gre6_menu5():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b881::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b881::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b881::2/64 dev azumi5\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b881::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran5_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b881::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    iran_gre6multip4_tunnel5()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def genevep4_multip4_grei65():
    ufw("2001:db7::1")
    ufw("2001:db7::2")
    ufw("2002:871a::1")
    ufw("2002:871a::2")
    ufw("fd1d:fc98:b73e:b881::1")
    ufw("fd1d:fc98:b73e:b881::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:871a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote 2002:871a::1\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::2/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::1/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen10_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db7::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def genp4_iran_gre5():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    iranp4_gre6_menu5()
    genevep4_multip4_grei65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def genp4_iran2_gre5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    iranp4_gre6_menu5()
    genevep4_multip4_grei65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# gen native multi
def gengre_native_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve \033[92mGRE6 \033[96mNative\033[93m Multi Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5_gen_gre()
            break
        elif server_type == "2":
            kharej12_gen_gre()
            break
        elif server_type == "3":
            clear()
            gen_multi_menuz()
            break
        else:
            print("Invalid choice.")


def kharej5_gen_gre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mNative \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_kharej_gre1()
            break
        elif server_type == "2":
            gen_kharej_gre2()
            break
        elif server_type == "3":
            gen_kharej_gre3()
            break
        elif server_type == "4":
            gen_kharej_gre4()
            break
        elif server_type == "5":
            gen_kharej_gre5()
            break
        elif server_type == "6":
            iran_question()
            break
        elif server_type == "0":
            clear()
            gengre_native_ip()
            break
        else:
            print("Invalid choice.")


def iran_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gen_iran2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def kharej12_gen_gre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mNative \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_iran_gre1()
            break
        elif server_type == "2":
            gen_iran_gre2()
            break
        elif server_type == "3":
            gen_iran_gre3()
            break
        elif server_type == "4":
            gen_iran_gre4()
            break
        elif server_type == "5":
            gen_iran_gre5()
            break
        elif server_type == "6":
            kharej_question()
            break
        elif server_type == "0":
            clear()
            gengre_native_ip()
            break
        else:
            print("Invalid choice.")


def kharej_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gen_kharej2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def gre6k__multi_tunnel1():
    global local_ip, remote_ip
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:831a::1/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002:831a::2/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multi_tunnel1():
    global local_ip, remote_ip
    gre6k__multi_tunnel1()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre61_service()
    gre61_cronjob()


def geneve_multi_grek61():
    ufw("2001:db3::1")
    ufw("2001:db3::2")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::1/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::2/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen1_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db3::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_kharej_gre1():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6multi_tunnel1()
    geneve_multi_grek61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_kharej2_gre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6multi_tunnel1()
    geneve_multi_grek61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multi_tunnel1():
    global local_ip, remote_ip
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:831a::2/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002:831a::1/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multi_tunnel1():
    global local_ip, remote_ip
    gre6i__multi_tunnel1()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre61_service()
    gre61_cronjob()


def geneve_multi_grei61():
    ufw("2001:db3::1")
    ufw("2001:db3::2")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen1",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen1", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db3::2/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db3::1/64", "dev", "azumigen1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys1.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen1 type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen1 up\n")
        f.write("sudo ip addr add 2001:db3::2/64 dev azumigen1\n")
        f.write("sudo ip route add 2001:db3::1/64 dev azumigen1\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"
        with open("/etc/sys1.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen2_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db3::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db3::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping1_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping1_sys.sh", 0o755)
    ping_kh1_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_iran_gre1():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6multi_tunnel1()
    geneve_multi_grei61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_iran2_gre1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6multi_tunnel1()
    geneve_multi_grei61()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 2


def gre6k__multi_tunnel2():
    global local_ip, remote_ip
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:841a::1/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002:841a::2/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multi_tunnel2():
    global local_ip, remote_ip
    gre6k__multi_tunnel2()
    ip_address = "2002:841a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre62_service()
    gre62_cronjob()


def geneve_multi_grek62():
    ufw("2001:db4::1")
    ufw("2001:db4::2")
    ufw("2002:841a::1")
    ufw("2002:841a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:841a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote 2002:841a::2\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::1/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::2/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen3_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db4::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_kharej_gre2():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6multi_tunnel2()
    geneve_multi_grek62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_kharej2_gre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6multi_tunnel2()
    geneve_multi_grek62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multi_tunnel2():
    global local_ip, remote_ip
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:841a::2/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002:841a::1/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multi_tunnel2():
    global local_ip, remote_ip
    gre6i__multi_tunnel2()
    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre62_service()
    gre62_cronjob()


def geneve_multi_grei62():
    ufw("2001:db4::1")
    ufw("2001:db4::2")
    ufw("2002:841a::1")
    ufw("2002:841a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen2",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:841a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen2", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db4::2/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db4::1/64", "dev", "azumigen2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys2.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen2 type geneve id 1000 remote 2002:841a::1\n"
        )
        f.write("sudo ip link set azumigen2 up\n")
        f.write("sudo ip addr add 2001:db4::2/64 dev azumigen2\n")
        f.write("sudo ip route add 2001:db4::1/64 dev azumigen2\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"
        with open("/etc/sys2.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen4_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db4::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db4::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping2_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping2_sys.sh", 0o755)
    ping_kh2_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_iran_gre2():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6multi_tunnel2()
    geneve_multi_grei62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_iran2_gre2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6multi_tunnel2()
    geneve_multi_grei62()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 3


def gre6k__multi_tunnel3():
    global local_ip, remote_ip
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:851a::1/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002:851a::2/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multi_tunnel3():
    global local_ip, remote_ip
    gre6k__multi_tunnel3()
    ip_address = "2002:851a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre63_service()
    gre63_cronjob()


def geneve_multi_grek63():
    ufw("2001:db5::1")
    ufw("2001:db5::2")
    ufw("2002:851a::1")
    ufw("2002:851a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:851a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote 2002:851a::2\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::1/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::2/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen5_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db5::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_kharej_gre3():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6multi_tunnel3()
    geneve_multi_grek63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_kharej2_gre3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6multi_tunnel3()
    geneve_multi_grek63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multi_tunnel3():
    global local_ip, remote_ip
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:851a::2/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002:851a::1/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multi_tunnel3():
    global local_ip, remote_ip
    gre6i__multi_tunnel3()
    ip_address = "2002:851a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre63_service()
    gre63_cronjob()


def geneve_multi_grei63():
    ufw("2001:db5::1")
    ufw("2001:db5::2")
    ufw("2002:851a::1")
    ufw("2002:851a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen3",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:851a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen3", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db5::2/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db5::1/64", "dev", "azumigen3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys3.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen3 type geneve id 1000 remote 2002:851a::1\n"
        )
        f.write("sudo ip link set azumigen3 up\n")
        f.write("sudo ip addr add 2001:db5::2/64 dev azumigen3\n")
        f.write("sudo ip route add 2001:db5::1/64 dev azumigen3\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"
        with open("/etc/sys3.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen6_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db5::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db5::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping3_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping3_sys.sh", 0o755)
    ping_kh3_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_iran_gre3():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6multi_tunnel3()
    geneve_multi_grei63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_iran2_gre3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6multi_tunnel3()
    geneve_multi_grei63()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 4


def gre6k__multi_tunnel4():
    global local_ip, remote_ip
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:861a::1/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002:861a::2/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multi_tunnel4():
    global local_ip, remote_ip
    gre6k__multi_tunnel4()
    ip_address = "2002:861a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre64_service()
    gre64_cronjob()


def geneve_multi_grek64():
    ufw("2001:db6::1")
    ufw("2001:db6::2")
    ufw("2002:861a::1")
    ufw("2002:861a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:861a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote 2002:861a::2\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::1/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::2/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen7_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db6::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_kharej_gre4():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6multi_tunnel4()
    geneve_multi_grek64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_kharej2_gre4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6multi_tunnel4()
    geneve_multi_grek64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multi_tunnel4():
    global local_ip, remote_ip
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:861a::2/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002:861a::1/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multi_tunnel4():
    global local_ip, remote_ip
    gre6i__multi_tunnel4()
    ip_address = "2002:861a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre64_service()
    gre64_cronjob()


def geneve_multi_grei64():
    ufw("2001:db6::1")
    ufw("2001:db6::2")
    ufw("2002:861a::1")
    ufw("2002:861a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen4",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:861a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen4", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db6::2/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db6::1/64", "dev", "azumigen4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys4.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen4 type geneve id 1000 remote 2002:861a::1\n"
        )
        f.write("sudo ip link set azumigen4 up\n")
        f.write("sudo ip addr add 2001:db6::2/64 dev azumigen4\n")
        f.write("sudo ip route add 2001:db6::1/64 dev azumigen4\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"
        with open("/etc/sys4.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen8_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db6::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db6::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping4_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping4_sys.sh", 0o755)
    ping_kh4_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_iran_gre4():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6multi_tunnel4()
    geneve_multi_grei64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_iran2_gre4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6multi_tunnel4()
    geneve_multi_grei64()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 5


def gre6k__multi_tunnel5():
    global local_ip, remote_ip
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:871a::1/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002:871a::2/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def kharej_gre6multi_tunnel5():
    global local_ip, remote_ip
    gre6k__multi_tunnel5()
    ip_address = "2002:871a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre65_service()
    gre65_cronjob()


def geneve_multi_grek65():
    ufw("2001:db7::1")
    ufw("2001:db7::2")
    ufw("2002:871a::1")
    ufw("2002:871a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:871a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote 2002:871a::2\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::1/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::2/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen9_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db7::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_kharej_gre5():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6multi_tunnel5()
    geneve_multi_grek65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_kharej2_gre5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6multi_tunnel5()
    geneve_multi_grek65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran
def gre6i__multi_tunnel5():
    global local_ip, remote_ip
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gre local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:871a::2/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002:871a::1/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(["bash", file_path], check=True)


def iran_gre6multi_tunnel5():
    global local_ip, remote_ip
    gre6i__multi_tunnel5()
    ip_address = "2002:871a::1"  # kharejip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    iran_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre65_service()
    gre65_cronjob()


def geneve_multi_grei65():
    ufw("2001:db7::1")
    ufw("2001:db7::2")
    ufw("2002:871a::1")
    ufw("2002:871a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen5",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:871a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen5", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db7::2/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "2001:db7::1/64", "dev", "azumigen5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys5.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen5 type geneve id 1000 remote 2002:871a::1\n"
        )
        f.write("sudo ip link set azumigen5 up\n")
        f.write("sudo ip addr add 2001:db7::2/64 dev azumigen5\n")
        f.write("sudo ip route add 2001:db7::1/64 dev azumigen5\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"
        with open("/etc/sys5.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    gen10_ping()

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db7::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db7::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping5_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping5_sys.sh", 0o755)
    ping_kh5_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[93mDon't forget to use \033[96mufw reload \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")


def gen_iran_gre5():
    global local_ip, remote_ip
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6multi_tunnel5()
    geneve_multi_grei65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_iran2_gre5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6multi_tunnel5()
    geneve_multi_grei65()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gen_ipsec_multi1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mGeneve + IPsec \033[93mMulti Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGen IPsec IPV4  \033[0m")
    print("2. \033[93mGen IPsec Native\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen11_multi_ip4sec()
            break
        elif server_type == "2":
            gen11_ipsec_native()
            break
        elif server_type == "0":
            clear()
            gen_multi_menuz()
            break
        else:
            print("Invalid choice.")


def gen11_multi_ip4sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mIPSec \033[93mIPV4 Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej51_ipsec_gen()
            break
        elif server_type == "2":
            kharej1_ipsec_gen()
            break
        elif server_type == "3":
            clear()
            gen_ipsec_multi1()
            break
        else:
            print("Invalid choice.")


def kharej51_ipsec_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92m[5]Kharej\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            kharej5_s1()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            kharej5_s2()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            kharej5_s3()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            kharej5_s4()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            kharej5_s5()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            iran11_ipsec_gen()
            break
        elif server_type == "0":
            clear()
            gen11_multi_ip4sec()
            break
        else:
            print("Invalid choice.")


def iran11_ipsec_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have? :\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "iran52_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def iran11_ipsec_genedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have? :\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def iran11_ipsec_genedit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mKharej Servers\033[93m do you have s\033[96mright now? :\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipsecgeni(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    restart_forced_strongazumi()


def kharej1_ipsec_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92m[5]IRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            iran5_s1()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            iran5_s2()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            iran5_s3()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            iran5_s4()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            iran5_s5()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            kharej11_ipsec_gen()
            break
        elif server_type == "0":
            clear()
            gen11_multi_ip4sec()
            break
        else:
            print("Invalid choice.")


def kharej11_ipsec_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have? :\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "kharej52_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def kharej11_ipsec_genedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have? :\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def kharej11_ipsec_genedit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now? :\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipsecgenk(psk, num_servers)
    restart_forced_strongazumi()


# pre
def config_ipsecgenk(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn Geneve{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2001:db{i+3}::1/64\n")
            f.write(f"  leftid=2001:db{i+3}::1\n")
            f.write(f"  right=2001:db{i+3}::2\n")
            f.write(f"  rightsubnet=2001:db{i+3}::2/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2001:db{i+3}::2 2001:db{i+3}::1 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecgeni(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn Geneve{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2001:db{i+3}::2/64\n")
            f.write(f"  leftid=2001:db{i+3}::2\n")
            f.write(f"  right=2001:db{i+3}::1\n")
            f.write(f"  rightsubnet=2001:db{i+3}::1/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2001:db{i+3}::1 2001:db{i+3}::2 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsec_genk1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db3::1/64
  leftid=2001:db3::1
  right=2001:db3::2
  rightsubnet=2001:db3::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db3::2 2001:db3::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


# new
def new1():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_genk1(psk)


def new2():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_genk2(psk)


def config_ipsec_genk2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db4::1/64
  leftid=2001:db4::1
  right=2001:db4::2
  rightsubnet=2001:db4::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db4::2 2001:db4::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def new3():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_genk3(psk)


def config_ipsec_genk3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db5::1/64
  leftid=2001:db5::1
  right=2001:db5::2
  rightsubnet=2001:db5::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db5::2 2001:db5::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def new4():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_genk4(psk)


def config_ipsec_genk4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db6::1/64
  leftid=2001:db6::1
  right=2001:db6::2
  rightsubnet=2001:db6::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db6::2 2001:db6::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def new5():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_genk5(psk)


def config_ipsec_genk5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db7::1/64
  leftid=2001:db7::1
  right=2001:db7::2
  rightsubnet=2001:db7::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db7::2 2001:db7::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


# iran config
def newi1():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_geni1(psk)


def config_ipsec_geni1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db3::2/64
  leftid=2001:db3::2
  right=2001:db3::1
  rightsubnet=2001:db3::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db3::1 2001:db3::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def newi2():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_geni2(psk)


def config_ipsec_geni2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db4::2/64
  leftid=2001:db4::2
  right=2001:db4::1
  rightsubnet=2001:db4::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db4::1 2001:db4::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def newi3():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_geni3(psk)


def config_ipsec_geni3(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db5::2/64
  leftid=2001:db5::2
  right=2001:db5::1
  rightsubnet=2001:db5::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db5::1 2001:db5::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def newi4():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_geni4(psk)


def config_ipsec_geni4(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db6::2/64
  leftid=2001:db6::2
  right=2001:db6::1
  rightsubnet=2001:db6::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db6::1 2001:db6::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def newi5():
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsec_geni5(psk)


def config_ipsec_geni5(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn erspan5
  left=%defaultroute
  leftsubnet=2001:db7::2/64
  leftid=2001:db7::2
  right=2001:db7::1
  rightsubnet=2001:db7::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2001:db7::1 2001:db7::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


# native
def gen11_ipsec_native():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mIPsec Native\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5n_ipsec_gen()
            break
        elif server_type == "2":
            kharej1n_ipsec_gen()
            break
        elif server_type == "3":
            clear()
            gen_ipsec_multi1()
            break
        else:
            print("Invalid choice.")


def kharej5n_ipsec_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mIPsec [5]Kharej\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            kharej5n_s1()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            kharej5n_s2()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            kharej5n_s3()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            kharej5n_s4()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            kharej5n_s5()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            iran1_ipsecn_gen()
            break
        elif server_type == "0":
            clear()
            gen11_ipsec_native()
            break
        else:
            print("Invalid choice.")


def iran1_ipsecn_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "iran52n_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def iran1_ipsecn_genedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    restart_forced_strongazumi()


def kharej1n_ipsec_gen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mIPsec [5]IRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            iran5n_s1()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            iran5n_s2()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            iran5n_s3()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            iran5n_s4()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            iran5n_s5()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            kharej1_ipsecn_gen()
            break
        elif server_type == "0":
            clear()
            gen11_ipsec_native()
            break
        else:
            print("Invalid choice.")


def kharej1_ipsecn_gen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "kharej52n_s{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def kharej1_ipsecn_genedit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    restart_forced_strongazumi()


def gen_ipsec_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mGeneve GRE6 + IPsec \033[93mMulti Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGen IPsec IPV4  \033[0m")
    print("2. \033[93mGen IPsec Native\033[0m")
    print("0. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gengre_multi_ip4sec()
            break
        elif server_type == "2":
            gengre_multin_ip6sec()
            break
        elif server_type == "0":
            clear()
            gen_multi_menuz()
            break
        else:
            print("Invalid choice.")


def gengre_multin_ip6sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve \033[92mGRE6 \033[96mNative\033[93m Multi Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5_ipsecgen_gre()
            break
        elif server_type == "2":
            kharej11_ipsecgen_gre()
            break
        elif server_type == "3":
            clear()
            gen_ipsec_multi2()
            break
        else:
            print("Invalid choice.")


def kharej5_ipsecgen_gre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mNative \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[92mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            gen_kharej_gre1()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            gen_kharej_gre2()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            gen_kharej_gre3()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            gen_kharej_gre4()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            gen_kharej_gre5()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            iran_ipsecz_question()
            break
        elif server_type == "0":
            clear()
            gengre_multin_ip6sec()
            break
        else:
            print("Invalid choice.")


def iran_ipsecz_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "gen_iran2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def iran_ipsecz_questione():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def iran_ipsecz_questione2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mKharej Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    restart_forced_strongazumi()


def kharej11_ipsecgen_gre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mNative \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[92mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            gen_iran_gre1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            gen_iran_gre2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            gen_iran_gre3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            gen_iran_gre4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            gen_iran_gre5()
            break
        elif server_type == "6":
            kharej_ipsecz_question()
            break
        elif server_type == "0":
            clear()
            gengre_multin_ip6sec()
            break
        else:
            print("Invalid choice.")


def kharej_ipsecz_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "gen_kharej2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


# edit
def kharej_ipsecz_questione():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)


# edit2
def kharej_ipsecz_questione2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipsecgenk(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


# ipsec gre6 ipv4
def gengre_multi_ip4sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve \033[92mGRE6 IPsec \033[96mIPV4\033[93m Multi Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN \033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5_genp4_ipsecgre()
            break
        elif server_type == "2":
            kharej1_genp4_ipsecgre()
            break
        elif server_type == "3":
            clear()
            gen_ipsec_multi2()
            break
        else:
            print("Invalid choice.")


def kharej5_genp4_ipsecgre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mIPV4 \033[93m+\033[92m Gre6 IPsec \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[92mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[93mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            genp4_kharej_gre1()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            genp4_kharej_gre2()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            genp4_kharej_gre3()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            genp4_kharej_gre4()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            genp4_kharej_gre5()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            iranp4_ipsec_question()
            break
        elif server_type == "0":
            clear()
            gengre_multi_ip4sec()
            break
        else:
            print("Invalid choice.")


def iranp4_ipsec_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "genp4_iran2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def iranp4_ipsec_questione():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgeni(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def iranp4_ipsec_questione2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mKharej Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipsecgeni(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    restart_forced_strongazumi()


def kharej1_genp4_ipsecgre():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mIPV4 \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[92mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[93mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            genp4_iran_gre1()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            genp4_iran_gre2()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            genp4_iran_gre3()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            genp4_iran_gre4()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            genp4_iran_gre5()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            kharejp4_ipsec_question()
            break
        elif server_type == "0":
            clear()
            gengre_multi_ip4sec()
            break
        else:
            print("Invalid choice.")


def kharejp4_ipsec_question():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "genp4_kharej2_gre{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def kharejp4_ipsec_questione():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def kharejp4_ipsec_questione2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    enable_reset_ipsec()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m: \033[0m")
    config_ipsecgenk(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    restart_forced_strongazumi()


## gre6tap simple
def gre6tapmulti_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGRE6tap Multi\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE6tap IPV4 Multi \033[0m")
    print("2. \033[93mGRE6tap Native Multi \033[0m")
    print("3. \033[92mGRE6tap IPV4 + \033[96mIPsec\033[92m Multi \033[0m")
    print("4. \033[93mGRE6tap Native + \033[96mIPsec\033[92m Multi \033[0m")
    print("5. \033[93mIPsec Reset Timer\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnu()
            gretap4m()
            break
        elif server_type == "2":
            gre6_reset_rmvmnu()
            gretapnm()
            break
        elif server_type == "3":
            gre6_reset_rmvmnu()
            gretap4m1()
            break
        elif server_type == "4":
            gre6_reset_rmvmnu()
            gretapnm1()
            break
        elif server_type == "5":
            choose_reset2()
            break
        elif server_type == "0":
            clear()
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


# ip4 start
def gretap4m():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mIPV4 \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10] Kharej [1] IRAN\033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap4mu_k()
            break
        elif server_type == "2":
            gre6tap4mu_i()
            break
        elif server_type == "3":
            clear()
            gre6tapmulti_mnu
            break
        else:
            print("Invalid choice.")


def gre6tap4mu_k():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mIPV4 \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("6. \033[92mKharej [6]\033[0m")
    print("7. \033[92mKharej [7]\033[0m")
    print("8. \033[93mKharej [8]\033[0m")
    print("9. \033[92mKharej [9]\033[0m")
    print("10.\033[92mKharej [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[96mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap6_kharejz1()
            break
        elif server_type == "2":
            gre6tap6_kharejz2()
            break
        elif server_type == "3":
            gre6tap6_kharejz3()
            break
        elif server_type == "4":
            gre6tap6_kharejz4()
            break
        elif server_type == "5":
            gre6tap6_kharejz5()
            break
        elif server_type == "6":
            gre6tap6_kharejz6()
            break
        elif server_type == "7":
            gre6tap6_kharejz7()
            break
        elif server_type == "8":
            gre6tap6_kharejz8()
            break
        elif server_type == "9":
            gre6tap6_kharejz9()
            break
        elif server_type == "10":
            gre6tap6_kharejz10()
            break
        elif server_type == "11":
            irangretap4_q()
            break
        elif server_type == "0":
            clear()
            gretap4m()
            break
        else:
            print("Invalid choice.")


def irangretap4_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6tap62_iranz{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def gre6tap4mu_i():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mIPV4 \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[96mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap6_iranz1()
            break
        elif server_type == "2":
            gre6tap6_iranz2()
            break
        elif server_type == "3":
            gre6tap6_iranz3()
            break
        elif server_type == "4":
            gre6tap6_iranz4()
            break
        elif server_type == "5":
            gre6tap6_iranz5()
            break
        elif server_type == "6":
            kharejgretap4_q()
            break
        elif server_type == "0":
            clear()
            gretap4m()
            break
        else:
            print("Invalid choice.")


def kharejgretap4_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6tap62_kharejz{}".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))


def ping_v64_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v64.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v64.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v64.service"])
    subprocess.run(["systemctl", "start", "ping_v64.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v64.service"])


def ping_v65_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v65.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v65.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v65.service"])
    subprocess.run(["systemctl", "start", "ping_v65.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v65.service"])


def add_cron4_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private4.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private4.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def add_cron5_job():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/private5.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/private5.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_gre64_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip4.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip4.service"])
    subprocess.run(["systemctl", "start", "ping_ip4.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip4.service"])


def iran_gre65_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip5.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip5.service"])
    subprocess.run(["systemctl", "start", "ping_ip5.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip5.service"])


## gre6tap ip4 server 1


def rungen_pingz1():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b481::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def run_pingz1():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b081::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel1(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:801a::1/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig61\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:80{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:801a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_tunnel1sec(remote_ip, local_ip):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:801a::1/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002:801a::2/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:801a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz1():
    remote_ip = "fd1d:fc98:b73e:b081::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b081::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel1(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:801a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre61_service()

    gre61_cronjob()


def gre6tap_kharejz1sec():
    remote_ip = "fd1d:fc98:b73e:b081::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b081::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6tap_tunnel1sec(remote_ip, local_ip)

    ip_address = "2002:801a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping1_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre61_service()

    gre61_cronjob()


def kharej_gretap6_menu1():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b081::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b081::1/64 dev azumi1\n")
        f.write("ip -6 route add fd1d::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b081::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz1()
    sleep(1)


def kharej_gretap6_menu1sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b081::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b081::2/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b081::1/64 dev azumi1\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b081::2/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz1()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b081::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz1sec()
    sleep(1)


def gretap6_iranz1():
    remote_ip = "fd1d:fc98:b73e:b081::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b081::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz1(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:801a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre61_service()

    gre61_cronjob()


def gretap6_iranz1sec():
    remote_ip = "fd1d:fc98:b73e:b081::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b081::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gretap6_iran_tunnelz1sec(remote_ip, local_ip)

    ip_address = "2002:801a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping1_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre61_service()

    gre61_cronjob()


def gretap6_iran_tunnelz1(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:801a::2/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig61\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:80{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:801a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gretap6_iran_tunnelz1sec(remote_ip, local_ip):
    file_path = "/etc/gre61.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig61 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:801a::2/64 dev azumig61\n")
        f.write("ip link set azumig61 up\n")
        f.write("ip -6 route add 2002:801a::1/64 dev azumig61\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:801a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran1_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b081::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu1():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b081::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b081::2/64 dev azumi1\n")
        f.write("ip -6 route add fd1d::/16 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran1_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b081::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    gretap6_iranz1()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def iran_gretap6_menu1sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private1.sh"):
        os.remove("/etc/private1.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi1",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi1", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b081::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi1"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b081::1/64", "dev", "azumi1"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private1.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi1 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi1 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b081::2/64 dev azumi1\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b081::1/64 dev azumi1\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"
        with open("/etc/private1.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private1.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron1_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran1_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b081::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v61.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v61.sh", 0o755)
    ping_v61_service()
    gretap6_iranz1sec()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 2
def rungen_pingz2():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b581::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def run_pingz2():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b181::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel2(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:811a::1/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig62\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:81{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:811a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_tunnel2sec(remote_ip, local_ip):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:811a::1/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002:811a::2/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:811a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz2():
    remote_ip = "fd1d:fc98:b73e:b181::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b181::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel2(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:811a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre62_service()

    gre62_cronjob()


def gre6tap_kharejz2sec():
    remote_ip = "fd1d:fc98:b73e:b181::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b181::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6tap_tunnel2sec(remote_ip, local_ip)

    ip_address = "2002:811a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping2_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre62_service()

    gre62_cronjob()


def kharej_gretap6_menu2():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b181::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b181::1/64 dev azumi2\n")
        f.write("ip -6 route add fd1d::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b181::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz2()
    sleep(1)


def kharej_gretap6_menu2sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b181::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b181::2/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b181::1/64 dev azumi2\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b181::2/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz2()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b181::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz2sec()
    sleep(1)


def gretap6_iranz2():
    remote_ip = "fd1d:fc98:b73e:b181::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b181::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz2(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:811a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre62_service()

    gre62_cronjob()


def gretap6_iranz2sec():
    remote_ip = "fd1d:fc98:b73e:b181::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b181::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gretap6_iran_tunnelz2sec(remote_ip, local_ip)

    ip_address = "2002:811a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping2_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre62_service()

    gre62_cronjob()


def gretap6_iran_tunnelz2(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:811a::2/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig62\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:81{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gretap6_iran_tunnelz2sec(remote_ip, local_ip):
    file_path = "/etc/gre62.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig62 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:811a::2/64 dev azumig62\n")
        f.write("ip link set azumig62 up\n")
        f.write("ip -6 route add 2002:811a::1/64 dev azumig62\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:811a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran2_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b181::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu2():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b181::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b181::2/64 dev azumi2\n")
        f.write("ip -6 route add fd1d::/16 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran2_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b181::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    gretap6_iranz2()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def iran_gretap6_menu2sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private2.sh"):
        os.remove("/etc/private2.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi2",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi2", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b181::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi2"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b181::1/64", "dev", "azumi2"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private2.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi2 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi2 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b181::2/64 dev azumi2\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b181::1/64 dev azumi2\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"
        with open("/etc/private2.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private2.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron2_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran2_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b181::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v62.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v62.sh", 0o755)
    ping_v62_service()
    gretap6_iranz2sec()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 3


def rungen_pingz3():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b681::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def run_pingz3():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b281::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel3(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:821a::1/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig63\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:82{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_tunnel3sec(remote_ip, local_ip):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:821a::1/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002:821a::2/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz3():
    remote_ip = "fd1d:fc98:b73e:b281::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b281::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel3(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:821a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre63_service()

    gre63_cronjob()


def gre6tap_kharejz3sec():
    remote_ip = "fd1d:fc98:b73e:b281::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b281::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6tap_tunnel3sec(remote_ip, local_ip)

    ip_address = "2002:821a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping3_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre63_service()

    gre63_cronjob()


def kharej_gretap6_menu3():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b281::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b281::1/64 dev azumi3\n")
        f.write("ip -6 route add fd1d::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b281::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz3()
    sleep(1)


def kharej_gretap6_menu3sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b281::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b281::2/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b281::1/64 dev azumi3\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b281::2/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz3()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b281::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz3sec()
    sleep(1)


def gretap6_iranz3():
    remote_ip = "fd1d:fc98:b73e:b281::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b281::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz3(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:821a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre63_service()

    gre63_cronjob()


def gretap6_iranz3sec():
    remote_ip = "fd1d:fc98:b73e:b281::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b281::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gretap6_iran_tunnelz3sec(remote_ip, local_ip)

    ip_address = "2002:821a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping3_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre63_service()

    gre63_cronjob()


def gretap6_iran_tunnelz3(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:821a::2/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig63\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:82{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gretap6_iran_tunnelz3sec(remote_ip, local_ip):
    file_path = "/etc/gre63.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig63 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:821a::2/64 dev azumig63\n")
        f.write("ip link set azumig63 up\n")
        f.write("ip -6 route add 2002:821a::1/64 dev azumig63\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:821a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran3_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b281::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu3():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b281::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b281::2/64 dev azumi3\n")
        f.write("ip -6 route add fd1d::/16 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran3_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b281::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    gretap6_iranz3()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def iran_gretap6_menu3sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private3.sh"):
        os.remove("/etc/private3.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi3",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi3", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b281::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi3"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b281::1/64", "dev", "azumi3"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private3.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi3 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi3 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b281::2/64 dev azumi3\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b281::1/64 dev azumi3\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"
        with open("/etc/private3.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private3.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron3_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran3_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b281::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v63.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v63.sh", 0o755)
    ping_v63_service()
    gretap6_iranz3sec()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz3():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 4


def rungen_pingz4():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b781::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def run_pingz4():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b381::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel4(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:831a::1/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig64\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:83{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_tunnel4sec(remote_ip, local_ip):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:831a::1/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002:831a::2/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz4():
    remote_ip = "fd1d:fc98:b73e:b381::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b381::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel4(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre64_service()

    gre64_cronjob()


def gre6tap_kharejz4sec():
    remote_ip = "fd1d:fc98:b73e:b381::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b381::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6tap_tunnel4sec(remote_ip, local_ip)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping4_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre64_service()

    gre64_cronjob()


def kharej_gretap6_menu4():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b381::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b381::1/64 dev azumi4\n")
        f.write("ip -6 route add fd1d::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b381::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz4()
    sleep(1)


def kharej_gretap6_menu4sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b381::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b381::2/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b381::1/64 dev azumi4\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b381::2/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz4()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b381::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz4sec()
    sleep(1)


def gretap6_iranz4():
    remote_ip = "fd1d:fc98:b73e:b381::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b381::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz4(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre64_service()

    gre64_cronjob()


def gretap6_iranz4sec():
    remote_ip = "fd1d:fc98:b73e:b381::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b381::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gretap6_iran_tunnelz4sec(remote_ip, local_ip)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping4_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre64_service()

    gre64_cronjob()


def gretap6_iran_tunnelz4(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:831a::2/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig64\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:83{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gretap6_iran_tunnelz4sec(remote_ip, local_ip):
    file_path = "/etc/gre64.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig64 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:831a::2/64 dev azumig64\n")
        f.write("ip link set azumig64 up\n")
        f.write("ip -6 route add 2002:831a::1/64 dev azumig64\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran4_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b381::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu4():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b381::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b381::2/64 dev azumi4\n")
        f.write("ip -6 route add fd1d::/16 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran4_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b381::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    gretap6_iranz4()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def iran_gretap6_menu4sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private4.sh"):
        os.remove("/etc/private4.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi4",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi4", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b381::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi4"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b381::1/64", "dev", "azumi4"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private4.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi4 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi4 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b381::2/64 dev azumi4\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b381::1/64 dev azumi4\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"
        with open("/etc/private4.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private4.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron4_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran4_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b381::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v64.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v64.sh", 0o755)
    ping_v64_service()
    gretap6_iranz4sec()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz4():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 5
def rungen_pingz5():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b881::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def run_pingz5():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b481::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel5(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:841a::1/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig65\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:84{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_tunnel5sec(remote_ip, local_ip):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:841a::1/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002:841a::2/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz5():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel5(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:841a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre65_service()

    gre65_cronjob()


def gre6tap_kharejz5sec():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6tap_tunnel5sec(remote_ip, local_ip)

    ip_address = "2002:841a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping5_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre65_service()

    gre65_cronjob()


def kharej_gretap6_menu5():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi5\n")
        f.write("ip -6 route add fd1d::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz5()
    sleep(1)


def kharej_gretap6_menu5sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::2/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi5\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::2/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz5()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz5sec()
    sleep(1)


def gretap6_iranz5():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz5(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre65_service()

    gre65_cronjob()


def gretap6_iranz5sec():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gretap6_iran_tunnelz5sec(remote_ip, local_ip)

    ip_address = "2002:841a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping5_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre65_service()

    gre65_cronjob()


def gretap6_iran_tunnelz5(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:841a::2/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig65\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:84{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gretap6_iran_tunnelz5sec(remote_ip, local_ip):
    file_path = "/etc/gre65.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig65 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:841a::2/64 dev azumig65\n")
        f.write("ip link set azumig65 up\n")
        f.write("ip -6 route add 2002:841a::1/64 dev azumig65\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:841a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran5_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b481::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu5():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi5\n")
        f.write("ip -6 route add fd1d::/16 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran5_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    gretap6_iranz5()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def iran_gretap6_menu5sec():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private5.sh"):
        os.remove("/etc/private5.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi5",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi5", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi5"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::1/64", "dev", "azumi5"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private5.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi5 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi5 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi5\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::1/64 dev azumi5\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"
        with open("/etc/private5.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private5.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron5_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran5_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v65.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v65.sh", 0o755)
    ping_v65_service()
    gretap6_iranz5sec()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz5():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 6
def run_pingz6():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b581::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel6(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre66.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig66 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:851a::1/64 dev azumig66\n")
        f.write("ip link set azumig66 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig66\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:85{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig66\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:851a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz6():
    remote_ip = "fd1d:fc98:b73e:b581::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b581::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel6(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:851a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping6_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre66_service()

    gre66_cronjob()


def kharej_gretap6_menu6():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b581::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b581::1/64 dev azumi6\n")
        f.write("ip -6 route add fd1d::/16 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz6()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b581::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz6()
    sleep(1)


def gretap6_iranz6():
    remote_ip = "fd1d:fc98:b73e:b581::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b581::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz6(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:851a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping6_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre66_service()

    gre66_cronjob()


def gretap6_iran_tunnelz6(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre66.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig66 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:851a::2/64 dev azumig66\n")
        f.write("ip link set azumig66 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig66\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:85{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig66\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:851a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran6_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b581::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu6():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private6.sh"):
        os.remove("/etc/private6.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi6",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi6", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b581::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi6"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private6.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi6 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi6 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b581::2/64 dev azumi6\n")
        f.write("ip -6 route add fd1d::/16 dev azumi6\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"
        with open("/etc/private6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private6.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron6_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran6_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b581::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v66.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v66.sh", 0o755)
    ping_v66_service()
    gretap6_iranz6()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz6():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 6\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[6]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu6()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 7
def run_pingz7():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b681::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel7(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre67.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig67 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:861a::1/64 dev azumig67\n")
        f.write("ip link set azumig67 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig67\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:86{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig67\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:861a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz7():
    remote_ip = "fd1d:fc98:b73e:b681::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b681::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel7(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:861a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping7_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre67_service()

    gre67_cronjob()


def kharej_gretap6_menu7():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b681::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b681::1/64 dev azumi7\n")
        f.write("ip -6 route add fd1d::/16 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz7()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b681::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz7()
    sleep(1)


def gretap6_iranz7():
    remote_ip = "fd1d:fc98:b73e:b681::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b681::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz7(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:861a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping7_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre67_service()

    gre67_cronjob()


def gretap6_iran_tunnelz7(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre67.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig67 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:861a::2/64 dev azumig67\n")
        f.write("ip link set azumig67 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig67\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:86{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig67\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:861a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran7_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b681::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu7():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private7.sh"):
        os.remove("/etc/private7.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi7",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi7", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b681::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi7"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private7.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi7 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi7 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b681::2/64 dev azumi7\n")
        f.write("ip -6 route add fd1d::/16 dev azumi7\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"
        with open("/etc/private7.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private7.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron7_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran7_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b681::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v67.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v67.sh", 0o755)
    ping_v67_service()
    gretap6_iranz7()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz7():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 7\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[7]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu7()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 8


def run_pingz8():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b781::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel8(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre68.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig68 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:871a::1/64 dev azumig68\n")
        f.write("ip link set azumig68 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig68\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:87{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig68\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:871a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz8():
    remote_ip = "fd1d:fc98:b73e:b781::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b781::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel8(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:871a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping8_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre68_service()

    gre68_cronjob()


def kharej_gretap6_menu8():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b781::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b781::1/64 dev azumi8\n")
        f.write("ip -6 route add fd1d::/16 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz8()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b781::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz8()
    sleep(1)


def gretap6_iranz8():
    remote_ip = "fd1d:fc98:b73e:b781::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b781::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz8(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:871a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping8_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre68_service()

    gre68_cronjob()


def gretap6_iran_tunnelz8(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre68.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig68 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:871a::2/64 dev azumig68\n")
        f.write("ip link set azumig68 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig68\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:87{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig68\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:871a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran8_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b781::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu8():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private8.sh"):
        os.remove("/etc/private8.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi8",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi8", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b781::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi8"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private8.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi8 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi8 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b781::2/64 dev azumi8\n")
        f.write("ip -6 route add fd1d::/16 dev azumi8\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"
        with open("/etc/private8.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private8.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron8_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran8_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b781::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v68.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v68.sh", 0o755)
    ping_v68_service()
    gretap6_iranz8()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz8():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 8\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[8]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu8()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 9
def run_pingz9():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b881::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel9(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre69.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig69 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:881a::1/64 dev azumig69\n")
        f.write("ip link set azumig69 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig69\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:88{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig69\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:881a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz9():
    remote_ip = "fd1d:fc98:b73e:b881::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b881::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel9(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:881a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping9_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre69_service()

    gre69_cronjob()


def kharej_gretap6_menu9():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b881::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b881::1/64 dev azumi9\n")
        f.write("ip -6 route add fd1d::/16 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz9()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b881::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz9()
    sleep(1)


def gretap6_iranz9():
    remote_ip = "fd1d:fc98:b73e:b881::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b881::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz9(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:881a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping9_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre69_service()

    gre69_cronjob()


def gretap6_iran_tunnelz9(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre69.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig69 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:881a::2/64 dev azumig69\n")
        f.write("ip link set azumig69 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig69\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:88{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig69\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:881a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran9_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b881::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu9():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private9.sh"):
        os.remove("/etc/private9.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi9",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi9", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b881::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi9"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private9.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi9 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi9 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b881::2/64 dev azumi9\n")
        f.write("ip -6 route add fd1d::/16 dev azumi9\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"
        with open("/etc/private9.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private9.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron9_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran9_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b881::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v69.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v69.sh", 0o755)
    ping_v69_service()
    gretap6_iranz9()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz9():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 9\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[9]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu9()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 10


def run_pingz10():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b981::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gre6tap_tunnel10(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre610.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig610 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:891a::1/64 dev azumig610\n")
        f.write("ip link set azumig610 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig610\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:89{i}a::1"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig610\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:891a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6tap_kharejz10():
    remote_ip = "fd1d:fc98:b73e:b891::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b891::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gre6tap_tunnel10(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:891a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping10_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre610_service()

    gre610_cronjob()


def kharej_gretap6_menu10():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b891::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b981::1/64 dev azumi10\n")
        f.write("ip -6 route add fd1d::/16 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_pingz10()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b981::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")
    gre6tap_kharejz10()
    sleep(1)


def gretap6_iranz10():
    remote_ip = "fd1d:fc98:b73e:b891::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b891::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6tap\033[97m tunnel: "
        )
    )
    gretap6_iran_tunnelz10(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:891a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping10_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre610_service()

    gre610_cronjob()


def gretap6_iran_tunnelz10(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre610.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe ip6_gre\n")
        f.write(
            f"ip link add name azumig610 type ip6gretap local {local_ip} remote {remote_ip}\n"
        )
        f.write("ip -6 addr add 2002:891a::2/64 dev azumig610\n")
        f.write("ip link set azumig610 up\n")
        f.write("ip -6 route add 2002::/16 dev azumig610\n")

        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:89{i}a::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumig610\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(["bash", file_path], check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6tap]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"
        with open(file_path, "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:891a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran10_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b891::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def iran_gretap6_menu10():
    os.system("clear")
    global local_ip, remote_ip
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring GRE6tap \033[92mIran\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private10.sh"):
        os.remove("/etc/private10.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi10",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi10", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b891::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi10"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private10.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi10 mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi10 up\n")
        f.write("ip addr add fd1d:fc98:b73e:b891::2/64 dev azumi10\n")
        f.write("ip -6 route add fd1d::/16 dev azumi10\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"
        with open("/etc/private10.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private10.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron10_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran10_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b891::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v610.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v610.sh", 0o755)
    ping_v610_service()
    gretap6_iranz10()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    display_checkmark("\033[92mGRE6tap Configuration Completed!\033[0m")


def gre6tap6_kharejz10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10 \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz10():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 10\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[10]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu10()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    display_checkmark("\033[92mConfiguration is done!\033[0m")


## native ipsec
def config_ipsecn1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap1
  left=%defaultroute
  leftsubnet=2002:801a::1/64
  leftid=2002:801a::1
  right=2002:801a::2
  rightsubnet=2002:801a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:801a::2 2002:801a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn12(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap2
  left=%defaultroute
  leftsubnet=2002:811a::1/64
  leftid=2002:811a::1
  right=2002:811a::2
  rightsubnet=2002:811a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:811a::2 2002:811a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn13(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap3
  left=%defaultroute
  leftsubnet=2002:821a::1/64
  leftid=2002:821a::1
  right=2002:821a::2
  rightsubnet=2002:821a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:821a::2 2002:821a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn14(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
  
conn gretap4
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn15(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap5
  left=%defaultroute
  leftsubnet=2002:841a::1/64
  leftid=2002:841a::1
  right=2002:841a::2
  rightsubnet=2002:841a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:841a::2 2002:841a::1 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec1.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap1
  left=%defaultroute
  leftsubnet=2002:801a::2/64
  leftid=2002:801a::2
  right=2002:801a::1
  rightsubnet=2002:801a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:801a::1 2002:801a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn22(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec2.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec2.conf", "a") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap2
  left=%defaultroute
  leftsubnet=2002:811a::2/64
  leftid=2002:811a::2
  right=2002:811a::1
  rightsubnet=2002:811a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "a") as f:
        f.write(f'2002:811a::1 2002:811a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec2.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn23(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec3.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec3.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap3
  left=%defaultroute
  leftsubnet=2002:821a::2/64
  leftid=2002:821a::2
  right=2002:821a::1
  rightsubnet=2002:821a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:821a::1 2002:821a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec3.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn24(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec4.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec4.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap4
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec4.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn25(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec5.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    with open("/etc/ipsec5.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyourarea
  
conn gretap5
  left=%defaultroute
  leftsubnet=2002:841a::2/64
  leftid=2002:841a::2
  right=2002:841a::1
  rightsubnet=2002:841a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no\n"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:841a::1 2002:841a::2 : PSK "{psk}"\n')

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec5.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissions1()
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


# start


def gretapnm1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative + IPsec \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN\033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tapmu_k1()
            break
        elif server_type == "2":
            gre6tapmu_i1()
            break
        elif server_type == "3":
            clear()
            gre6tapmulti_mnu
            break
        else:
            print("Invalid choice.")


def gre6tapmu_k1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative +IPsec \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[96mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k11()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k21()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k31()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k41()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k51()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            enable_reset_ipsec()
            irangretap_q1()
            break
        elif server_type == "0":
            clear()
            gretapnm1()
            break
        else:
            print("Invalid choice.")


def config_ipsecn1k(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn GRE6{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:8{i+0}1a::1/64\n")
            f.write(f"  leftid=2002:8{i+0}1a::1\n")
            f.write(f"  right=2002:8{i+0}1a::2\n")
            f.write(f"  rightsubnet=2002:8{i+0}1a::2/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2002:8{i+0}1a::2 2002:8{i+0}1a::1 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_ipsecn1i(psk, num_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")

    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "disable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "stop", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open(f"/etc/ipsec1.conf", "w") as f:
        f.write("config setup\n")
        f.write('  charondebug="all"\n')
        f.write("  uniqueids=no\n")
        f.write("##azumiisinyourarea\n")

        for i in range(num_servers):
            f.write(f"\nconn GRE6{i+1}\n")
            f.write("  left=%defaultroute\n")
            f.write(f"  leftsubnet=2002:8{i+0}1a::2/64\n")
            f.write(f"  leftid=2002:8{i+0}1a::2\n")
            f.write(f"  right=2002:8{i+0}1a::1\n")
            f.write(f"  rightsubnet=2002:8{i+0}1a::1/64\n")
            f.write("  ike=aes256gcm16-sha512-ecp384!\n")
            f.write("  esp=aes256gcm16-sha512-ecp384!\n")
            f.write("  keyexchange=ikev2\n")
            f.write("  auto=start\n")
            f.write("  authby=secret\n")
            f.write("  keyingtries=%forever\n")
            f.write("  dpdaction=restart\n")
            f.write("  dpddelay=30s\n")
            f.write("  dpdtimeout=120s\n")
            f.write("  rekeymargin=3m\n")
            f.write("  rekeyfuzz=100%\n")
            f.write("  reauth=no\n")

    subprocess.run(
        ["sudo", "chmod", "+x", f"/etc/ipsec1.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.secrets", "w") as f:
        for i in range(num_servers):
            f.write(f'2002:8{i+0}1a::1 2002:8{i+0}1a::2 : PSK "{psk}"\n')

    subprocess.run(
        ["sudo", "chmod", "+x", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(
            """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork"""
        )

        for i in range(num_servers):
            f.write(f" --conf /etc/ipsec1.conf")

        f.write(
            """
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target\n"""
        )

    permissionz(num_servers)
    subprocess.run(
        ["sudo", "systemctl", "daemon-reload"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def irangretap_q1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1i(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "gre6tap2_i{}1".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit
def irangretap_q1edit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1i(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def irangretap_q1edit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mKharej Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipsecn1i(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    restart_forced_strongazumi()


def gre6tapmu_i1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mNative +IPsec \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[96mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i11()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i21()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i31()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i41()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i51()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            enable_reset_ipsec()
            kharejgretap_q1()
            break
        elif server_type == "0":
            clear()
            gretapnm1()
            break
        else:
            print("Invalid choice.")


def kharejgretap_q1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1k(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "gre6tap2_k{}1".format(i)
        globals()[menu_name]()
    restart_forced_strongazumi()


# edit


def kharejgretap_q1edit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1k(psk, num_servers)
    restart_forced_strongazumi()


# edit2


def kharejgretap_q1edit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1k(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    restart_forced_strongazumi()


def gre6tap_k11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1(psk)
    ip_address = "2002:801a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:801a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tap_i11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn2(psk)
    ip_address = "2002:801a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[1]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel1()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:801a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 2native


def gre6tap_k21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn12(psk)
    ip_address = "2002:811a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:811a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tap_i21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn22(psk)
    ip_address = "2002:811a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[2]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel2()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:811a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 3native


def gre6tap_k31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn13(psk)
    ip_address = "2002:821a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:821a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tap_i31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn23(psk)
    ip_address = "2002:821a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[3]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel3()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:821a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end

# 4native


def gre6tap_k41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn14(psk)
    ip_address = "2002:831a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:831a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tap_i41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn24(psk)
    ip_address = "2002:831a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[4]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel4()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:831a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end
# 5native


def gre6tap_k51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    kharej_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn15(psk)
    ip_address = "2002:841a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_k51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    kharej_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:841a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# iran  native


def gre6tap_i51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV6 address: \033[0m")
    iran_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn25(psk)
    ip_address = "2002:841a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap2_i51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV6 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[5]\033[93m IPV6 address: \033[0m"
    )
    iran_gre6tap_tunnel5()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    ip_address = "2002:841a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


##end


##IPsec IPv4
# ip4 start
def gretap4m1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mGre6tap + IPsec V4 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN\033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap4mu_k1()
            break
        elif server_type == "2":
            gre6tap4mu_i1()
            break
        elif server_type == "3":
            clear()
            gre6tapmulti_mnu()
            break
        else:
            print("Invalid choice.")


def gre6tap4mu_k1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mIPV4 + IPsec \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[96mIRAN\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz11()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz21()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz31()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz41()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz51()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            enable_reset_ipsec()
            irangretap4_q1()
            break
        elif server_type == "0":
            clear()
            gretap4m1()
            break
        else:
            print("Invalid choice.")


def irangretap4_q1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1i(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "gre6tap62_iranz{}1".format(i)
        if menu_name in globals():
            globals()[menu_name]()
        else:
            print("Function {} does not exist.".format(menu_name))
    restart_forced_strongazumi()


# edit
def irangretap4_q1edit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1i(psk, num_servers)
    restart_forced_strongazumi()


# edit2
def irangretap4_q1edit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time!\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mKharej Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m?: \033[0m")
    config_ipsecn1i(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    restart_forced_strongazumi()


def gre6tap4mu_i1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mIPV4 \033[93m+\033[92m Gretap6 \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[96mKharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz51()
            break
        elif server_type == "6":
            enable_reset_ipsec()
            kharejgretap4_q1()
            break
        elif server_type == "0":
            clear()
            gretap4m1()
            break
        else:
            print("Invalid choice.")


def kharejgretap4_q1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1k(psk, num_servers)
    for i in range(1, num_servers + 1):
        menu_name = "gre6tap62_kharejz{}1".format(i)
        globals()[menu_name]()


# edit
def kharejgretap4_q1edit():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset_ipsec()
    remove_config()
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1k(psk, num_servers)


# edit2
def kharejgretap4_q1edit2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset_ipsec()
    remove_config()
    num_servers = int(
        input(
            "\033[93mHow many \033[92mIRAN Servers\033[93m do you have \033[96mright now?\033[0m "
        )
    )
    psk = input("\033[93mWhat was your \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1k(psk, num_servers)
    subprocess.run(
        ["sudo", "systemctl", "restart", "strong-azumi1"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def remove_config():
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def gre6tap6_kharejz11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu1sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn1(psk)
    ip_address = "2002:801a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu1sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:801a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu1sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn2(psk)
    ip_address = "2002:801a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz11():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 1\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[1]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu1sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:801a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 2


def gre6tap6_kharejz21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu2sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn12(psk)
    ip_address = "2002:811a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu2sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:811a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu2sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn22(psk)
    ip_address = "2002:811a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz21():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 2\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[2]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu2sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:811a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 3


def gre6tap6_kharejz31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu3sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn13(psk)
    ip_address = "2002:821a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu3sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:821a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu3sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn23(psk)
    ip_address = "2002:821a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz31():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 3\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[3]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu3sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:821a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 4


def gre6tap6_kharejz41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu4sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn14(psk)
    ip_address = "2002:831a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu4sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:831a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu4sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn24(psk)
    ip_address = "2002:831a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz41():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 4\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[4]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu4sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:831a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# 5


def gre6tap6_kharejz51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mkharej\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu5sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn15(psk)
    ip_address = "2002:841a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_kharejz51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej_gretap6_menu5sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:841a::2"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap6_iranz51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu5sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_ipsecn25(psk)
    ip_address = "2002:841a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


def gre6tap62_iranz51():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[92mSERVER 5\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[96m[5]\033[93m IPV4 address: \033[0m"
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran_gretap6_menu5sec()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ip_address = "2002:841a::1"  # iranip
    print("\033[92m(\033[96mPlease wait,Azumi is pinging again...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    display_checkmark("\033[92mConfiguration is done!\033[0m")


# edit server
def edit_server():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mAdd | Edit | Reconfig Server \033[0m")
    print(
        "2. \033[93mRemove [for reconfiging, first remove the appropriate server] \033[0m"
    )
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editmenu()
            break
        elif server_type == "2":
            removemenu()
            break
        elif server_type == "0":
            clear()
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def editmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6 \033[0m")
    print("2. \033[92mIP6IP6 + IPSec \033[0m")
    print("3. \033[93mGRE6 \033[0m")
    print("4. \033[93mGRE6 + IPSec \033[0m")
    print("5. \033[96m6to4 \033[0m")
    print("6. \033[96m6to4 + IPSec \033[0m")
    print("7. \033[92mGRE6tap \033[0m")
    print("8. \033[92mGRE6tap + IPsec \033[0m")
    print("9. \033[93mGeneve [IPsec included] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            edit_ip6ip6()
            break
        elif server_type == "2":
            edit_ip6ip6_sec()
            break
        elif server_type == "3":
            edit_gre6()
            break
        elif server_type == "4":
            edit_gre6_sec()
            break
        elif server_type == "5":
            edit_6to4()
            break
        elif server_type == "6":
            edit_6to4_sec()
            break
        elif server_type == "7":
            edit_gre6tap()
            break
        elif server_type == "8":
            edit_gre6tapsec()
            break
        elif server_type == "9":
            edit_geneve()
            break
        elif server_type == "0":
            clear()
            edit_server()
            break
        else:
            print("Invalid choice.")


def edit_ip6ip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit IP6IP6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [10] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_ip6ip6()
            break
        elif server_type == "2":
            oneiran_ip6ip6()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_ip6ip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit IP6IP6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("6. \033[93m[6] Kharej \033[0m")
    print("7. \033[93m[7] Kharej \033[0m")
    print("8. \033[93m[8] Kharej \033[0m")
    print("9. \033[92m[9] Kharej \033[0m")
    print("10.\033[93m[10] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_ipip61_menu()
            break
        elif server_type == "2":
            kharej_ipip62_menu()
            break
        elif server_type == "3":
            kharej_ipip63_menu()
            break
        elif server_type == "4":
            kharej_ipip64_menu()
            break
        elif server_type == "5":
            kharej_ipip65_menu()
            break
        elif server_type == "6":
            kharej_ipip66_menu()
            break
        elif server_type == "7":
            kharej_ipip67_menu()
            break
        elif server_type == "8":
            kharej_ipip68_menu()
            break
        elif server_type == "9":
            kharej_ipip69_menu()
            break
        elif server_type == "10":
            kharej_ipip610_menu()
            break
        elif server_type == "11":
            oneiran_one()
            break
        elif server_type == "0":
            clear()
            edit_ip6ip6()
            break
        else:
            print("Invalid choice.")


def oneiran_one():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m IP6IP6 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("6. \033[93mServer [6] \033[0m")
    print("7. \033[93mServer [7] \033[0m")
    print("8. \033[92mServer [8] \033[0m")
    print("9. \033[93mServer [9] \033[0m")
    print("10.\033[93mServer [10] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran_ipip61_menu()
            break
        elif server_type == "2":
            iran_ipip62_menu()
            break
        elif server_type == "3":
            iran_ipip63_menu()
            break
        elif server_type == "4":
            iran_ipip64_menu()
            break
        elif server_type == "5":
            iran_ipip65_menu()
            break
        elif server_type == "6":
            iran_ipip66_menu()
            break
        elif server_type == "7":
            iran_ipip67_menu()
            break
        elif server_type == "8":
            iran_ipip68_menu()
            break
        elif server_type == "9":
            iran_ipip69_menu()
            break
        elif server_type == "10":
            iran_ipip610_menu()
            break
        elif server_type == "0":
            clear()
            fivekharej_ip6ip6()
            break
        else:
            print("Invalid choice.")


# ip6ip6 iran side
def oneiran_ip6ip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit IP6IP6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("6. \033[93m[6] IRAN \033[0m")
    print("7. \033[93m[7] IRAN \033[0m")
    print("8. \033[93m[8] IRAN \033[0m")
    print("9. \033[92m[9] IRAN \033[0m")
    print("10.\033[93m[10] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran2_ipip61_menu()
            break
        elif server_type == "2":
            iran2_ipip62_menu()
            break
        elif server_type == "3":
            iran2_ipip63_menu()
            break
        elif server_type == "4":
            iran2_ipip64_menu()
            break
        elif server_type == "5":
            iran2_ipip65_menu()
            break
        elif server_type == "6":
            iran2_ipip66_menu()
            break
        elif server_type == "7":
            iran2_ipip67_menu()
            break
        elif server_type == "8":
            iran2_ipip68_menu()
            break
        elif server_type == "9":
            iran2_ipip69_menu()
            break
        elif server_type == "10":
            iran2_ipip610_menu()
            break
        elif server_type == "11":
            onekharej_one()
            break
        elif server_type == "0":
            clear()
            edit_ip6ip6()
            break
        else:
            print("Invalid choice.")


def onekharej_one():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m IP6IP6 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("6. \033[93mServer [6] \033[0m")
    print("7. \033[93mServer [7] \033[0m")
    print("8. \033[92mServer [8] \033[0m")
    print("9. \033[93mServer [9] \033[0m")
    print("10.\033[93mServer [10] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej2_ipip61_menu()
            break
        elif server_type == "2":
            kharej2_ipip62_menu()
            break
        elif server_type == "3":
            kharej2_ipip63_menu()
            break
        elif server_type == "4":
            kharej2_ipip64_menu()
            break
        elif server_type == "5":
            kharej2_ipip65_menu()
            break
        elif server_type == "6":
            kharej2_ipip66_menu()
            break
        elif server_type == "7":
            kharej2_ipip67_menu()
            break
        elif server_type == "8":
            kharej2_ipip68_menu()
            break
        elif server_type == "9":
            kharej2_ipip69_menu()
            break
        elif server_type == "10":
            kharej2_ipip610_menu()
            break
        elif server_type == "0":
            clear()
            oneiran_ip6ip6()
            break
        else:
            print("Invalid choice.")


# ip6ip6 ipsec


def edit_ip6ip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit IP6IP6 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_ip6ip6_sec()
            break
        elif server_type == "2":
            oneiran_ip6ip6_sec()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side + ipsec
def fivekharej_ip6ip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit IP6IP6 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharej_ipip61sec_menu()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharej_ipip62sec_menu()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharej_ipip63sec_menu()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharej_ipip64sec_menu()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharej_ipip65sec_menu()
            break
        elif server_type == "6":
            oneiran_one_ipipsec()
            break
        elif server_type == "0":
            clear()
            edit_ip6ip6_sec()
            break
        else:
            print("Invalid choice.")


def oneiran_one_ipipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m IP6IP6 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejip_qsecedit()
            iran_ipip61sec_menu()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharejip_qsecedit()
            iran_ipip62sec_menu()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharejip_qsecedit()
            iran_ipip63sec_menu()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharejip_qsecedit()
            iran_ipip64sec_menu()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharejip_qsecedit()
            iran_ipip65sec_menu()
            break
        elif server_type == "0":
            clear()
            fivekharej_ip6ip6_sec()
            break
        else:
            print("Invalid choice.")


# ip6ip6 + IPsec iran side
def oneiran_ip6ip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit IP6IP6 + IPsaec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            iran2_ipip61sec_menu()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iran2_ipip62sec_menu()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            iran2_ipip63sec_menu()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            iran2_ipip64sec_menu()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            iran2_ipip65sec_menu()
            break
        elif server_type == "6":
            onekharej_one_ipipsec()
            break
        elif server_type == "0":
            clear()
            edit_ip6ip6_sec()
            break
        else:
            print("Invalid choice.")


def onekharej_one_ipipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m IP6IP6 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            iranip_qsecedit()
            kharej2_ipip61sec_menu()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iranip_qsecedit()
            kharej2_ipip62sec_menu()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            iranip_qsecedit()
            kharej2_ipip63sec_menu()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            iranip_qsecedit()
            kharej2_ipip64sec_menu()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            iranip_qsecedit()
            kharej2_ipip65sec_menu()
            break
        elif server_type == "0":
            clear()
            oneiran_ip6ip6_sec()
            break
        else:
            print("Invalid choice.")


# GRE6


def edit_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_gre6()
            break
        elif server_type == "2":
            oneiran_gre6()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("6. \033[93m[6] Kharej \033[0m")
    print("7. \033[93m[7] Kharej \033[0m")
    print("8. \033[93m[8] Kharej \033[0m")
    print("9. \033[92m[9] Kharej \033[0m")
    print("10.\033[93m[10] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_gre61_menu()
            break
        elif server_type == "2":
            kharej_gre62_menu()
            break
        elif server_type == "3":
            kharej_gre63_menu()
            break
        elif server_type == "4":
            kharej_gre64_menu()
            break
        elif server_type == "5":
            kharej_gre65_menu()
            break
        elif server_type == "6":
            kharej_gre66_menu()
            break
        elif server_type == "7":
            kharej_gre67_menu()
            break
        elif server_type == "8":
            kharej_gre68_menu()
            break
        elif server_type == "9":
            kharej_gre69_menu()
            break
        elif server_type == "10":
            kharej_gre610_menu()
            break
        elif server_type == "11":
            oneiran_onegre6()
            break
        elif server_type == "0":
            clear()
            edit_gre6()
            break
        else:
            print("Invalid choice.")


def oneiran_onegre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m GRE6 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("6. \033[93mServer [6] \033[0m")
    print("7. \033[93mServer [7] \033[0m")
    print("8. \033[92mServer [8] \033[0m")
    print("9. \033[93mServer [9] \033[0m")
    print("10.\033[93mServer [10] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran_gre61_menu()
            break
        elif server_type == "2":
            iran_gre62_menu()
            break
        elif server_type == "3":
            iran_gre63_menu()
            break
        elif server_type == "4":
            iran_gre64_menu()
            break
        elif server_type == "5":
            iran_gre65_menu()
            break
        elif server_type == "6":
            iran_gre66_menu()
            break
        elif server_type == "7":
            iran_gre67_menu()
            break
        elif server_type == "8":
            iran_gre68_menu()
            break
        elif server_type == "9":
            iran_gre69_menu()
            break
        elif server_type == "10":
            iran_gre610_menu()
            break
        elif server_type == "0":
            clear()
            fivekharej_gre6()
            break
        else:
            print("Invalid choice.")


# GRE6 iran side
def oneiran_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran2_gre61_menu()
            break
        elif server_type == "2":
            iran2_gre62_menu()
            break
        elif server_type == "3":
            iran2_gre63_menu()
            break
        elif server_type == "4":
            iran2_gre64_menu()
            break
        elif server_type == "5":
            iran2_gre65_menu()
            break
        elif server_type == "6":
            onekharej_onegre6()
            break
        elif server_type == "0":
            clear()
            edit_gre6()
            break
        else:
            print("Invalid choice.")


def onekharej_onegre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m GRE6 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej2_gre61_menu()
            break
        elif server_type == "2":
            kharej2_gre62_menu()
            break
        elif server_type == "3":
            kharej2_gre63_menu()
            break
        elif server_type == "4":
            kharej2_gre64_menu()
            break
        elif server_type == "5":
            kharej2_gre65_menu()
            break
        elif server_type == "0":
            clear()
            oneiran_gre6()
            break
        else:
            print("Invalid choice.")


# gre6 + ipsec


def edit_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_gre6_sec()
            break
        elif server_type == "2":
            oneiran_gre6_sec()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharej_gre61_ipsec()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharej_gre62_ipsec()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharej_gre63_ipsec()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharej_gre64_ipsec()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharej_gre65_ipsec()
            break
        elif server_type == "6":
            oneiran_onegre6_sec()
            break
        elif server_type == "0":
            clear()
            edit_gre6_sec()
            break
        else:
            print("Invalid choice.")


def oneiran_onegre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m GRE6 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejgre_qipsec_edit()
            iran_gre61_ipsec()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharejgre_qipsec_edit()
            iran_gre62_ipsec()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharejgre_qipsec_edit()
            iran_gre63_ipsec()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharejgre_qipsec_edit()
            iran_gre64_ipsec()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharejgre_qipsec_edit()
            iran_gre65_ipsec()
            break
        elif server_type == "0":
            clear()
            fivekharej_gre6_sec()
            break
        else:
            print("Invalid choice.")


# GRE6 iran side
def oneiran_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            iran2_gre61_ipsec()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iran2_gre62_ipsec()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            iran2_gre63_ipsec()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            iran2_gre64_ipsec()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            iran2_gre65_ipsec()
            break
        elif server_type == "6":
            onekharej_onegre6_sec()
            break
        elif server_type == "0":
            clear()
            edit_gre6_sec()
            break
        else:
            print("Invalid choice.")


def onekharej_onegre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m GRE6 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            irangre_qipsec_edit()
            kharej2_gre61_ipsec()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            irangre_qipsec_edit()
            kharej2_gre62_ipsec()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            irangre_qipsec_edit()
            kharej2_gre63_ipsec()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            irangre_qipsec_edit()
            kharej2_gre64_ipsec()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            irangre_qipsec_edit()
            kharej2_gre65_ipsec()
            break
        elif server_type == "0":
            clear()
            oneiran_gre6_sec()
            break
        else:
            print("Invalid choice.")


# 6to4


def edit_6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit 6TO4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_6to4()
            break
        elif server_type == "2":
            oneiran_6to4()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit 6TO4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("6. \033[93m[6] Kharej \033[0m")
    print("7. \033[93m[7] Kharej \033[0m")
    print("8. \033[93m[8] Kharej \033[0m")
    print("9. \033[92m[9] Kharej \033[0m")
    print("10.\033[93m[10] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej1_private_menu()
            break
        elif server_type == "2":
            kharej2_private_menu()
            break
        elif server_type == "3":
            kharej3_private_menu()
            break
        elif server_type == "4":
            kharej4_private_menu()
            break
        elif server_type == "5":
            kharej5_private_menu()
            break
        elif server_type == "6":
            kharej6_private_menu()
            break
        elif server_type == "7":
            kharej7_private_menu()
            break
        elif server_type == "8":
            kharej8_private_menu()
            break
        elif server_type == "9":
            kharej9_private_menu()
            break
        elif server_type == "10":
            kharej10_private_menu()
            break
        elif server_type == "11":
            oneiran_one6to4()
            break
        elif server_type == "0":
            clear()
            edit_6to4()
            break
        else:
            print("Invalid choice.")


def oneiran_one6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m 6TO4 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("6. \033[93mServer [6] \033[0m")
    print("7. \033[93mServer [7] \033[0m")
    print("8. \033[92mServer [8] \033[0m")
    print("9. \033[93mServer [9 \033[0m")
    print("10.\033[93mServer [10] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran1_private_menu()
            break
        elif server_type == "2":
            iran2_private_menu()
            break
        elif server_type == "3":
            iran3_private_menu()
            break
        elif server_type == "4":
            iran4_private_menu()
            break
        elif server_type == "5":
            iran5_private_menu()
            break
        elif server_type == "6":
            iran6_private_menu()
            break
        elif server_type == "7":
            iran7_private_menu()
            break
        elif server_type == "8":
            iran8_private_menu()
            break
        elif server_type == "9":
            iran9_private_menu()
            break
        elif server_type == "10":
            iran10_private_menu()
            break
        elif server_type == "0":
            clear()
            fivekharej_6to4()
            break
        else:
            print("Invalid choice.")


# 6TO4 iran side
def oneiran_6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit 6TO4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran1_private2_menu()
            break
        elif server_type == "2":
            iran2_private2_menu()
            break
        elif server_type == "3":
            iran3_private2_menu()
            break
        elif server_type == "4":
            iran4_private2_menu()
            break
        elif server_type == "5":
            iran5_private2_menu()
            break
        elif server_type == "6":
            onekharej_one6to4()
            break
        elif server_type == "0":
            clear()
            edit_6to4()
            break
        else:
            print("Invalid choice.")


def onekharej_one6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m 6TO4 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej1_private2_menu()
            break
        elif server_type == "2":
            kharej2_private2_menu()
            break
        elif server_type == "3":
            kharej3_private2_menu()
            break
        elif server_type == "4":
            kharej4_private2_menu()
            break
        elif server_type == "5":
            kharej5_private2_menu()
            break
        elif server_type == "0":
            clear()
            oneiran_6to4()
            break
        else:
            print("Invalid choice.")


# 6to4 + IPsec


def edit_6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit 6TO4 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_6to4_sec()
            break
        elif server_type == "2":
            oneiran_6to4_sec()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit 6TO4 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharej1_private_ipsec()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharej2_private_ipsec()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharej3_private_ipsec()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharej4_private_ipsec()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharej5_private_ipsec()
            break
        elif server_type == "6":
            oneiran_one6to4_sec()
            break
        elif server_type == "0":
            clear()
            edit_6to4_sec()
            break
        else:
            print("Invalid choice.")


def oneiran_one6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m 6TO4 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharej_qpri_ipsecedit()
            iran1_private_ipsec()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharej_qpri_ipsecedit()
            iran2_private_ipsec()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharej_qpri_ipsecedit()
            iran3_private_ipsec()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharej_qpri_ipsecedit()
            iran4_private_ipsec()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharej_qpri_ipsecedit()
            iran5_private_ipsec()
            break
        elif server_type == "0":
            clear()
            fivekharej_6to4_sec()
            break
        else:
            print("Invalid choice.")


# 6TO4 iran side
def oneiran_6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit 6TO4 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            iran1_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iran2_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            iran3_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            iran4_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            iran5_private2_ipsec()
            restart_forced_strongazumi()
            break
        elif server_type == "6":
            onekharej_one6to4_sec()
            break
        elif server_type == "0":
            clear()
            edit_6to4_sec()
            break
        else:
            print("Invalid choice.")


def onekharej_one6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m 6TO4 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            iran_qpri_ipsecedit()
            kharej1_private2_ipsec()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            iran_qpri_ipsecedit()
            kharej2_private2_ipsec()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            iran_qpri_ipsecedit()
            kharej3_private2_ipsec()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            iran_qpri_ipsecedit()
            kharej4_private2_ipsec()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            iran_qpri_ipsecedit()
            kharej5_private2_ipsec()
            break
        elif server_type == "0":
            clear()
            oneiran_6to4_sec()
            break
        else:
            print("Invalid choice.")


# gre6tap
def edit_gre6tap():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE6tap IPV4 Multi \033[0m")
    print("2. \033[93mGRE6tap Native Multi \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_v4_edit()
            break
        elif server_type == "2":
            gre6tap_v6_edit()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


def gre6tap_v4_edit():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap V4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_gre6tap_v4()
            break
        elif server_type == "2":
            oneiran_gre6tap_v4()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_gre6tap_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap V4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("6. \033[93m[6] Kharej \033[0m")
    print("7. \033[93m[7] Kharej \033[0m")
    print("8. \033[93m[8] Kharej \033[0m")
    print("9. \033[92m[9] Kharej \033[0m")
    print("10.\033[93m[10] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap6_kharejz1()
            break
        elif server_type == "2":
            gre6tap6_kharejz2()
            break
        elif server_type == "3":
            gre6tap6_kharejz3()
            break
        elif server_type == "4":
            gre6tap6_kharejz4()
            break
        elif server_type == "5":
            gre6tap6_kharejz5()
            break
        elif server_type == "6":
            gre6tap6_kharejz6()
            break
        elif server_type == "7":
            gre6tap6_kharejz7()
            break
        elif server_type == "8":
            gre6tap6_kharejz8()
            break
        elif server_type == "9":
            gre6tap6_kharejz9()
            break
        elif server_type == "10":
            gre6tap6_kharejz10()
            break
        elif server_type == "11":
            oneiran_onegre6tap4()
            break
        elif server_type == "0":
            clear()
            edit_gre6tap()
            break
        else:
            print("Invalid choice.")


def oneiran_onegre6tap4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m GRE6tap V4 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("6. \033[93mServer [6] \033[0m")
    print("7. \033[93mServer [7] \033[0m")
    print("8. \033[92mServer [8] \033[0m")
    print("9. \033[93mServer [9] \033[0m")
    print("10.\033[93mServer [10] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap62_iranz1()
            break
        elif server_type == "2":
            gre6tap62_iranz2()
            break
        elif server_type == "3":
            gre6tap62_iranz3()
            break
        elif server_type == "4":
            gre6tap62_iranz4()
            break
        elif server_type == "5":
            gre6tap62_iranz5()
            break
        elif server_type == "6":
            gre6tap62_iranz6()
            break
        elif server_type == "7":
            gre6tap62_iranz7()
            break
        elif server_type == "8":
            gre6tap62_iranz8()
            break
        elif server_type == "9":
            gre6tap62_iranz9()
            break
        elif server_type == "10":
            gre6tap62_iranz10()
            break
        elif server_type == "0":
            clear()
            fivekharej_gre6tap_v4()
            break
        else:
            print("Invalid choice.")


# gre6tap iran side
def oneiran_gre6tap_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap V4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap6_iranz1()
            break
        elif server_type == "2":
            gre6tap6_iranz2()
            break
        elif server_type == "3":
            gre6tap6_iranz3()
            break
        elif server_type == "4":
            gre6tap6_iranz4()
            break
        elif server_type == "5":
            gre6tap6_iranz5()
            break
        elif server_type == "6":
            onekharej_one_gre6tap4()
            break
        elif server_type == "0":
            clear()
            edit_gre6tap()
            break
        else:
            print("Invalid choice.")


def onekharej_one_gre6tap4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m GRE6tap V4 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap62_kharejz1()
            break
        elif server_type == "2":
            gre6tap62_kharejz2()
            break
        elif server_type == "3":
            gre6tap62_kharejz3()
            break
        elif server_type == "4":
            gre6tap62_kharejz4()
            break
        elif server_type == "5":
            gre6tap62_kharejz5()
            break
        elif server_type == "0":
            clear()
            oneiran_gre6tap_v4()
            break
        else:
            print("Invalid choice.")


# native gre6tap
def gre6tap_v6_edit():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap V6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_gre6tap_v6()
            break
        elif server_type == "2":
            oneiran_gre6tap_v6()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_gre6tap_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap V6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("6. \033[93m[6] Kharej \033[0m")
    print("7. \033[93m[7] Kharej \033[0m")
    print("8. \033[93m[8] Kharej \033[0m")
    print("9. \033[92m[9] Kharej \033[0m")
    print("10.\033[93m[10] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_k1()
            break
        elif server_type == "2":
            gre6tap_k2()
            break
        elif server_type == "3":
            gre6tap_k3()
            break
        elif server_type == "4":
            gre6tap_k4()
            break
        elif server_type == "5":
            gre6tap_k5()
            break
        elif server_type == "6":
            gre6tap_k6()
            break
        elif server_type == "7":
            gre6tap_k7()
            break
        elif server_type == "8":
            gre6tap_k8()
            break
        elif server_type == "9":
            gre6tap_k9()
            break
        elif server_type == "10":
            gre6tap_k10()
            break
        elif server_type == "11":
            oneiran_onegre6tap6()
            break
        elif server_type == "0":
            clear()
            edit_gre6tap()
            break
        else:
            print("Invalid choice.")


def oneiran_onegre6tap6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m GRE6tap V6 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("6. \033[93mServer [6] \033[0m")
    print("7. \033[93mServer [7] \033[0m")
    print("8. \033[92mServer [8] \033[0m")
    print("9. \033[93mServer [9] \033[0m")
    print("10.\033[93mServer [10] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap2_i1()
            break
        elif server_type == "2":
            gre6tap2_i2()
            break
        elif server_type == "3":
            gre6tap2_i3()
            break
        elif server_type == "4":
            gre6tap2_i4()
            break
        elif server_type == "5":
            gre6tap2_i5()
            break
        elif server_type == "6":
            gre6tap2_i6()
            break
        elif server_type == "7":
            gre6tap2_i7()
            break
        elif server_type == "8":
            gre6tap2_i8()
            break
        elif server_type == "9":
            gre6tap2_i9()
            break
        elif server_type == "10":
            gre6tap2_i10()
            break
        elif server_type == "0":
            clear()
            fivekharej_gre6tap_v6()
            break
        else:
            print("Invalid choice.")


# gre6tap iran side
def oneiran_gre6tap_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap V6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_i1()
            break
        elif server_type == "2":
            gre6tap_i2()
            break
        elif server_type == "3":
            gre6tap_i3()
            break
        elif server_type == "4":
            gre6tap_i4()
            break
        elif server_type == "5":
            gre6tap_i5()
            break
        elif server_type == "6":
            onekharej_one_gre6tap6()
            break
        elif server_type == "0":
            clear()
            edit_gre6tap()
            break
        else:
            print("Invalid choice.")


def onekharej_one_gre6tap6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m GRE6tap V6 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap2_k1()
            break
        elif server_type == "2":
            gre6tap2_k2()
            break
        elif server_type == "3":
            gre6tap2_k3()
            break
        elif server_type == "4":
            gre6tap2_k4()
            break
        elif server_type == "5":
            gre6tap2_k5()
            break
        elif server_type == "0":
            clear()
            oneiran_gre6tap_v6()
            break
        else:
            print("Invalid choice.")


# gre6tap + IPsec
def edit_gre6tapsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE6tap + IPsec IPV4 Multi \033[0m")
    print("2. \033[93mGRE6tap + IPsec Native Multi \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_v4sec_edit()
            break
        elif server_type == "2":
            gre6tap_v6sec_edit()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# gre6tap + IPsec native


def gre6tap_v6sec_edit():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap + IPsec V6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_gre6tapsec_v6()
            break
        elif server_type == "2":
            oneiran_gre6tapsec_v6()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_gre6tapsec_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Gre6tap V6 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap_k51()
            break
        elif server_type == "6":
            oneiran_onegre6tapn_sec()
            break
        elif server_type == "0":
            clear()
            gre6tap_v6sec_edit()
            break
        else:
            print("Invalid choice.")


def oneiran_onegre6tapn_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Gre6tap V6 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            irangretap_q1edit()
            gre6tap2_i11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            irangretap_q1edit()
            gre6tap2_i21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            irangretap_q1edit()
            gre6tap2_i31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            irangretap_q1edit()
            gre6tap2_i41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            irangretap_q1edit()
            gre6tap2_i51()
            break
        elif server_type == "0":
            clear()
            fivekharej_gre6tapsec_v6()
            break
        else:
            print("Invalid choice.")


# gre6tap iran side
def oneiran_gre6tapsec_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Gre6tap V6 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap_i51()
            break
        elif server_type == "6":
            onekharej_onegre6tapn_sec()
            break
        elif server_type == "0":
            clear()
            gre6tap_v4sec_edit()
            break
        else:
            print("Invalid choice.")


def onekharej_onegre6tapn_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Gre6tap V6 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejgretap_q1edit()
            gre6tap2_k11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharejgretap_q1edit()
            gre6tap2_k21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharejgretap_q1edit()
            gre6tap2_k31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharejgretap_q1edit()
            gre6tap2_k41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharejgretap_q1edit()
            gre6tap2_k51()
            break
        elif server_type == "0":
            clear()
            oneiran_gre6tapsec_v6()
            break
        else:
            print("Invalid choice.")


def gre6tap_v4sec_edit():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit GRE6tap + IPsec V4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_gre6tapsec_v4()
            break
        elif server_type == "2":
            oneiran_gre6tapsec_v4()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_gre6tapsec_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Gre6tap V4 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_kharejz51()
            break
        elif server_type == "6":
            oneiran_onegre6tap_sec()
            break
        elif server_type == "0":
            clear()
            gre6tap_v4sec_edit()
            break
        else:
            print("Invalid choice.")


def oneiran_onegre6tap_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Gre6tap V4 + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            irangretap4_q1edit()
            gre6tap62_iranz11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            irangretap4_q1edit()
            gre6tap62_iranz21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            irangretap4_q1edit()
            gre6tap62_iranz31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            irangretap4_q1edit()
            gre6tap62_iranz41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            irangretap4_q1edit()
            gre6tap62_iranz51()
            break
        elif server_type == "0":
            clear()
            fivekharej_gre6tapsec_v4()
            break
        else:
            print("Invalid choice.")


# gre6tap iran side
def oneiran_gre6tapsec_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Gre6tap V4 + IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            gre6tap6_iranz51()
            break
        elif server_type == "6":
            onekharej_onegre6tap_sec()
            break
        elif server_type == "0":
            clear()
            gre6tap_v4sec_edit()
            break
        else:
            print("Invalid choice.")


def onekharej_onegre6tap_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Gre6tap + IPsec Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            kharejgretap4_q1edit()
            gre6tap62_kharejz11()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            kharejgretap4_q1edit()
            gre6tap62_kharejz21()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            kharejgretap4_q1edit()
            gre6tap62_kharejz31()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            kharejgretap4_q1edit()
            gre6tap62_kharejz41()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            kharejgretap4_q1edit()
            gre6tap62_kharejz51()
            break
        elif server_type == "0":
            clear()
            oneiran_gre6tapsec_v4()
            break
        else:
            print("Invalid choice.")


# geneve
def edit_geneve():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Edit Geneve Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve UDP  \033[0m")
    print("2. \033[93mGeneve + Native\033[0m")
    print("3. \033[96mGeneve + IPv4 + GRE6\033[0m")
    print("4. \033[92mGeneve + Native + GRE6\033[0m")
    print("5. \033[96mGeneve + IPsec\033[0m")
    print("6. \033[93mGeneve + IPsec + GRE6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            edit_geneve_udp()
            break
        elif server_type == "2":
            edit_geneve_native()
            break
        elif server_type == "3":
            edit_geneve_ipv4g6()
            break
        elif server_type == "4":
            edit_geneve_ipv6g6()
            break
        elif server_type == "5":
            edit_geneve_ipsec()
            break
        elif server_type == "6":
            edit_geneve_gre6sec()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


def edit_geneve_udp():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneveudp()
            break
        elif server_type == "2":
            oneiran_geneveudp()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneveudp():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve Kharej Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5_s1()
            break
        elif server_type == "2":
            kharej5_s2()
            break
        elif server_type == "3":
            kharej5_s3()
            break
        elif server_type == "4":
            kharej5_s4()
            break
        elif server_type == "5":
            kharej5_s5()
            break
        elif server_type == "6":
            oneiran_onegenudp()
            break
        elif server_type == "0":
            clear()
            edit_geneve_udp()
            break
        else:
            print("Invalid choice.")


def oneiran_onegenudp():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran52_s1()
            break
        elif server_type == "2":
            iran52_s2()
            break
        elif server_type == "3":
            iran52_s3()
            break
        elif server_type == "4":
            iran52_s4()
            break
        elif server_type == "5":
            iran52_s5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneveudp()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneveudp():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve IRAN Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran5_s1()
            break
        elif server_type == "2":
            iran5_s2()
            break
        elif server_type == "3":
            iran5_s3()
            break
        elif server_type == "4":
            iran5_s4()
            break
        elif server_type == "5":
            iran5_s5()
            break
        elif server_type == "6":
            onekharej_onegeneveudp()
            break
        elif server_type == "0":
            clear()
            edit_geneve_udp()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneveudp():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej52_s1()
            break
        elif server_type == "2":
            kharej52_s2()
            break
        elif server_type == "3":
            kharej52_s3()
            break
        elif server_type == "4":
            kharej52_s4()
            break
        elif server_type == "5":
            kharej52_s5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneveudp()
            break
        else:
            print("Invalid choice.")


# native geneve
def edit_geneve_native():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve Native Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneveudpn()
            break
        elif server_type == "2":
            oneiran_geneveudpn()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneveudpn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Native Geneve Kharej Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej5n_s1()
            break
        elif server_type == "2":
            kharej5n_s2()
            break
        elif server_type == "3":
            kharej5n_s3()
            break
        elif server_type == "4":
            kharej5n_s4()
            break
        elif server_type == "5":
            kharej5n_s5()
            break
        elif server_type == "6":
            oneiran_onegenudpn()
            break
        elif server_type == "0":
            clear()
            edit_geneve_native()
            break
        else:
            print("Invalid choice.")


def oneiran_onegenudpn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran52n_s1()
            break
        elif server_type == "2":
            iran52n_s2()
            break
        elif server_type == "3":
            iran52n_s3()
            break
        elif server_type == "4":
            iran52n_s4()
            break
        elif server_type == "5":
            iran52n_s5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneveudpn()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneveudpn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Native Geneve IRAN Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran5n_s1()
            break
        elif server_type == "2":
            iran5n_s2()
            break
        elif server_type == "3":
            iran5n_s3()
            break
        elif server_type == "4":
            iran5n_s4()
            break
        elif server_type == "5":
            iran5n_s5()
            break
        elif server_type == "6":
            onekharej_onegeneveudpn()
            break
        elif server_type == "0":
            clear()
            edit_geneve_native()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneveudpn():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej52n_s1()
            break
        elif server_type == "2":
            kharej52n_s2()
            break
        elif server_type == "3":
            kharej52n_s3()
            break
        elif server_type == "4":
            kharej52n_s4()
            break
        elif server_type == "5":
            kharej52n_s5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneveudpn()
            break
        else:
            print("Invalid choice.")


# geneve ipv4 gre6
def edit_geneve_ipv4g6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve + GRE6 V4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneve_gre6v4()
            break
        elif server_type == "2":
            oneiran_geneve_gre6v4()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneve_gre6v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + GRE6 V4 Kharej Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genp4_kharej_gre1()
            break
        elif server_type == "2":
            genp4_kharej_gre2()
            break
        elif server_type == "3":
            genp4_kharej_gre3()
            break
        elif server_type == "4":
            genp4_kharej_gre4()
            break
        elif server_type == "5":
            genp4_kharej_gre5()
            break
        elif server_type == "6":
            oneiran_onegen_gre6v4()
            break
        elif server_type == "0":
            clear()
            edit_geneve_ipv4g6()
            break
        else:
            print("Invalid choice.")


def oneiran_onegen_gre6v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genp4_iran2_gre1()
            break
        elif server_type == "2":
            genp4_iran2_gre2()
            break
        elif server_type == "3":
            genp4_iran2_gre3()
            break
        elif server_type == "4":
            genp4_iran2_gre4()
            break
        elif server_type == "5":
            genp4_iran2_gre5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneve_gre6v4()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneve_gre6v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + GRE6 V4 IRAN Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genp4_iran_gre1()
            break
        elif server_type == "2":
            genp4_iran_gre2()
            break
        elif server_type == "3":
            genp4_iran_gre3()
            break
        elif server_type == "4":
            genp4_iran_gre4()
            break
        elif server_type == "5":
            genp4_iran_gre5()
            break
        elif server_type == "6":
            onekharej_onegeneve_gre6v4()
            break
        elif server_type == "0":
            clear()
            edit_geneve_ipv4g6()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneve_gre6v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genp4_kharej2_gre1()
            break
        elif server_type == "2":
            genp4_kharej2_gre2()
            break
        elif server_type == "3":
            genp4_kharej2_gre3()
            break
        elif server_type == "4":
            genp4_kharej2_gre4()
            break
        elif server_type == "5":
            genp4_kharej2_gre5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneve_gre6v4()
            break
        else:
            print("Invalid choice.")


# geneve gre6 v6
def edit_geneve_ipv6g6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve + GRE6 V6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneve_gre6v6()
            break
        elif server_type == "2":
            oneiran_geneve_gre6v6()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneve_gre6v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + GRE6 V6 Kharej Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_kharej_gre1()
            break
        elif server_type == "2":
            gen_kharej_gre2()
            break
        elif server_type == "3":
            gen_kharej_gre3()
            break
        elif server_type == "4":
            gen_kharej_gre4()
            break
        elif server_type == "5":
            gen_kharej_gre5()
            break
        elif server_type == "6":
            oneiran_onegen_gre6v6()
            break
        elif server_type == "0":
            clear()
            edit_geneve_ipv6g6()
            break
        else:
            print("Invalid choice.")


def oneiran_onegen_gre6v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_iran2_gre1()
            break
        elif server_type == "2":
            gen_iran2_gre2()
            break
        elif server_type == "3":
            gen_iran2_gre3()
            break
        elif server_type == "4":
            gen_iran2_gre4()
            break
        elif server_type == "5":
            gen_iran2_gre5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneve_gre6v6()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneve_gre6v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + GRE6 V6 IRAN Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_iran_gre1()
            break
        elif server_type == "2":
            gen_iran_gre2()
            break
        elif server_type == "3":
            gen_iran_gre3()
            break
        elif server_type == "4":
            gen_iran_gre4()
            break
        elif server_type == "5":
            gen_iran_gre5()
            break
        elif server_type == "6":
            onekharej_onegeneve_gre6v6()
            break
        elif server_type == "0":
            clear()
            edit_geneve_ipv6g6()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneve_gre6v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_kharej2_gre1()
            break
        elif server_type == "2":
            gen_kharej2_gre2()
            break
        elif server_type == "3":
            gen_kharej2_gre3()
            break
        elif server_type == "4":
            gen_kharej2_gre4()
            break
        elif server_type == "5":
            gen_kharej2_gre5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneve_gre6v6()
            break
        else:
            print("Invalid choice.")


# geneve ipsec
def edit_geneve_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mGeneve + IPsec \033[93mMulti Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGen IPsec IPV4  \033[0m")
    print("2. \033[93mGen IPsec Native\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            edit_gensec_ipv4()
            break
        elif server_type == "2":
            edit_gensec_ipv6()
            break
        elif server_type == "0":
            clear()
            edit_geneve()
            break
        else:
            print("Invalid choice.")


def edit_gensec_ipv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve + IPsec V4 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneve_secv4()
            break
        elif server_type == "2":
            oneiran_geneve_secv4()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneve_secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + IPsec V4 Kharej Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            kharej5_s1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            kharej5_s2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            kharej5_s3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            kharej5_s4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            kharej5_s5()
            break
        elif server_type == "6":
            oneiran_onegen_secv4()
            break
        elif server_type == "0":
            clear()
            edit_gensec_ipv4()
            break
        else:
            print("Invalid choice.")


def oneiran_onegen_secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran11_ipsec_genedit()
            iran52_s1()
            break
        elif server_type == "2":
            iran11_ipsec_genedit()
            iran52_s2()
            break
        elif server_type == "3":
            iran11_ipsec_genedit()
            iran52_s3()
            break
        elif server_type == "4":
            iran11_ipsec_genedit()
            iran52_s4()
            break
        elif server_type == "5":
            iran11_ipsec_genedit()
            iran52_s5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneve_secv4()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneve_secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + IPsec V4 IRAN Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            iran5_s1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            iran5_s2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            iran5_s3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            iran5_s4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            iran5_s5()
            break
        elif server_type == "6":
            onekharej_onegeneve_secv4()
            break
        elif server_type == "0":
            clear()
            edit_gensec_ipv4()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneve_secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej11_ipsec_genedit()
            kharej52_s1()
            break
        elif server_type == "2":
            kharej11_ipsec_genedit()
            kharej52_s2()
            break
        elif server_type == "3":
            kharej11_ipsec_genedit()
            kharej52_s3()
            break
        elif server_type == "4":
            kharej11_ipsec_genedit()
            kharej52_s4()
            break
        elif server_type == "5":
            kharej11_ipsec_genedit()
            kharej52_s5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneve_secv4()
            break
        else:
            print("Invalid choice.")


# geneve native ipsec
def edit_gensec_ipv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mEdit Geneve + IPsec V6 Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneve_secv6()
            break
        elif server_type == "2":
            oneiran_geneve_secv6()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneve_secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + IPsec V6 Kharej Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            kharej5n_s1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            kharej5n_s2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            kharej5n_s3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            kharej5n_s4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            kharej5n_s5()
            break
        elif server_type == "6":
            oneiran_onegen_secv6()
            break
        elif server_type == "0":
            clear()
            edit_gensec_ipv6()
            break
        else:
            print("Invalid choice.")


def oneiran_onegen_secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran1_ipsecn_genedit()
            iran52n_s1()
            break
        elif server_type == "2":
            iran1_ipsecn_genedit()
            iran52n_s2()
            break
        elif server_type == "3":
            iran1_ipsecn_genedit()
            iran52n_s3()
            break
        elif server_type == "4":
            iran1_ipsecn_genedit()
            iran52n_s4()
            break
        elif server_type == "5":
            iran1_ipsecn_genedit()
            iran52n_s5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneve_secv6()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneve_secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + IPsec V6 IRAN Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            iran5n_s1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            iran5n_s2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            iran5n_s3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            iran5n_s4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            iran5n_s5()
            break
        elif server_type == "6":
            onekharej_onegeneve_secv6()
            break
        elif server_type == "0":
            clear()
            edit_gensec_ipv6()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneve_secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej1_ipsecn_genedit()
            kharej52n_s1()
            break
        elif server_type == "2":
            kharej1_ipsecn_genedit()
            kharej52n_s2()
            break
        elif server_type == "3":
            kharej1_ipsecn_genedit()
            kharej52n_s3()
            break
        elif server_type == "4":
            kharej1_ipsecn_genedit()
            kharej52n_s4()
            break
        elif server_type == "5":
            kharej1_ipsecn_genedit()
            kharej52n_s5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneve_secv6()
            break
        else:
            print("Invalid choice.")


# geneve + gre6 + ipsec


def edit_geneve_gre6sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[96mGeneve GRE6 + IPsec \033[93mMulti Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGen IPsec GRE6 IPV4  \033[0m")
    print("2. \033[93mGen IPsec GRE6 Native\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            edit_gensec_gre6ipv4()
            break
        elif server_type == "2":
            edit_gensec_gre6ipv6()
            break
        elif server_type == "0":
            clear()
            edit_geneve()
            break
        else:
            print("Invalid choice.")


def edit_gensec_gre6ipv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve Gre6 + IPsec V4 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneve_gre6secv4()
            break
        elif server_type == "2":
            oneiran_geneve_gre6secv4()
            break
        elif server_type == "0":
            clear()
            edit_geneve_gre6sec()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneve_gre6secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve GRE6 + IPsec V4 Kharej Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            genp4_kharej_gre1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            genp4_kharej_gre2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            genp4_kharej_gre3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            genp4_kharej_gre4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            genp4_kharej_gre5()
            break
        elif server_type == "6":
            oneiran_onegen_gre6secv4()
            break
        elif server_type == "0":
            clear()
            edit_gensec_gre6ipv4()
            break
        else:
            print("Invalid choice.")


def oneiran_onegen_gre6secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Gre6 Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iranp4_ipsec_questione()
            genp4_iran2_gre1()
            break
        elif server_type == "2":
            iranp4_ipsec_questione()
            genp4_iran2_gre2()
            break
        elif server_type == "3":
            iranp4_ipsec_questione()
            genp4_iran2_gre3()
            break
        elif server_type == "4":
            iranp4_ipsec_questione()
            genp4_iran2_gre4()
            break
        elif server_type == "5":
            iranp4_ipsec_questione()
            genp4_iran2_gre5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneve_gre6secv4()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneve_gre6secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + GRE6 IPsec V4 IRAN Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            genp4_iran_gre1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            genp4_iran_gre2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            genp4_iran_gre3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            genp4_iran_gre4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            genp4_iran_gre5()
            break
        elif server_type == "6":
            onekharej_onegeneve_gre6secv4()
            break
        elif server_type == "0":
            clear()
            edit_gensec_gre6ipv4()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneve_gre6secv4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejp4_ipsec_questione()
            genp4_kharej2_gre1()
            break
        elif server_type == "2":
            kharejp4_ipsec_questione()
            genp4_kharej2_gre2()
            break
        elif server_type == "3":
            kharejp4_ipsec_questione()
            genp4_kharej2_gre3()
            break
        elif server_type == "4":
            kharejp4_ipsec_questione()
            genp4_kharej2_gre4()
            break
        elif server_type == "5":
            kharejp4_ipsec_questione()
            genp4_kharej2_gre5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneve_gre6secv4()
            break
        else:
            print("Invalid choice.")


# native gre6 ipsec
def edit_gensec_gre6ipv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve Gre6 + IPsec V6 Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5] Kharej [1] IRAN \033[0m")
    print("2. \033[93m[1] Kharej [5] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            fivekharej_geneve_gre6secv6()
            break
        elif server_type == "2":
            oneiran_geneve_gre6secv6()
            break
        elif server_type == "0":
            clear()
            edit_geneve_gre6sec()
            break
        else:
            print("Invalid choice.")


# kharej side
def fivekharej_geneve_gre6secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve GRE6 + IPsec V6 Kharej Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] Kharej \033[0m")
    print("2. \033[93m[2] Kharej \033[0m")
    print("3. \033[93m[3] Kharej \033[0m")
    print("4. \033[92m[4] Kharej \033[0m")
    print("5. \033[93m[5] Kharej \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] IRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            new1()
            gen_kharej_gre1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            new2()
            gen_kharej_gre2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            new3()
            gen_kharej_gre3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            new4()
            gen_kharej_gre4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            new5()
            gen_kharej_gre5()
            break
        elif server_type == "6":
            oneiran_onegen_gre6secv6()
            break
        elif server_type == "0":
            clear()
            edit_gensec_gre6ipv6()
            break
        else:
            print("Invalid choice.")


def oneiran_onegen_gre6secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mIRAN\033[92m Gre6 Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran_ipsecz_questione()
            gen_iran2_gre1()
            break
        elif server_type == "2":
            iran_ipsecz_questione()
            gen_iran2_gre2()
            break
        elif server_type == "3":
            iran_ipsecz_questione()
            gen_iran2_gre3()
            break
        elif server_type == "4":
            iran_ipsecz_questione()
            gen_iran2_gre4()
            break
        elif server_type == "5":
            iran_ipsecz_questione()
            gen_iran2_gre5()
            break
        elif server_type == "0":
            clear()
            fivekharej_geneve_gre6secv6()
            break
        else:
            print("Invalid choice.")


# geneve iran side
def oneiran_geneve_gre6secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit Geneve + GRE6 IPsec V6 IRAN Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93m[1] IRAN \033[0m")
    print("2. \033[93m[2] IRAN \033[0m")
    print("3. \033[93m[3] IRAN \033[0m")
    print("4. \033[92m[4] IRAN \033[0m")
    print("5. \033[93m[5] IRAN \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6. \033[93m[1] Kharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_config()
            enable_reset_ipsec()
            newi1()
            gen_iran_gre1()
            break
        elif server_type == "2":
            remove_config()
            enable_reset_ipsec()
            newi2()
            gen_iran_gre2()
            break
        elif server_type == "3":
            remove_config()
            enable_reset_ipsec()
            newi3()
            gen_iran_gre3()
            break
        elif server_type == "4":
            remove_config()
            enable_reset_ipsec()
            newi4()
            gen_iran_gre4()
            break
        elif server_type == "5":
            remove_config()
            enable_reset_ipsec()
            newi5()
            gen_iran_gre5()
            break
        elif server_type == "6":
            onekharej_onegeneve_gre6secv6()
            break
        elif server_type == "0":
            clear()
            edit_gensec_gre6ipv6()
            break
        else:
            print("Invalid choice.")


def onekharej_onegeneve_gre6secv6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mEdit \033[96mKharej\033[92m Geneve[IPsec] Servers\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[93mServer [1] \033[0m")
    print("2. \033[93mServer [2] \033[0m")
    print("3. \033[92mServer [3] \033[0m")
    print("4. \033[93mServer [4] \033[0m")
    print("5. \033[93mServer [5] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_ipsecz_questione()
            gen_kharej2_gre1()
            break
        elif server_type == "2":
            kharej_ipsecz_questione()
            gen_kharej2_gre2()
            break
        elif server_type == "3":
            kharej_ipsecz_questione()
            gen_kharej2_gre3()
            break
        elif server_type == "4":
            kharej_ipsecz_questione()
            gen_kharej2_gre4()
            break
        elif server_type == "5":
            kharej_ipsecz_questione()
            gen_kharej2_gre5()
            break
        elif server_type == "0":
            clear()
            oneiran_geneve_gre6secv6()
            break
        else:
            print("Invalid choice.")


# remove
def removemenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mRemove Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIP6IP6 \033[0m")
    print("2. \033[92mIP6IP6 + IPSec \033[0m")
    print("3. \033[93mGRE6 \033[0m")
    print("4. \033[93mGRE6 + IPSec \033[0m")
    print("5. \033[96m6to4 \033[0m")
    print("6. \033[96m6to4 + IPSec \033[0m")
    print("7. \033[92mGRE6tap \033[0m")
    print("8. \033[92mGRE6tap + IPsec \033[0m")
    print("9. \033[93mGeneve [IPsec included] \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editremove_ip6ip6()
            break
        elif server_type == "2":
            editremove_ip6ip6_sec()
            break
        elif server_type == "3":
            editremove_gre6()
            break
        elif server_type == "4":
            editremove_gre6_sec()
            break
        elif server_type == "5":
            editremove_6to4()
            break
        elif server_type == "6":
            editremove_6to4_sec()
            break
        elif server_type == "7":
            editremove_gre6tap()
            break
        elif server_type == "8":
            editremove_gre6tapsec()
            break
        elif server_type == "9":
            editremove_geneve()
            break
        elif server_type == "0":
            clear()
            edit_server()
            break
        else:
            print("Invalid choice.")


# remove ip6ip6
def editremove_ip6ip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [10]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_ipip6()
            break
        elif server_type == "2":
            editir_ipip6()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def editkh_ipip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            break
        elif server_type == "2":
            remove_ipip62()
            break
        elif server_type == "3":
            remove_ipip63()
            break
        elif server_type == "4":
            remove_ipip64()
            break
        elif server_type == "5":
            remove_ipip65()
            break
        elif server_type == "6":
            remove_ipip66()
            break
        elif server_type == "7":
            remove_ipip67()
            break
        elif server_type == "8":
            remove_ipip68()
            break
        elif server_type == "9":
            remove_ipip69()
            break
        elif server_type == "10":
            remove_ipip610()
            break
        elif server_type == "11":
            edit_iranip6ip6()
            break
        elif server_type == "0":
            clear()
            editremove_ip6ip6()
            break
        else:
            print("Invalid choice.")


def edit_iranip6ip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("6. \033[92mIRAN-Tunnel[6]\033[0m")
    print("7. \033[92mIRAN-Tunnel[7]\033[0m")
    print("8. \033[93mIRAN-Tunnel[8]\033[0m")
    print("9. \033[92mIRAN-Tunnel[9]\033[0m")
    print("10.\033[92mIRAN-Tunnel[10]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            break
        elif server_type == "2":
            remove_ipip62()
            break
        elif server_type == "3":
            remove_ipip63()
            break
        elif server_type == "4":
            remove_ipip64()
            break
        elif server_type == "5":
            remove_ipip65()
            break
        elif server_type == "6":
            remove_ipip66()
            break
        elif server_type == "7":
            remove_ipip67()
            break
        elif server_type == "8":
            remove_ipip68()
            break
        elif server_type == "9":
            remove_ipip69()
            break
        elif server_type == "10":
            remove_ipip610()
            break
        elif server_type == "0":
            clear()
            editkh_ipip6()
            break
        else:
            print("Invalid choice.")


def editir_ipip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 [10]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("6. \033[92mIRAN[6]\033[0m")
    print("7. \033[92mIRAN[7]\033[0m")
    print("8. \033[93mIRAN[8]\033[0m")
    print("9. \033[92mIRAN[9]\033[0m")
    print("10.\033[92mIRAN[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            break
        elif server_type == "2":
            remove_ipip62()
            break
        elif server_type == "3":
            remove_ipip63()
            break
        elif server_type == "4":
            remove_ipip64()
            break
        elif server_type == "5":
            remove_ipip65()
            break
        elif server_type == "6":
            remove_ipip66()
            break
        elif server_type == "7":
            remove_ipip67()
            break
        elif server_type == "8":
            remove_ipip68()
            break
        elif server_type == "9":
            remove_ipip69()
            break
        elif server_type == "10":
            remove_ipip610()
            break
        elif server_type == "11":
            edit_kharejip6ip6()
            break
        elif server_type == "0":
            clear()
            editremove_ip6ip6()
            break
        else:
            print("Invalid choice.")


def edit_kharejip6ip6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("6. \033[92mKharej-Tunnel[6]\033[0m")
    print("7. \033[92mKharej-Tunnel[7]\033[0m")
    print("8. \033[93mKharej-Tunnel[8]\033[0m")
    print("9. \033[92mKharej-Tunnel[9]\033[0m")
    print("10.\033[92mKharej-Tunnel[10]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            break
        elif server_type == "2":
            remove_ipip62()
            break
        elif server_type == "3":
            remove_ipip63()
            break
        elif server_type == "4":
            remove_ipip64()
            break
        elif server_type == "5":
            remove_ipip65()
            break
        elif server_type == "6":
            remove_ipip66()
            break
        elif server_type == "7":
            remove_ipip67()
            break
        elif server_type == "8":
            remove_ipip68()
            break
        elif server_type == "9":
            remove_ipip69()
            break
        elif server_type == "10":
            remove_ipip610()
            break
        elif server_type == "0":
            clear()
            editir_ipip6()
            break
        else:
            print("Invalid choice.")


# ip6ip6 + sec remove
def editremove_ip6ip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_ipip6_sec()
            break
        elif server_type == "2":
            editir_ipip6_sec()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def editkh_ipip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 + IPsec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61_sec()
            break
        elif server_type == "2":
            remove_ipip62_sec()
            break
        elif server_type == "3":
            remove_ipip63_sec()
            break
        elif server_type == "4":
            remove_ipip64_sec()
            break
        elif server_type == "5":
            remove_ipip65_sec()
            break
        elif server_type == "6":
            edit_iranip6ip6_sec()
            break
        elif server_type == "0":
            clear()
            editremove_ip6ip6_sec()
            break
        else:
            print("Invalid choice.")


def edit_iranip6ip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            kharejip_qsecedit2()
            break
        elif server_type == "2":
            remove_ipip62()
            kharejip_qsecedit2()
            break
        elif server_type == "3":
            remove_ipip63()
            kharejip_qsecedit2()
            break
        elif server_type == "4":
            remove_ipip64()
            kharejip_qsecedit2()
            break
        elif server_type == "5":
            remove_ipip65()
            kharejip_qsecedit2()
            break
        elif server_type == "0":
            clear()
            editkh_ipip6_sec()
            break
        else:
            print("Invalid choice.")


def editir_ipip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 + IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            break
        elif server_type == "2":
            remove_ipip62()
            break
        elif server_type == "3":
            remove_ipip63()
            break
        elif server_type == "4":
            remove_ipip64()
            break
        elif server_type == "5":
            remove_ipip65()
            break
        elif server_type == "6":
            edit_kharejip6ip6_sec()
            break
        elif server_type == "0":
            clear()
            editremove_ip6ip6_sec()
            break
        else:
            print("Invalid choice.")


def edit_kharejip6ip6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m IP6IP6 + IPsec Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip61()
            iranip_qsecedit2()
            break
        elif server_type == "2":
            remove_ipip62()
            iranip_qsecedit2()
            break
        elif server_type == "3":
            remove_ipip63()
            iranip_qsecedit2()
            break
        elif server_type == "4":
            remove_ipip64()
            iranip_qsecedit2()
            break
        elif server_type == "5":
            remove_ipip65()
            iranip_qsecedit2()
            break
        elif server_type == "0":
            clear()
            editir_ipip6_sec()
            break
        else:
            print("Invalid choice.")


# remove gre6
def editremove_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gre6()
            break
        elif server_type == "2":
            editir_gre6()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def editkh_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61()
            break
        elif server_type == "2":
            remove_gre62()
            break
        elif server_type == "3":
            remove_gre63()
            break
        elif server_type == "4":
            remove_gre64()
            break
        elif server_type == "5":
            remove_gre65()
            break
        elif server_type == "6":
            remove_gre66()
            break
        elif server_type == "7":
            remove_gre67()
            break
        elif server_type == "8":
            remove_gre68()
            break
        elif server_type == "9":
            remove_gre69()
            break
        elif server_type == "10":
            remove_gre610()
            break
        elif server_type == "11":
            edit_irangre6()
            break
        elif server_type == "0":
            clear()
            editremove_gre6()
            break
        else:
            print("Invalid choice.")


def edit_irangre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("6. \033[92mIRAN-Tunnel[6]\033[0m")
    print("7. \033[92mIRAN-Tunnel[7]\033[0m")
    print("8. \033[93mIRAN-Tunnel[8]\033[0m")
    print("9. \033[92mIRAN-Tunnel[9]\033[0m")
    print("10.\033[92mIRAN-Tunnel[10]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61()
            break
        elif server_type == "2":
            remove_gre62()
            break
        elif server_type == "3":
            remove_gre63()
            break
        elif server_type == "4":
            remove_gre64()
            break
        elif server_type == "5":
            remove_gre65()
            break
        elif server_type == "6":
            remove_gre66()
            break
        elif server_type == "7":
            remove_gre67()
            break
        elif server_type == "8":
            remove_gre68()
            break
        elif server_type == "9":
            remove_gre69()
            break
        elif server_type == "10":
            remove_gre610()
            break
        elif server_type == "0":
            clear()
            editkh_gre6()
            break
        else:
            print("Invalid choice.")


def editir_gre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61()
            break
        elif server_type == "2":
            remove_gre62()
            break
        elif server_type == "3":
            remove_gre63()
            break
        elif server_type == "4":
            remove_gre64()
            break
        elif server_type == "5":
            remove_gre65()
            break
        elif server_type == "6":
            edit_kharejgre6()
            break
        elif server_type == "0":
            clear()
            editremove_gre6()
            break
        else:
            print("Invalid choice.")


def edit_kharejgre6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61()
            break
        elif server_type == "2":
            remove_gre62()
            break
        elif server_type == "3":
            remove_gre63()
            break
        elif server_type == "4":
            remove_gre64()
            break
        elif server_type == "5":
            remove_gre65()
            break
        elif server_type == "0":
            clear()
            editir_gre6()
            break
        else:
            print("Invalid choice.")


# gre6 ipsec
def editremove_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 + IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gre6_sec()
            break
        elif server_type == "2":
            editir_gre6_sec()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def editkh_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 | IPsec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61_ipsec()
            break
        elif server_type == "2":
            remove_gre62_ipsec()
            break
        elif server_type == "3":
            remove_gre63_ipsec()
            break
        elif server_type == "4":
            remove_gre64_ipsec()
            break
        elif server_type == "5":
            remove_gre65_ipsec()
            break
        elif server_type == "6":
            edit_irangre6_sec()
            break
        elif server_type == "0":
            clear()
            editremove_gre6_sec()
            break
        else:
            print("Invalid choice.")


def edit_irangre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 | IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61_ipsec()
            kharejgre_qipsec_edit2()
            break
        elif server_type == "2":
            remove_gre62_ipsec()
            kharejgre_qipsec_edit2()
            break
        elif server_type == "3":
            remove_gre63_ipsec()
            kharejgre_qipsec_edit2()
            break
        elif server_type == "4":
            remove_gre64_ipsec()
            kharejgre_qipsec_edit2()
            break
        elif server_type == "5":
            remove_gre65_ipsec()
            kharejgre_qipsec_edit2()
            break
        elif server_type == "0":
            clear()
            editkh_gre6_sec()
            break
        else:
            print("Invalid choice.")


def editir_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 | IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61_ipsec()
            break
        elif server_type == "2":
            remove_gre62_ipsec()
            break
        elif server_type == "3":
            remove_gre63_ipsec()
            break
        elif server_type == "4":
            remove_gre64_ipsec()
            break
        elif server_type == "5":
            remove_gre65_ipsec()
            break
        elif server_type == "6":
            edit_kharejgre6_sec()
            break
        elif server_type == "0":
            clear()
            editremove_gre6_sec()
            break
        else:
            print("Invalid choice.")


def edit_kharejgre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m GRE6 | IPsec Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gre61_ipsec()
            irangre_qipsec_edit2()
            break
        elif server_type == "2":
            remove_gre62_ipsec()
            irangre_qipsec_edit2()
            break
        elif server_type == "3":
            remove_gre63_ipsec()
            irangre_qipsec_edit2()
            break
        elif server_type == "4":
            remove_gre64_ipsec()
            irangre_qipsec_edit2()
            break
        elif server_type == "5":
            remove_gre65_ipsec()
            irangre_qipsec_edit2()
            break
        elif server_type == "0":
            clear()
            editir_gre6_sec()
            break
        else:
            print("Invalid choice.")


# 6to4 remove


def editremove_6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_6to4()
            break
        elif server_type == "2":
            editir_6to4()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def editkh_6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1()
            break
        elif server_type == "2":
            remove_private2()
            break
        elif server_type == "3":
            remove_private3()
            break
        elif server_type == "4":
            remove_private4()
            break
        elif server_type == "5":
            remove_private5()
            break
        elif server_type == "6":
            remove_private6()
            break
        elif server_type == "7":
            remove_private7()
            break
        elif server_type == "8":
            remove_private8()
            break
        elif server_type == "9":
            remove_private9()
            break
        elif server_type == "10":
            remove_private10()
            break
        elif server_type == "11":
            edit_iran6to4()
            break
        elif server_type == "0":
            clear()
            editremove_6to4()
            break
        else:
            print("Invalid choice.")


def edit_iran6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("6. \033[92mIRAN-Tunnel[6]\033[0m")
    print("7. \033[92mIRAN-Tunnel[7]\033[0m")
    print("8. \033[93mIRAN-Tunnel[8]\033[0m")
    print("9. \033[92mIRAN-Tunnel[9]\033[0m")
    print("10.\033[92mIRAN-Tunnel[10]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1()
            break
        elif server_type == "2":
            remove_private2()
            break
        elif server_type == "3":
            remove_private3()
            break
        elif server_type == "4":
            remove_private4()
            break
        elif server_type == "5":
            remove_private5()
            break
        elif server_type == "6":
            remove_private6()
            break
        elif server_type == "7":
            remove_private7()
            break
        elif server_type == "8":
            remove_private8()
            break
        elif server_type == "9":
            remove_private9()
            break
        elif server_type == "10":
            remove_private10()
            break
        elif server_type == "0":
            clear()
            editkh_6to4()
            break
        else:
            print("Invalid choice.")


def editir_6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1()
            break
        elif server_type == "2":
            remove_private2()
            break
        elif server_type == "3":
            remove_private3()
            break
        elif server_type == "4":
            remove_private4()
            break
        elif server_type == "5":
            remove_private5()
            break
        elif server_type == "6":
            edit_kharej6to4()
            break
        elif server_type == "0":
            clear()
            editremove_6to4()
            break
        else:
            print("Invalid choice.")


def edit_kharej6to4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1()
            break
        elif server_type == "2":
            remove_private2()
            break
        elif server_type == "3":
            remove_private3()
            break
        elif server_type == "4":
            remove_private4()
            break
        elif server_type == "5":
            remove_private5()
            break
        elif server_type == "0":
            clear()
            editir_6to4()
            break
        else:
            print("Invalid choice.")


# 6to4 ipsec
def editremove_6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 | IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_6to4_sec()
            break
        elif server_type == "2":
            editir_6to4_sec()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def editkh_6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 | IPsec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1_sec()
            break
        elif server_type == "2":
            remove_private2_sec()
            break
        elif server_type == "3":
            remove_private3_sec()
            break
        elif server_type == "4":
            remove_private4_sec()
            break
        elif server_type == "5":
            remove_private5_sec()
            break
        elif server_type == "6":
            edit_iran6to4_sec()
            break
        elif server_type == "0":
            clear()
            editremove_6to4_sec()
            break
        else:
            print("Invalid choice.")


def edit_iran6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1_sec()
            kharej_qpri_ipsecedit2()
            break
        elif server_type == "2":
            remove_private2_sec()
            kharej_qpri_ipsecedit2()
            break
        elif server_type == "3":
            remove_private3_sec()
            kharej_qpri_ipsecedit2()
            break
        elif server_type == "4":
            remove_private4_sec()
            kharej_qpri_ipsecedit2()
            break
        elif server_type == "5":
            remove_private5_sec()
            kharej_qpri_ipsecedit2()
            break
        elif server_type == "0":
            clear()
            editkh_6to4_sec()
            break
        else:
            print("Invalid choice.")


def editir_6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1_sec()
            break
        elif server_type == "2":
            remove_private2_sec()
            break
        elif server_type == "3":
            remove_private3_sec()
            break
        elif server_type == "4":
            remove_private4_sec()
            break
        elif server_type == "5":
            remove_private5_sec()
            break
        elif server_type == "6":
            edit_kharej6to4_sec()
            break
        elif server_type == "0":
            clear()
            editremove_6to4_sec()
            break
        else:
            print("Invalid choice.")


def edit_kharej6to4_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m 6TO4 IPsec Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_private1_sec()
            iran_qpri_ipsecedit2()
            break
        elif server_type == "2":
            remove_private2_sec()
            iran_qpri_ipsecedit2()
            break
        elif server_type == "3":
            remove_private3_sec()
            iran_qpri_ipsecedit2()
            break
        elif server_type == "4":
            remove_private4_sec()
            iran_qpri_ipsecedit2()
            break
        elif server_type == "5":
            remove_private5_sec()
            iran_qpri_ipsecedit2()
            break
        elif server_type == "0":
            clear()
            editir_6to4_sec()
            break
        else:
            print("Invalid choice.")


# gretap ipv4
def editremove_gre6tap():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mRemove GRE6tap Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE6tap IPV4 Multi \033[0m")
    print("2. \033[93mGRE6tap Native Multi \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tap_v4_editrmv()
            break
        elif server_type == "2":
            gre6tap_v6_editrmv()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def gre6tap_v4_editrmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V4\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gre6tap_v4()
            break
        elif server_type == "2":
            editir_gre6tap_v4()
            break
        elif server_type == "0":
            clear()
            editremove_gre6tap()
            break
        else:
            print("Invalid choice.")


def editkh_gre6tap_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V4 [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            remove_gretap66()
            break
        elif server_type == "7":
            remove_gretap67()
            break
        elif server_type == "8":
            remove_gretap68()
            break
        elif server_type == "9":
            remove_gretap69()
            break
        elif server_type == "10":
            remove_gretap610()
            break
        elif server_type == "11":
            edit_irangre6tap_v4()
            break
        elif server_type == "0":
            clear()
            gre6tap_v4_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_irangre6tap_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("6. \033[92mServer[6]\033[0m")
    print("7. \033[92mServer[7]\033[0m")
    print("8. \033[93mServer[8]\033[0m")
    print("9. \033[92mServer[9]\033[0m")
    print("10.\033[92mServer[10]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            remove_gretap66()
            break
        elif server_type == "7":
            remove_gretap67()
            break
        elif server_type == "8":
            remove_gretap68()
            break
        elif server_type == "9":
            remove_gretap69()
            break
        elif server_type == "10":
            remove_gretap610()
            break
        elif server_type == "0":
            clear()
            editkh_gre6tap_v4()
            break
        else:
            print("Invalid choice.")


def editir_gre6tap_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V4 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            edit_kharejgre6tap_v4()
            break
        elif server_type == "0":
            clear()
            gre6tap_v4_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_kharejgre6tap_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V4 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "0":
            clear()
            editir_gre6tap_v4()
            break
        else:
            print("Invalid choice.")


# gre6tap v6
def gre6tap_v6_editrmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V6\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gre6tap_v6()
            break
        elif server_type == "2":
            editir_gre6tap_v6()
            break
        elif server_type == "0":
            clear()
            editremove_gre6tap()
            break
        else:
            print("Invalid choice.")


def editkh_gre6tap_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V6 [10]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("6. \033[92mKharej[6]\033[0m")
    print("7. \033[92mKharej[7]\033[0m")
    print("8. \033[93mKharej[8]\033[0m")
    print("9. \033[92mKharej[9]\033[0m")
    print("10.\033[92mKharej[10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            remove_gretap66()
            break
        elif server_type == "7":
            remove_gretap67()
            break
        elif server_type == "8":
            remove_gretap68()
            break
        elif server_type == "9":
            remove_gretap69()
            break
        elif server_type == "10":
            remove_gretap610()
            break
        elif server_type == "11":
            edit_irangre6tap_v6()
            break
        elif server_type == "0":
            clear()
            gre6tap_v6_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_irangre6tap_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("6. \033[92mServer[6]\033[0m")
    print("7. \033[92mServer[7]\033[0m")
    print("8. \033[93mServer[8]\033[0m")
    print("9. \033[92mServer[9]\033[0m")
    print("10.\033[92mServer[10]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            remove_gretap66()
            break
        elif server_type == "7":
            remove_gretap67()
            break
        elif server_type == "8":
            remove_gretap68()
            break
        elif server_type == "9":
            remove_gretap69()
            break
        elif server_type == "10":
            remove_gretap610()
            break
        elif server_type == "0":
            clear()
            editkh_gre6tap_v6()
            break
        else:
            print("Invalid choice.")


def editir_gre6tap_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V6 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "6":
            edit_kharejgre6tap_v6()
            break
        elif server_type == "0":
            clear()
            gre6tap_v6_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_kharejgre6tap_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V6 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61()
            break
        elif server_type == "2":
            remove_gretap62()
            break
        elif server_type == "3":
            remove_gretap63()
            break
        elif server_type == "4":
            remove_gretap64()
            break
        elif server_type == "5":
            remove_gretap65()
            break
        elif server_type == "0":
            clear()
            editir_gre6tap_v6()
            break
        else:
            print("Invalid choice.")


# gre6tap ipsec v4
def editremove_gre6tapsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mRemove GRE6tap IPsec Servers\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE6tap IPsec IPV4 Multi \033[0m")
    print("2. \033[93mGRE6tap IPsec Native Multi \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6tapsec_v4_editrmv()
            break
        elif server_type == "2":
            gre6tapsec_v6_editrmv()
            break
        elif server_type == "0":
            clear()
            removemenu()
            break
        else:
            print("Invalid choice.")


def gre6tapsec_v4_editrmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec V4\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gre6tapsec_v4()
            break
        elif server_type == "2":
            editir_gre6tapsec_v4()
            break
        elif server_type == "0":
            clear()
            editremove_gre6tapsec()
            break
        else:
            print("Invalid choice.")


def editkh_gre6tapsec_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec V4 [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            break
        elif server_type == "6":
            edit_irangre6tapsec_v4()
            break
        elif server_type == "0":
            clear()
            gre6tapsec_v4_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_irangre6tapsec_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            irangretap4_q1edit2()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            irangretap4_q1edit2()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            irangretap4_q1edit2()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            irangretap4_q1edit2()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            irangretap4_q1edit2()
            break
        elif server_type == "0":
            clear()
            editkh_gre6tapsec_v4()
            break
        else:
            print("Invalid choice.")


def editir_gre6tapsec_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec V4 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            break
        elif server_type == "6":
            edit_kharejgre6tapsec_v4()
            break
        elif server_type == "0":
            clear()
            gre6tapsec_v4_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_kharejgre6tapsec_v4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V4 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            kharejgretap4_q1edit2()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            kharejgretap4_q1edit2()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            kharejgretap4_q1edit2()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            kharejgretap4_q1edit2()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            kharejgretap4_q1edit2()
            break
        elif server_type == "0":
            clear()
            editir_gre6tapsec_v4()
            break
        else:
            print("Invalid choice.")


# gre6tap ipsec v6
def gre6tapsec_v6_editrmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec V6\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gre6tapsec_v6()
            break
        elif server_type == "2":
            editir_gre6tapsec_v6()
            break
        elif server_type == "0":
            clear()
            editremove_gre6tapsec()
            break
        else:
            print("Invalid choice.")


def editkh_gre6tapsec_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec V6 [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            break
        elif server_type == "6":
            edit_irangre6tapsec_v6()
            break
        elif server_type == "0":
            clear()
            gre6tapsec_v6_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_irangre6tapsec_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            irangretap_q1edit2()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            irangretap_q1edit2()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            irangretap_q1edit2()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            irangretap_q1edit2()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            irangretap_q1edit2()
            break
        elif server_type == "0":
            clear()
            editkh_gre6tapsec_v6()
            break
        else:
            print("Invalid choice.")


def editir_gre6tapsec_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap IPsec V6 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            break
        elif server_type == "6":
            edit_kharejgre6tapsec_v6()
            break
        elif server_type == "0":
            clear()
            gre6tapsec_v6_editrmv()
            break
        else:
            print("Invalid choice.")


def edit_kharejgre6tapsec_v6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Gre6tap V6 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mServer[1]\033[0m")
    print("2. \033[92mServer[2]\033[0m")
    print("3. \033[93mServer[3]\033[0m")
    print("4. \033[92mServer[4]\033[0m")
    print("5. \033[92mServer[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_gretap61_sec()
            kharejgretap_q1edit2()
            break
        elif server_type == "2":
            remove_gretap62_sec()
            kharejgretap_q1edit2()
            break
        elif server_type == "3":
            remove_gretap63_sec()
            kharejgretap_q1edit2()
            break
        elif server_type == "4":
            remove_gretap64_sec()
            kharejgretap_q1edit2()
            break
        elif server_type == "5":
            remove_gretap65_sec()
            kharejgretap_q1edit2()
            break
        elif server_type == "0":
            clear()
            editir_gre6tapsec_v6()
            break
        else:
            print("Invalid choice.")


# geneve remove
def editremove_geneve():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m Remove Geneve Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve UDP  \033[0m")
    print("2. \033[93mGeneve + Native\033[0m")
    print("3. \033[96mGeneve + IPv4 + GRE6\033[0m")
    print("4. \033[92mGeneve + Native + GRE6\033[0m")
    print("5. \033[96mGeneve + IPsec\033[0m")
    print("6. \033[93mGeneve + IPsec + GRE6\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editrmv_geneve_udp()
            break
        elif server_type == "2":
            editrmv_geneve_native()
            break
        elif server_type == "3":
            editrmv_geneve_ipv4g6()
            break
        elif server_type == "4":
            editrmv_geneve_ipv6g6()
            break
        elif server_type == "5":
            editrmv_geneve_ipsec()
            break
        elif server_type == "6":
            editrmv_geneve_gre6sec()
            break
        elif server_type == "0":
            clear()
            editmenu()
            break
        else:
            print("Invalid choice.")


# geneve udp remove
def editrmv_geneve_udp():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_genudp_rmv()
            break
        elif server_type == "2":
            editir_genudp_rmv()
            break
        elif server_type == "0":
            clear()
            editremove_geneve()
            break
        else:
            print("Invalid choice.")


def editkh_genudp_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "6":
            edit_irangenudp_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_udp()
            break
        else:
            print("Invalid choice.")


def edit_irangenudp_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "0":
            clear()
            editkh_genudp_rmv()
            break
        else:
            print("Invalid choice.")


def editir_genudp_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "6":
            edit_kharejgenudp_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_udp()
            break
        else:
            print("Invalid choice.")


def edit_kharejgenudp_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "0":
            clear()
            editir_genudp_rmv()
            break
        else:
            print("Invalid choice.")


# geneve native


def editrmv_geneve_native():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Native\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_genudpn_rmv()
            break
        elif server_type == "2":
            editir_genudpn_rmv()
            break
        elif server_type == "0":
            clear()
            editremove_geneve()
            break
        else:
            print("Invalid choice.")


def editkh_genudpn_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Native [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "6":
            edit_irangenudpn_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_native()
            break
        else:
            print("Invalid choice.")


def edit_irangenudpn_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Native IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "0":
            clear()
            editkh_genudpn_rmv()
            break
        else:
            print("Invalid choice.")


def editir_genudpn_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Native [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "6":
            edit_kharejgenudpn_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_native()
            break
        else:
            print("Invalid choice.")


def edit_kharejgenudpn_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Native Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall()
            break
        elif server_type == "2":
            genz2_uninstall()
            break
        elif server_type == "3":
            genz3_uninstall()
            break
        elif server_type == "4":
            genz4_uninstall()
            break
        elif server_type == "5":
            genz5_uninstall()
            break
        elif server_type == "0":
            clear()
            editir_genudpn_rmv()
            break
        else:
            print("Invalid choice.")


# geneve gre6 v4
def editrmv_geneve_ipv4g6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V4\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gengrev4_rmv()
            break
        elif server_type == "2":
            editir_gengrev4_rmv()
            break
        elif server_type == "0":
            clear()
            editremove_geneve()
            break
        else:
            print("Invalid choice.")


def editkh_gengrev4_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V4 [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "6":
            edit_irangengrev4_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_ipv4g6()
            break
        else:
            print("Invalid choice.")


def edit_irangengrev4_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V4 IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "0":
            clear()
            editkh_gengrev4_rmv()
            break
        else:
            print("Invalid choice.")


def editir_gengrev4_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V4 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "6":
            edit_kharejgengrev4_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_ipv4g6()
            break
        else:
            print("Invalid choice.")


def edit_kharejgengrev4_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V4 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "0":
            clear()
            editir_gengrev4_rmv()
            break
        else:
            print("Invalid choice.")


# gen gre6 v6
def editrmv_geneve_ipv6g6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V6\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gengrev6_rmv()
            break
        elif server_type == "2":
            editir_gengrev6_rmv()
            break
        elif server_type == "0":
            clear()
            editremove_geneve()
            break
        else:
            print("Invalid choice.")


def editkh_gengrev6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V6 [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "6":
            edit_irangengrev6_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_ipv6g6()
            break
        else:
            print("Invalid choice.")


def edit_irangengrev6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V6 IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "0":
            clear()
            editkh_gengrev6_rmv()
            break
        else:
            print("Invalid choice.")


def editir_gengrev6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V6 [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "6":
            edit_kharejgengrev6_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_ipv6g6()
            break
        else:
            print("Invalid choice.")


def edit_kharejgengrev6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V6 Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1gre_uninstall()
            break
        elif server_type == "2":
            genz2gre_uninstall()
            break
        elif server_type == "3":
            genz3gre_uninstall()
            break
        elif server_type == "4":
            genz4gre_uninstall()
            break
        elif server_type == "5":
            genz5gre_uninstall()
            break
        elif server_type == "0":
            clear()
            editir_gengrev6_rmv()
            break
        else:
            print("Invalid choice.")


# geneve ipsec udp
def editrmv_geneve_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve UDP + IPsec\033[0m")
    print("2. \033[93mGeneve Native + IPsec\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            edit_genudpsec_rmv()
            break
        elif server_type == "2":
            edit_gennativesec_rmv()
            break
        elif server_type == "0":
            clear()
            editremove_geneve()
            break
        else:
            print("Invalid choice.")


def edit_genudpsec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Udp IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_genudpsec_rmv()
            break
        elif server_type == "2":
            editir_genudpsec_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_ipsec()
            break
        else:
            print("Invalid choice.")


def editkh_genudpsec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP IPsec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            break
        elif server_type == "6":
            edit_irangenudpsec_rmv()
            break
        elif server_type == "0":
            clear()
            edit_genudpsec_rmv()
            break
        else:
            print("Invalid choice.")


def edit_irangenudpsec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "0":
            clear()
            editkh_genudpsec_rmv()
            break
        else:
            print("Invalid choice.")


def editir_genudpsec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            break
        elif server_type == "6":
            edit_kharejgenudpsec_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_ipsec()
            break
        else:
            print("Invalid choice.")


def edit_kharejgenudpsec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve UDP IPsec Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "0":
            clear()
            editir_genudpsec_rmv()
            break
        else:
            print("Invalid choice.")


# gen native ipsec


def edit_gennativesec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve V6 IPsec\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_genudpsec6_rmv()
            break
        elif server_type == "2":
            editir_genudpsec6_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_ipsec()
            break
        else:
            print("Invalid choice.")


def editkh_genudpsec6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve V6 IPsec [5]Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            break
        elif server_type == "6":
            edit_irangenudpsec6_rmv()
            break
        elif server_type == "0":
            clear()
            edit_gennativesec_rmv()
            break
        else:
            print("Invalid choice.")


def edit_irangenudpsec6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve V6 IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            iran11_ipsec_genedit2()
            break
        elif server_type == "0":
            clear()
            editkh_genudpsec6_rmv()
            break
        else:
            print("Invalid choice.")


def editir_genudpsec6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve V6 IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            break
        elif server_type == "6":
            edit_kharejgenudpsec6_rmv()
            break
        elif server_type == "0":
            clear()
            edit_gennativesec_rmv()
            break
        else:
            print("Invalid choice.")


def edit_kharejgenudpsec6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve V6 IPsec Kharej\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "2":
            genz2u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "3":
            genz3u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "4":
            genz4u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "5":
            genz5u_uninstall_sec()
            kharej11_ipsec_genedit2()
            break
        elif server_type == "0":
            clear()
            editir_genudpsec6_rmv()
            break
        else:
            print("Invalid choice.")


# geneve gre6 v4
def editrmv_geneve_gre6sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve Gre6 V4 IPsec\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve GRE6 V4 + IPsec\033[0m")
    print("2. \033[93mGeneve GRE6 V6 + IPsec\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            edit_gengre6secv4_rmv()
            break
        elif server_type == "2":
            edit_gengre6secv6_rmv()
            break
        elif server_type == "0":
            clear()
            editremove_geneve()
            break
        else:
            print("Invalid choice.")


def edit_gengre6secv4_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V4 IPsec\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gengre6v4sec_rmv()
            break
        elif server_type == "2":
            editir_gengre6v4sec_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_gre6sec()
            break
        else:
            print("Invalid choice.")


def editkh_gengre6v4sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V4 IPsec [5]Kharej\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            break
        elif server_type == "6":
            edit_irangengre6v4sec_rmv()
            break
        elif server_type == "0":
            clear()
            edit_gengre6secv4_rmv()
            break
        else:
            print("Invalid choice.")


def edit_irangengre6v4sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V4 IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            iranp4_ipsec_questione2()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            iranp4_ipsec_questione2()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            iranp4_ipsec_questione2()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            iranp4_ipsec_questione2()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            iranp4_ipsec_questione2()
            break
        elif server_type == "0":
            clear()
            editkh_gengre6v4sec_rmv()
            break
        else:
            print("Invalid choice.")


def editir_gengre6v4sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V4 IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            break
        elif server_type == "6":
            edit_kharejgengre6v4sec_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_gre6sec()
            break
        else:
            print("Invalid choice.")


def edit_kharejgengre6v4sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V4 IPsec Kharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            kharejp4_ipsec_questione2()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            kharejp4_ipsec_questione2()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            kharejp4_ipsec_questione2()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            kharejp4_ipsec_questione2()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            kharejp4_ipsec_questione2()
            break
        elif server_type == "0":
            clear()
            editir_gengre6v4sec_rmv()
            break
        else:
            print("Invalid choice.")


# geneve gre6 v6
def edit_gengre6secv6_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V6 IPsec\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej | [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej | [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            editkh_gengre6v6sec_rmv()
            break
        elif server_type == "2":
            editir_gengre6v6sec_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_gre6sec()
            break
        else:
            print("Invalid choice.")


def editkh_gengre6v6sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V6 IPsec [5]Kharej\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej[1]\033[0m")
    print("2. \033[92mKharej[2]\033[0m")
    print("3. \033[93mKharej[3]\033[0m")
    print("4. \033[92mKharej[4]\033[0m")
    print("5. \033[92mKharej[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            break
        elif server_type == "6":
            edit_irangengre6v6sec_rmv()
            break
        elif server_type == "0":
            clear()
            edit_gengre6secv6_rmv()
            break
        else:
            print("Invalid choice.")


def edit_irangengre6v6sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V6 IPsec IRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN-Tunnel[1]\033[0m")
    print("2. \033[92mIRAN-Tunnel[2]\033[0m")
    print("3. \033[93mIRAN-Tunnel[3]\033[0m")
    print("4. \033[92mIRAN-Tunnel[4]\033[0m")
    print("5. \033[92mIRAN-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            iran_ipsecz_questione2()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            iran_ipsecz_questione2()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            iran_ipsecz_questione2()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            iran_ipsecz_questione2()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            iran_ipsecz_questione2()
            break
        elif server_type == "0":
            clear()
            editkh_gengre6v6sec_rmv()
            break
        else:
            print("Invalid choice.")


def editir_gengre6v6sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V6 IPsec [5]IRAN\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN[1]\033[0m")
    print("2. \033[92mIRAN[2]\033[0m")
    print("3. \033[93mIRAN[3]\033[0m")
    print("4. \033[92mIRAN[4]\033[0m")
    print("5. \033[92mIRAN[5]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            break
        elif server_type == "6":
            edit_kharejgengre6v6sec_rmv()
            break
        elif server_type == "0":
            clear()
            editrmv_geneve_gre6sec()
            break
        else:
            print("Invalid choice.")


def edit_kharejgengre6v6sec_rmv():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Geneve GRE6 V6 IPsec Kharej\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej-Tunnel[1]\033[0m")
    print("2. \033[92mKharej-Tunnel[2]\033[0m")
    print("3. \033[93mKharej-Tunnel[3]\033[0m")
    print("4. \033[92mKharej-Tunnel[4]\033[0m")
    print("5. \033[92mKharej-Tunnel[5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz1_uninstall_sec()
            kharej_ipsecz_questione2()
            break
        elif server_type == "2":
            genz2_uninstall_sec()
            kharej_ipsecz_questione2()
            break
        elif server_type == "3":
            genz3_uninstall_sec()
            kharej_ipsecz_questione2()
            break
        elif server_type == "4":
            genz4_uninstall_sec()
            kharej_ipsecz_questione2()
            break
        elif server_type == "5":
            genz5_uninstall_sec()
            kharej_ipsecz_questione2()
            break
        elif server_type == "0":
            clear()
            editir_gengre6v6sec_rmv()
            break
        else:
            print("Invalid choice.")


def mtu2_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mEdit MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m6TO4\033[0m")
    print("2. \033[93mIP6IP6 \033[0m")
    print("3. \033[92mGRE6 \033[0m")
    print("4. \033[93mGRE6tap \033[0m")
    print("5. \033[92mGeneve \033[0m")
    print("6. \033[96manycast \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_mnu()
            break
        elif server_type == "2":
            ip6_mnu()
            break
        elif server_type == "3":
            gre6mtu_mnu()
            break
        elif server_type == "4":
            gre6tapt_mnu()
            break
        elif server_type == "5":
            geneve_multi_mtumnu()
            break
        elif server_type == "6":
            i6to4any2_mtu()
            break
        elif server_type == "0":
            clear()
            multiserver_mnu()
            break
        else:
            print("Invalid choice.")


def geneve_multi_mtumnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve UDP  \033[0m")
    print("2. \033[93mGeneve + Native\033[0m")
    print("3. \033[96mGeneve + IPv4 + GRE6\033[0m")
    print("4. \033[92mGeneve + Native + GRE6\033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            simplegenm_mnu()
            break
        elif server_type == "2":
            simplegenm_mnu()
            break
        elif server_type == "3":
            ipv4genm_mnu()
            break
        elif server_type == "4":
            ipv6genm_mnu()
            break
        elif server_type == "0":
            clear()
            mtu2_menu()
            break
        else:
            print("Invalid choice.")


def ipv6genm_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN \033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genip6_mutlti_mtuk5()
            break
        elif server_type == "2":
            genip6_mutlti_mtuk1()
            break
        elif server_type == "0":
            clear()
            geneve_multi_mtumnu()
            break
        else:
            print("Invalid choice.")


def genip6_mutlti_mtuk5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genn1_mutli_mtu()
            break
        elif server_type == "2":
            genn2_mutli_mtu()
            break
        elif server_type == "3":
            genn3_mutli_mtu()
            break
        elif server_type == "4":
            genn4_mutli_mtu()
            break
        elif server_type == "5":
            genn5_mutli_mtu()
            break
        elif server_type == "6":
            ip6_mtu3_qgen()
            break
        elif server_type == "0":
            clear()
            ipv6genm_mnu()
            break
        else:
            print("Invalid choice.")


def ip6_mtu3_qgen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genn1_mutli_mtu()
            break
        elif server_type == "2":
            genn2_mutli_mtu()
            break
        elif server_type == "3":
            genn3_mutli_mtu()
            break
        elif server_type == "4":
            genn4_mutli_mtu()
            break
        elif server_type == "5":
            genn5_mutli_mtu()
            break
        elif server_type == "6":
            ip6_m3_qgen()
            break
        elif server_type == "0":
            clear()
            genip6_mutlti_mtuk5()
            break
        else:
            print("Invalid choice.")


def ip6_m3_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genn{}_mutli_mtu()".format(i)
        globals()[menu_name]()


def genip6_mutlti_mtuk1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genn1_mutli_mtu()
            break
        elif server_type == "2":
            genn2_mutli_mtu()
            break
        elif server_type == "3":
            genn3_mutli_mtu()
            break
        elif server_type == "4":
            genn4_mutli_mtu()
            break
        elif server_type == "5":
            genn5_mutli_mtu()
            break
        elif server_type == "6":
            ip6_mtu4_qgen()
            break
        elif server_type == "0":
            clear()
            ipv6genm_mnu()
            break
        else:
            print("Invalid choice.")


def ip6_mtu4_qgen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genn1_mutli_mtu()
            break
        elif server_type == "2":
            genn2_mutli_mtu()
            break
        elif server_type == "3":
            genn3_mutli_mtu()
            break
        elif server_type == "4":
            genn4_mutli_mtu()
            break
        elif server_type == "5":
            genn5_mutli_mtu()
            break
        elif server_type == "6":
            ip6_m4_qgen()
            break
        elif server_type == "0":
            clear()
            genip6_mutlti_mtuk1()
            break
        else:
            print("Invalid choice.")


def ip6_m4_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genn{}_mutli_mtu()".format(i)
        globals()[menu_name]()


# gen simple & native prequisite
def gen1_mutli_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys1.sh"):
        with open("/etc/sys1.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen1 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys1.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen2_mutli_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys2.sh"):
        with open("/etc/sys2.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen2 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys2.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen3_mutli_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys3.sh"):
        with open("/etc/sys3.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen3 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys3.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen4_mutli_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys4.sh"):
        with open("/etc/sys4.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen4 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys4.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen5_mutli_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys5.sh"):
        with open("/etc/sys5.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen5 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys5.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


# native
def simplegenm_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN \033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_mutlti_mtuk5()
            break
        elif server_type == "2":
            gen_mutlti_mtuk1()
            break
        elif server_type == "0":
            clear()
            geneve_multi_mtumnu()
            break
        else:
            print("Invalid choice.")


def gen_mutlti_mtuk5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen1_mutli_mtu()
            break
        elif server_type == "2":
            gen2_mutli_mtu()
            break
        elif server_type == "3":
            gen3_mutli_mtu()
            break
        elif server_type == "4":
            gen4_mutli_mtu()
            break
        elif server_type == "5":
            gen5_mutli_mtu()
            break
        elif server_type == "6":
            mtu3_qgen()
            break
        elif server_type == "0":
            clear()
            simplegenm_mnu()
            break
        else:
            print("Invalid choice.")


def mtu3_qgen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen1_mutli_mtu()
            break
        elif server_type == "2":
            gen2_mutli_mtu()
            break
        elif server_type == "3":
            gen3_mutli_mtu()
            break
        elif server_type == "4":
            gen4_mutli_mtu()
            break
        elif server_type == "5":
            gen5_mutli_mtu()
            break
        elif server_type == "6":
            m3_qgen()
            break
        elif server_type == "0":
            clear()
            gen_mutlti_mtuk5()
            break
        else:
            print("Invalid choice.")


def m3_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gen{}_mutli_mtu".format(i)
        globals()[menu_name]()


def gen_mutlti_mtuk1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen1_mutli_mtu()
            break
        elif server_type == "2":
            gen2_mutli_mtu()
            break
        elif server_type == "3":
            gen3_mutli_mtu()
            break
        elif server_type == "4":
            gen4_mutli_mtu()
            break
        elif server_type == "5":
            gen5_mutli_mtu()
            break
        elif server_type == "6":
            mtu4_qgen()
            break
        elif server_type == "0":
            clear()
            simplegenm_mnu()
            break
        else:
            print("Invalid choice.")


def mtu4_qgen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen1_mutli_mtu()
            break
        elif server_type == "2":
            gen2_mutli_mtu()
            break
        elif server_type == "3":
            gen3_mutli_mtu()
            break
        elif server_type == "4":
            gen4_mutli_mtu()
            break
        elif server_type == "5":
            gen5_mutli_mtu()
            break
        elif server_type == "6":
            m4_qgen()
            break
        elif server_type == "0":
            clear()
            gen_mutlti_mtuk1()
            break
        else:
            print("Invalid choice.")


def m4_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gen{}_mutli_mtu".format(i)
        globals()[menu_name]()


# ip4 gre6 gen
def ipv4genm_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[5]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN \033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genip4_mutlti_mtuk5()
            break
        elif server_type == "2":
            genip4_mutlti_mtuk1()
            break
        elif server_type == "0":
            clear()
            geneve_multi_mtumnu()
            break
        else:
            print("Invalid choice.")


def genip4_mutlti_mtuk5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genip41_mutli_mtu()
            break
        elif server_type == "2":
            genip42_mutli_mtu()
            break
        elif server_type == "3":
            genip43_mutli_mtu()
            break
        elif server_type == "4":
            genip44_mutli_mtu()
            break
        elif server_type == "5":
            genip45_mutli_mtu()
            break
        elif server_type == "6":
            ip4_mtu3_qgen()
            break
        elif server_type == "0":
            clear()
            ipv4genm_mnu()
            break
        else:
            print("Invalid choice.")


def ip4_mtu3_qgen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genip41_mutli_mtu()
            break
        elif server_type == "2":
            genip42_mutli_mtu()
            break
        elif server_type == "3":
            genip43_mutli_mtu()
            break
        elif server_type == "4":
            genip44_mutli_mtu()
            break
        elif server_type == "5":
            genip45_mutli_mtu()
            break
        elif server_type == "6":
            ip4_m3_qgen()
            break
        elif server_type == "0":
            clear()
            genip4_mutlti_mtuk5()
            break
        else:
            print("Invalid choice.")


def ip4_m3_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genip4{}_mutli_mtu".format(i)
        globals()[menu_name]()


def genip4_mutlti_mtuk1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genip41_mutli_mtu()
            break
        elif server_type == "2":
            genip42_mutli_mtu()
            break
        elif server_type == "3":
            genip43_mutli_mtu()
            break
        elif server_type == "4":
            genip44_mutli_mtu()
            break
        elif server_type == "5":
            genip45_mutli_mtu()
            break
        elif server_type == "6":
            ip4_mtu4_qgen()
            break
        elif server_type == "0":
            clear()
            ipv4genm_mnu()
            break
        else:
            print("Invalid choice.")


def ip4_mtu4_qgen():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genip41_mutli_mtu()
            break
        elif server_type == "2":
            genip42_mutli_mtu()
            break
        elif server_type == "3":
            genip43_mutli_mtu()
            break
        elif server_type == "4":
            genip44_mutli_mtu()
            break
        elif server_type == "5":
            genip45_mutli_mtu()
            break
        elif server_type == "6":
            ip4_m4_qgen()
            break
        elif server_type == "0":
            clear()
            genip4_mutlti_mtuk1()
            break
        else:
            print("Invalid choice.")


def ip4_m4_qgen():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "genip4{}_mutli_mtu".format(i)
        globals()[menu_name]()


## gre6 gen ipv4 mtu prequisite
def genip41_mutli_mtu():
    gre6_kh1_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys1.sh"):
        with open("/etc/sys1.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen1 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys1.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genip42_mutli_mtu():
    gre6_kh2_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys2.sh"):
        with open("/etc/sys2.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen2 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys2.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genip43_mutli_mtu():
    gre6_kh3_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys3.sh"):
        with open("/etc/sys3.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen3 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys3.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genip44_mutli_mtu():
    gre6_kh4_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys4.sh"):
        with open("/etc/sys4.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen4 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys4.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genip45_mutli_mtu():
    gre6_kh5_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys5.sh"):
        with open("/etc/sys5.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen5 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys5.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genn1_mutli_mtu():
    gre6_kh1tap_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen1 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys1.sh"):
        with open("/etc/sys1.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen1 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys1.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genn2_mutli_mtu():
    gre6_kh2tap_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen2 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys2.sh"):
        with open("/etc/sys2.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen2 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys2.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genn3_mutli_mtu():
    gre6_kh3tap_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen3 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys3.sh"):
        with open("/etc/sys3.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen3 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys3.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genn4_mutli_mtu():
    gre6_kh4tap_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen4 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys4.sh"):
        with open("/etc/sys4.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen4 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys4.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def genn5_mutli_mtu():
    gre6_kh5tap_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen5 mtu {mtu_value}\n"

    if os.path.exists("/etc/sys5.sh"):
        with open("/etc/sys5.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen5 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys5.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def private_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mPrivateIP Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN \033[0m")
    print("3. \033[92m[5]Kharej [1]IRAN + IPSEC\033[0m")
    print("4. \033[93m[1]Kharej [5]IRAN + IPSEC\033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            khprivate_mnu()
            break
        elif server_type == "2":
            irprivate_mnu()
            break
        elif server_type == "3":
            khprivate_mnu2()
            break
        elif server_type == "4":
            irprivate_mnu()
            break
        elif server_type == "0":
            clear()
            mtu2_menu()
            break
        else:
            print("Invalid choice.")


def khprivate_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[10]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[93mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("6. \033[92mKharej [6]\033[0m")
    print("7. \033[93mKharej [7]\033[0m")
    print("8. \033[93mKharej [8]\033[0m")
    print("9. \033[92mKharej [9]\033[0m")
    print("10.\033[92mKharej [10]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_kh1_mtu()
            break
        elif server_type == "2":
            priv_kh2_mtu()
            break
        elif server_type == "3":
            priv_kh3_mtu()
            break
        elif server_type == "4":
            priv_kh4_mtu()
            break
        elif server_type == "5":
            priv_kh5_mtu()
            break
        elif server_type == "6":
            priv_kh6_mtu()
            break
        elif server_type == "7":
            priv_kh7_mtu()
            break
        elif server_type == "8":
            priv_kh8_mtu()
            break
        elif server_type == "9":
            priv_kh9_mtu()
            break
        elif server_type == "10":
            priv_kh10_mtu()
            break
        elif server_type == "11":
            mtu1_q()
            break
        elif server_type == "0":
            clear()
            private_mnu()
            break
        else:
            print("Invalid choice.")


def mtu1_q():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[93mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[92mTunnel [6]\033[0m")
    print("7. \033[93mTunnel [7]\033[0m")
    print("8. \033[93mTunnel [8]\033[0m")
    print("9. \033[92mTunnel [9]\033[0m")
    print("10.\033[92mTunnel [10]\033[0m")
    print("11.\033[96mAll OF Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_ir1_mtu()
            break
        elif server_type == "2":
            priv_ir2_mtu()
            break
        elif server_type == "3":
            priv_ir3_mtu()
            break
        elif server_type == "4":
            priv_ir4_mtu()
            break
        elif server_type == "5":
            priv_ir5_mtu()
            break
        elif server_type == "6":
            priv_ir6_mtu()
            break
        elif server_type == "7":
            priv_ir7_mtu()
            break
        elif server_type == "8":
            priv_ir8_mtu()
            break
        elif server_type == "9":
            priv_ir9_mtu()
            break
        elif server_type == "10":
            priv_ir10_mtu()
            break
        elif server_type == "11":
            mtu1_q1()
            break
        elif server_type == "0":
            clear()
            khprivate_mnu()
            break
        else:
            print("Invalid choice.")


def khprivate_mnu2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]Kharej IPSEC Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[93mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_kh1_mtu()
            break
        elif server_type == "2":
            priv_kh2_mtu()
            break
        elif server_type == "3":
            priv_kh3_mtu()
            break
        elif server_type == "4":
            priv_kh4_mtu()
            break
        elif server_type == "5":
            priv_kh5_mtu()
            break
        elif server_type == "6":
            mtu1_q22()
            break
        elif server_type == "0":
            clear()
            private_mnu()
            break
        else:
            print("Invalid choice.")


def mtu1_q22():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN IPSEC MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[93mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6.\033[96mAll OF Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_ir1_mtu()
            break
        elif server_type == "2":
            priv_ir2_mtu()
            break
        elif server_type == "3":
            priv_ir3_mtu()
            break
        elif server_type == "4":
            priv_ir4_mtu()
            break
        elif server_type == "5":
            priv_ir5_mtu()
            break
        elif server_type == "6":
            mtu1_q1()
            break
        elif server_type == "0":
            clear()
            khprivate_mnu()
            break
        else:
            print("Invalid choice.")


##later usage
def mtu1_q1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "priv_ir{}_mtu".format(i)
        globals()[menu_name]()


def irprivate_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[93mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_ir1_mtu()
            break
        elif server_type == "2":
            priv_ir2_mtu()
            break
        elif server_type == "3":
            priv_ir3_mtu()
            break
        elif server_type == "4":
            priv_ir4_mtu()
            break
        elif server_type == "5":
            priv_ir5_mtu()
            break
        elif server_type == "6":
            mtu2_q()
            break
        elif server_type == "0":
            clear()
            private_mnu()
            break
        else:
            print("Invalid choice.")


def mtu2_q():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[93mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll OF Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            priv_ir1_mtu()
            break
        elif server_type == "2":
            priv_ir2_mtu()
            break
        elif server_type == "3":
            priv_ir3_mtu()
            break
        elif server_type == "4":
            priv_ir4_mtu()
            break
        elif server_type == "5":
            priv_ir5_mtu()
            break
        elif server_type == "6":
            mtu1_q2()
            break
        elif server_type == "0":
            clear()
            irprivate_mnu()
            break
        else:
            print("Invalid choice.")


# later usage
def mtu1_q2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "priv_kh{}_mtu".format(i)
        globals()[menu_name]()


## gre6 & gre6tap menu


def gre6tapt_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE6 Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mNative GREtap [IPSEC too]\033[0m")
    print("2. \033[93mIPV4 GREtap [IPSEC too] \033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            nativegretap_mnu()
            break
        elif server_type == "2":
            gre6t_mnu()
            break
        elif server_type == "0":
            clear()
            mtu2_menu()
            break
        else:
            print("Invalid choice.")


# native
def nativegretap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE6tap Native [IPSEC too] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN \033[0m")
    print("3. \033[92m[5]Kharej [1]IRAN + IPSEC\033[0m")
    print("4. \033[93m[1]Kharej [5]IRAN + IPSEC\033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            khgre6tap_mnu()
            break
        elif server_type == "2":
            irgre6tap_mnu()
            break
        elif server_type == "3":
            khgre6tap_mnu()
            break
        elif server_type == "4":
            irgre6tap_mnu()
            break
        elif server_type == "0":
            clear()
            gre6tapt_mnu()
            break
        else:
            print("Invalid choice.")


## gre6 kharej menu
def khgre6tap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[10]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("6. \033[92mKharej [6]\033[0m")
    print("7. \033[92mKharej [7]\033[0m")
    print("8. \033[93mKharej [8]\033[0m")
    print("9. \033[92mKharej [9]\033[0m")
    print("10.\033[92mKharej [10]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh1tap_mtu()
            break
        elif server_type == "2":
            gre6_kh2tap_mtu()
            break
        elif server_type == "3":
            gre6_kh3tap_mtu()
            break
        elif server_type == "4":
            gre6_kh4tap_mtu()
            break
        elif server_type == "5":
            gre6_kh5tap_mtu()
            break
        elif server_type == "6":
            gre6_kh6tap_mtu()
            break
        elif server_type == "7":
            gre6_kh7tap_mtu()
            break
        elif server_type == "8":
            gre6_kh8tap_mtu()
            break
        elif server_type == "9":
            gre6_kh9tap_mtu()
            break
        elif server_type == "10":
            gre6_kh10tap_mtu()
            break
        elif server_type == "11":
            mtu3_qtap()
            break
        elif server_type == "0":
            clear()
            nativegretap_mnu()
            break
        else:
            print("Invalid choice.")


def mtu3_qtap():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[92mTunnel [6]\033[0m")
    print("7. \033[92mTunnel [7]\033[0m")
    print("8. \033[93mTunnel [8]\033[0m")
    print("9. \033[92mTunnel [9]\033[0m")
    print("10. 033[92mTunnel [10]\033[0m")
    print("11. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_ir1tap_mtu()
            break
        elif server_type == "2":
            gre6_ir2tap_mtu()
            break
        elif server_type == "3":
            gre6_ir3tap_mtu()
            break
        elif server_type == "4":
            gre6_ir4tap_mtu()
            break
        elif server_type == "5":
            gre6_ir5tap_mtu()
            break
        elif server_type == "6":
            gre6_ir6tap_mtu()
            break
        elif server_type == "7":
            gre6_ir7tap_mtu()
            break
        elif server_type == "8":
            gre6_ir8tap_mtu()
            break
        elif server_type == "9":
            gre6_ir9tap_mtu()
            break
        elif server_type == "10":
            gre6_ir10tap_mtu()
            break
        elif server_type == "11":
            m3_qtap()
            break
        elif server_type == "0":
            clear()
            khgre6tap_mnu()
            break
        else:
            print("Invalid choice.")


def m3_qtap():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6_ir{}tap_mtu".format(i)
        globals()[menu_name]()


def khgre6tap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]Kharej IPSEC Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh1tap_mtu()
            break
        elif server_type == "2":
            gre6_kh2tap_mtu()
            break
        elif server_type == "3":
            gre6_kh3tap_mtu()
            break
        elif server_type == "4":
            gre6_kh4tap_mtu()
            break
        elif server_type == "5":
            gre6_kh5tap_mtu()
            break
        elif server_type == "6":
            mtu3_qtap22()
            break
        elif server_type == "0":
            clear()
            nativegretap_mnu()
            break
        else:
            print("Invalid choice.")


def mtu3_qtap22():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN IPSEC Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_ir1tap_mtu()
            break
        elif server_type == "2":
            gre6_ir2tap_mtu()
            break
        elif server_type == "3":
            gre6_ir3tap_mtu()
            break
        elif server_type == "4":
            gre6_ir4tap_mtu()
            break
        elif server_type == "5":
            gre6_ir5tap_mtu()
            break
        elif server_type == "6":
            m3_qtap()
            break
        elif server_type == "0":
            clear()
            khgre6tap_mnu()
            break
        else:
            print("Invalid choice.")


def irgre6tap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_ir1tap_mtu()
            break
        elif server_type == "2":
            gre6_ir2tap_mtu()
            break
        elif server_type == "3":
            gre6_ir3tap_mtu()
            break
        elif server_type == "4":
            gre6_ir4tap_mtu()
            break
        elif server_type == "5":
            gre6_ir5tap_mtu()
            break
        elif server_type == "6":
            mtu4_qtap()
            break
        elif server_type == "0":
            clear()
            nativegretap_mnu()
            break
        else:
            print("Invalid choice.")


def mtu4_qtap():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh1tap_mtu()
            break
        elif server_type == "2":
            gre6_kh2tap_mtu()
            break
        elif server_type == "3":
            gre6_kh3tap_mtu()
            break
        elif server_type == "4":
            gre6_kh4tap_mtu()
            break
        elif server_type == "5":
            gre6_kh5tap_mtu()
            break
        elif server_type == "6":
            m4_qtap()
            break
        elif server_type == "0":
            clear()
            irgre6tap_mnu()
            break
        else:
            print("Invalid choice.")


def m4_qtap():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6_kh{}tap_mtu".format(i)
        globals()[menu_name]()


##
def gre6t_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE6tap V4 [IPSEC too] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN \033[0m")
    print("3. \033[92m[5]Kharej [1]IRAN + IPSEC\033[0m")
    print("4. \033[93m[1]Kharej [5]IRAN + IPSEC\033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            khgre6_mnu()
            break
        elif server_type == "2":
            irgre6_mnu()
            break
        elif server_type == "3":
            khgre6_mnu2()
            break
        elif server_type == "4":
            irgre6_mnu()
            break
        elif server_type == "0":
            clear()
            gre6tapt_mnu()
            break
        else:
            print("Invalid choice.")


def gre6mtu_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE6 Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [5]IRAN \033[0m")
    print("3. \033[92m[5]Kharej [1]IRAN + IPSEC\033[0m")
    print("4. \033[93m[1]Kharej [5]IRAN + IPSEC\033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            khgre6_mnu()
            break
        elif server_type == "2":
            irgre6_mnu()
            break
        elif server_type == "3":
            khgre6_mnu2()
            break
        elif server_type == "4":
            irgre6_mnu()
            break
        elif server_type == "0":
            clear()
            mtu2_menu()
            break
        else:
            print("Invalid choice.")


## gre6 kharej menu
def khgre6_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[10]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("6. \033[92mKharej [6]\033[0m")
    print("7. \033[92mKharej [7]\033[0m")
    print("8. \033[93mKharej [8]\033[0m")
    print("9. \033[92mKharej [9]\033[0m")
    print("10.\033[92mKharej [10]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("11. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh1_mtu()
            break
        elif server_type == "2":
            gre6_kh2_mtu()
            break
        elif server_type == "3":
            gre6_kh3_mtu()
            break
        elif server_type == "4":
            gre6_kh4_mtu()
            break
        elif server_type == "5":
            gre6_kh5_mtu()
            break
        elif server_type == "6":
            gre6_kh6_mtu()
            break
        elif server_type == "7":
            gre6_kh7_mtu()
            break
        elif server_type == "8":
            gre6_kh8_mtu()
            break
        elif server_type == "9":
            gre6_kh9_mtu()
            break
        elif server_type == "10":
            gre6_kh10_mtu()
            break
        elif server_type == "11":
            mtu3_q()
            break
        elif server_type == "0":
            clear()
            gre6mtu_mnu()
            break
        else:
            print("Invalid choice.")


def mtu3_q():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[92mTunnel [6]\033[0m")
    print("7. \033[92mTunnel [7]\033[0m")
    print("8. \033[93mTunnel [8]\033[0m")
    print("9. \033[92mTunnel [9]\033[0m")
    print("10.\033[92mTunnel [10]\033[0m")
    print("11.\033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_ir1_mtu()
            break
        elif server_type == "2":
            gre6_ir2_mtu()
            break
        elif server_type == "3":
            gre6_ir3_mtu()
            break
        elif server_type == "4":
            gre6_ir4_mtu()
            break
        elif server_type == "5":
            gre6_ir5_mtu()
            break
        elif server_type == "6":
            gre6_ir6_mtu()
            break
        elif server_type == "7":
            gre6_ir7_mtu()
            break
        elif server_type == "8":
            gre6_ir8_mtu()
            break
        elif server_type == "9":
            gre6_ir9_mtu()
            break
        elif server_type == "10":
            gre6_ir10_mtu()
            break
        elif server_type == "11":
            m3_q()
            break
        elif server_type == "0":
            clear()
            khgre6_mnu()
            break
        else:
            print("Invalid choice.")


def m3_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6_ir{}_mtu".format(i)
        globals()[menu_name]()


def khgre6_mnu2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]Kharej IPSEC Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh1_mtu()
            break
        elif server_type == "2":
            gre6_kh2_mtu()
            break
        elif server_type == "3":
            gre6_kh3_mtu()
            break
        elif server_type == "4":
            gre6_kh4_mtu()
            break
        elif server_type == "5":
            gre6_kh5_mtu()
            break
        elif server_type == "6":
            mtu3_q22()
            break
        elif server_type == "0":
            clear()
            gre6mtu_mnu()
            break
        else:
            print("Invalid choice.")


def mtu3_q22():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6.\033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_ir1_mtu()
            break
        elif server_type == "2":
            gre6_ir2_mtu()
            break
        elif server_type == "3":
            gre6_ir3_mtu()
            break
        elif server_type == "4":
            gre6_ir4_mtu()
            break
        elif server_type == "5":
            gre6_ir5_mtu()
            break
        elif server_type == "6":
            m3_q()
            break
        elif server_type == "0":
            clear()
            khgre6_mnu()
            break
        else:
            print("Invalid choice.")


def irgre6_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6. \033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_ir1_mtu()
            break
        elif server_type == "2":
            gre6_ir2_mtu()
            break
        elif server_type == "3":
            gre6_ir3_mtu()
            break
        elif server_type == "4":
            gre6_ir4_mtu()
            break
        elif server_type == "5":
            gre6_ir5_mtu()
            break
        elif server_type == "6":
            mtu4_q()
            break
        elif server_type == "0":
            clear()
            gre6mtu_mnu()
            break
        else:
            print("Invalid choice.")


def mtu4_q():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_kh1_mtu()
            break
        elif server_type == "2":
            gre6_kh2_mtu()
            break
        elif server_type == "3":
            gre6_kh3_mtu()
            break
        elif server_type == "4":
            gre6_kh4_mtu()
            break
        elif server_type == "5":
            gre6_kh5_mtu()
            break
        elif server_type == "6":
            m4_q()
            break
        elif server_type == "0":
            clear()
            irgre6_mnu()
            break
        else:
            print("Invalid choice.")


def m4_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "gre6_kh{}_mtu".format(i)
        globals()[menu_name]()


## ipip6 menu


def ip6_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIP6IP6 Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m[10]Kharej [1]IRAN\033[0m")
    print("2. \033[93m[1]Kharej [10]IRAN \033[0m")
    print("3. \033[92m[5]Kharej [1]IRAN + IPSEC\033[0m")
    print("4. \033[93m[1]Kharej [5]IRAN + IPSEC \033[0m")
    print("0. \033[94mback to the MTU menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            khip6_mnu()
            break
        elif server_type == "2":
            irip6_mnu()
            break
        elif server_type == "3":
            khip6_mnu2()
            break
        elif server_type == "4":
            irip6_mnu2()
            break
        elif server_type == "0":
            clear()
            mtu2_menu()
            break
        else:
            print("Invalid choice.")


def khip6_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[10]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("6. \033[92mKharej [6]\033[0m")
    print("7. \033[92mKharej [7]\033[0m")
    print("8. \033[93mKharej [8]\033[0m")
    print("9. \033[92mKharej [9]\033[0m")
    print("10.\033[92mKharej [10]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("11.\033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_kh1_mtu()
            break
        elif server_type == "2":
            ipip_kh2_mtu()
            break
        elif server_type == "3":
            ipip_kh3_mtu()
            break
        elif server_type == "4":
            ipip_kh4_mtu()
            break
        elif server_type == "5":
            ipip_kh5_mtu()
            break
        elif server_type == "6":
            ipip_kh6_mtu()
            break
        elif server_type == "7":
            ipip_kh7_mtu()
            break
        elif server_type == "8":
            ipip_kh8_mtu()
            break
        elif server_type == "9":
            ipip_kh9_mtu()
            break
        elif server_type == "10":
            ipip_kh10_mtu()
            break
        elif server_type == "11":
            mtu5_q()
            break
        elif server_type == "0":
            clear()
            ip6_mnu()
            break
        else:
            print("Invalid choice.")


def mtu5_q():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[92mTunnel [6]\033[0m")
    print("7. \033[92mTunnel [7]\033[0m")
    print("8. \033[93mTunnel [8]\033[0m")
    print("9. \033[92mTunnel [9]\033[0m")
    print("10.\033[92mTunnel [10]\033[0m")
    print("11.\033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_ir1_mtu()
            break
        elif server_type == "2":
            ipip_ir2_mtu()
            break
        elif server_type == "3":
            ipip_ir3_mtu()
            break
        elif server_type == "4":
            ipip_ir4_mtu()
            break
        elif server_type == "5":
            ipip_ir5_mtu()
            break
        elif server_type == "6":
            ipip_ir6_mtu()
            break
        elif server_type == "7":
            ipip_ir7_mtu()
            break
        elif server_type == "8":
            ipip_ir8_mtu()
            break
        elif server_type == "9":
            ipip_ir9_mtu()
            break
        elif server_type == "10":
            ipip_ir10_mtu()
            break
        elif server_type == "11":
            m5_q()
            break
        elif server_type == "0":
            clear()
            khip6_mnu()
            break
        else:
            print("Invalid choice.")


def m5_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mKharej Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "ipip_ir{}_mtu".format(i)
        globals()[menu_name]()


# ipip mtu sec
def khip6_mnu2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[10]Kharej Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej [1]\033[0m")
    print("2. \033[92mKharej [2]\033[0m")
    print("3. \033[93mKharej [3]\033[0m")
    print("4. \033[92mKharej [4]\033[0m")
    print("5. \033[92mKharej [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6.\033[93mIRAN \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_kh1_mtu()
            break
        elif server_type == "2":
            ipip_kh2_mtu()
            break
        elif server_type == "3":
            ipip_kh3_mtu()
            break
        elif server_type == "4":
            ipip_kh4_mtu()
            break
        elif server_type == "5":
            ipip_kh5_mtu()
            break
        elif server_type == "6":
            mtu5_q22()
            break
        elif server_type == "0":
            clear()
            ip6_mnu()
            break
        else:
            print("Invalid choice.")


def mtu5_q22():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6.\033[96mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_ir1_mtu()
            break
        elif server_type == "2":
            ipip_ir2_mtu()
            break
        elif server_type == "3":
            ipip_ir3_mtu()
            break
        elif server_type == "4":
            ipip_ir4_mtu()
            break
        elif server_type == "5":
            ipip_ir5_mtu()
            break
        elif server_type == "6":
            m5_q()
            break
        elif server_type == "0":
            clear()
            khip6_mnu2()
            break
        else:
            print("Invalid choice.")


def irip6_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("6. \033[92mIRAN [6]\033[0m")
    print("7. \033[92mIRAN [7]\033[0m")
    print("8. \033[93mIRAN [8]\033[0m")
    print("9. \033[92mIRAN [9]\033[0m")
    print("10.\033[92mIRAN [10]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("11.\033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_ir1_mtu()
            break
        elif server_type == "2":
            ipip_ir2_mtu()
            break
        elif server_type == "3":
            ipip_ir3_mtu()
            break
        elif server_type == "4":
            ipip_ir4_mtu()
            break
        elif server_type == "5":
            ipip_ir5_mtu()
            break
        elif server_type == "6":
            ipip_ir6_mtu()
            break
        elif server_type == "7":
            ipip_ir7_mtu()
            break
        elif server_type == "8":
            ipip_ir8_mtu()
            break
        elif server_type == "9":
            ipip_ir9_mtu()
            break
        elif server_type == "10":
            ipip_ir10_mtu()
            break
        elif server_type == "11":
            mtu6_q()
            break
        elif server_type == "0":
            clear()
            ip6_mnu()
            break
        else:
            print("Invalid choice.")


def mtu6_q():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6. \033[92mTunnel [6]\033[0m")
    print("7. \033[92mTunnel [7]\033[0m")
    print("8. \033[93mTunnel [8]\033[0m")
    print("9. \033[92mTunnel [9]\033[0m")
    print("10.\033[92mTunnel [10]\033[0m")
    print("11.\033[92mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_kh1_mtu()
            break
        elif server_type == "2":
            ipip_kh2_mtu()
            break
        elif server_type == "3":
            ipip_kh3_mtu()
            break
        elif server_type == "4":
            ipip_kh4_mtu()
            break
        elif server_type == "5":
            ipip_kh5_mtu()
            break
        elif server_type == "6":
            ipip_kh6_mtu()
            break
        elif server_type == "7":
            ipip_kh7_mtu()
            break
        elif server_type == "8":
            ipip_kh8_mtu()
            break
        elif server_type == "9":
            ipip_kh9_mtu()
            break
        elif server_type == "10":
            ipip_kh10_mtu()
            break
        elif server_type == "11":
            m6_q()
            break
        elif server_type == "0":
            clear()
            irip6_mnu()
            break
        else:
            print("Invalid choice.")


def m6_q():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    num_servers = int(
        input("\033[93mHow many \033[92mIRAN Servers\033[93m do you have?\033[0m ")
    )

    for i in range(1, num_servers + 1):
        menu_name = "ipip_kh{}_mtu".format(i)
        globals()[menu_name]()


# ipip mtu sec
def irip6_mnu2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m[5]IRAN Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIRAN [1]\033[0m")
    print("2. \033[92mIRAN [2]\033[0m")
    print("3. \033[93mIRAN [3]\033[0m")
    print("4. \033[92mIRAN [4]\033[0m")
    print("5. \033[92mIRAN [5]\033[0m")
    print("\033[93m──────────────────────────────────────\033[0m")
    print("6.\033[93mKharej \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_ir1_mtu()
            break
        elif server_type == "2":
            ipip_ir2_mtu()
            break
        elif server_type == "3":
            ipip_ir3_mtu()
            break
        elif server_type == "4":
            ipip_ir4_mtu()
            break
        elif server_type == "5":
            ipip_ir5_mtu()
            break
        elif server_type == "6":
            mtu6_q22()
            break
        elif server_type == "0":
            clear()
            ip6_mnu()
            break
        else:
            print("Invalid choice.")


def mtu6_q22():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKHAREJ Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mTunnel [1]\033[0m")
    print("2. \033[92mTunnel [2]\033[0m")
    print("3. \033[93mTunnel [3]\033[0m")
    print("4. \033[92mTunnel [4]\033[0m")
    print("5. \033[92mTunnel [5]\033[0m")
    print("6.\033[92mAll Of Them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip_kh1_mtu()
            break
        elif server_type == "2":
            ipip_kh2_mtu()
            break
        elif server_type == "3":
            ipip_kh3_mtu()
            break
        elif server_type == "4":
            ipip_kh4_mtu()
            break
        elif server_type == "5":
            ipip_kh5_mtu()
            break
        elif server_type == "6":
            m6_q()
            break
        elif server_type == "0":
            clear()
            irip6_mnu2()
            break
        else:
            print("Invalid choice.")


def ipip_kh1_mtu():

    priv_kh1_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip1 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip1.sh"):
        with open("/etc/ipip1.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip1 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip1 mtu" not in line
            ]

            with open("/etc/ipip1.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip1.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh2_mtu():

    priv_kh2_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip2 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip2.sh"):
        with open("/etc/ipip2.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip2 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip2 mtu" not in line
            ]

            with open("/etc/ipip2.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip2.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh3_mtu():

    priv_kh3_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip3 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip3.sh"):
        with open("/etc/ipip3.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip3 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip3 mtu" not in line
            ]

            with open("/etc/ipip3.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip3.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh4_mtu():

    priv_kh4_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip4 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip4.sh"):
        with open("/etc/ipip4.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip4 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip4 mtu" not in line
            ]

            with open("/etc/ipip4.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip4.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh5_mtu():

    priv_kh5_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip5 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip5.sh"):
        with open("/etc/ipip5.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip5 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip5 mtu" not in line
            ]

            with open("/etc/ipip5.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip5.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh6_mtu():

    priv_kh6_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip6 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip6.sh"):
        with open("/etc/ipip6.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip6 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip6 mtu" not in line
            ]

            with open("/etc/ipip6.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip6.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh7_mtu():

    priv_kh7_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip7 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip7.sh"):
        with open("/etc/ipip7.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip7 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip7 mtu" not in line
            ]

            with open("/etc/ipip7.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip7.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh8_mtu():

    priv_kh8_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip8 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip8.sh"):
        with open("/etc/ipip8.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip8 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip8 mtu" not in line
            ]

            with open("/etc/ipip8.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip8.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh9_mtu():

    priv_kh9_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip9 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip9.sh"):
        with open("/etc/ipip9.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip9 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip9 mtu" not in line
            ]

            with open("/etc/ipip9.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip9.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_kh10_mtu():

    priv_kh10_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip10 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip10.sh"):
        with open("/etc/ipip10.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip10 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip10 mtu" not in line
            ]

            with open("/etc/ipip10.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip10.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir1_mtu():

    priv_ir1_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip1 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip1.sh"):
        with open("/etc/ipip1.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip1 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip1 mtu" not in line
            ]

            with open("/etc/ipip1.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip1.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir2_mtu():

    priv_ir2_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip2 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip2.sh"):
        with open("/etc/ipip2.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip2 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip2 mtu" not in line
            ]

            with open("/etc/ipip2.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip2.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir3_mtu():

    priv_ir3_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip3 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip3.sh"):
        with open("/etc/ipip3.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip3 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip3 mtu" not in line
            ]

            with open("/etc/ipip3.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip3.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir4_mtu():

    priv_ir4_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip4 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip4.sh"):
        with open("/etc/ipip4.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip4 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip4 mtu" not in line
            ]

            with open("/etc/ipip4.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip4.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir5_mtu():

    priv_ir5_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip5 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip5.sh"):
        with open("/etc/ipip5.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip5 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip5 mtu" not in line
            ]

            with open("/etc/ipip5.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip5.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir6_mtu():

    priv_ir6_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip6 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip6.sh"):
        with open("/etc/ipip6.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip6 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip6 mtu" not in line
            ]

            with open("/etc/ipip6.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip6.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir7_mtu():

    priv_ir7_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip7 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip7.sh"):
        with open("/etc/ipip7.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip7 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip7 mtu" not in line
            ]

            with open("/etc/ipip7.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip7.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir8_mtu():

    priv_ir8_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip8 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip8.sh"):
        with open("/etc/ipip8.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip8 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip8 mtu" not in line
            ]

            with open("/etc/ipip8.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip8.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir9_mtu():

    priv_ir9_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip9 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip9.sh"):
        with open("/etc/ipip9.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip9 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip9 mtu" not in line
            ]

            with open("/etc/ipip9.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip9.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_ir10_mtu():

    priv_ir10_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip10 mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip10.sh"):
        with open("/etc/ipip10.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumip10 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumip10 mtu" not in line
            ]

            with open("/etc/ipip10.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/ipip10.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh1_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"

    if os.path.exists("/etc/private1.sh"):
        with open("/etc/private1.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi1 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi1 mtu" not in line
            ]

            with open("/etc/private1.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private1.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh2_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"

    if os.path.exists("/etc/private2.sh"):
        with open("/etc/private2.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi2 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi2 mtu" not in line
            ]

            with open("/etc/private2.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private2.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh3_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"

    if os.path.exists("/etc/private3.sh"):
        with open("/etc/private3.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi3 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi3 mtu" not in line
            ]

            with open("/etc/private3.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private3.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh4_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"

    if os.path.exists("/etc/private4.sh"):
        with open("/etc/private4.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi4 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi4 mtu" not in line
            ]

            with open("/etc/private4.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private4.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh5_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"

    if os.path.exists("/etc/private5.sh"):
        with open("/etc/private5.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi5 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi5 mtu" not in line
            ]

            with open("/etc/private5.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private5.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh6_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 6\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"

    if os.path.exists("/etc/private6.sh"):
        with open("/etc/private6.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi6 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi6 mtu" not in line
            ]

            with open("/etc/private6.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private6.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh7_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 7\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"

    if os.path.exists("/etc/private7.sh"):
        with open("/etc/private7.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi7 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi7 mtu" not in line
            ]

            with open("/etc/private7.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private7.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh8_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 8\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"

    if os.path.exists("/etc/private8.sh"):
        with open("/etc/private8.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi8 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi8 mtu" not in line
            ]

            with open("/etc/private8.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private8.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh9_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 9\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"

    if os.path.exists("/etc/private9.sh"):
        with open("/etc/private9.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi9 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi9 mtu" not in line
            ]

            with open("/etc/private9.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private9.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_kh10_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 10\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"

    if os.path.exists("/etc/private10.sh"):
        with open("/etc/private10.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi10 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi10 mtu" not in line
            ]

            with open("/etc/private10.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private10.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


# iran mtu private
def priv_ir1_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 1\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi1 mtu {mtu_value}\n"

    if os.path.exists("/etc/private1.sh"):
        with open("/etc/private1.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi1 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi1 mtu" not in line
            ]

            with open("/etc/private1.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private1.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir2_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 2\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi2 mtu {mtu_value}\n"

    if os.path.exists("/etc/private2.sh"):
        with open("/etc/private2.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi2 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi2 mtu" not in line
            ]

            with open("/etc/private2.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private2.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir3_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 3\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi3 mtu {mtu_value}\n"

    if os.path.exists("/etc/private3.sh"):
        with open("/etc/private3.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi3 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi3 mtu" not in line
            ]

            with open("/etc/private3.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private3.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir4_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 4\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi4 mtu {mtu_value}\n"

    if os.path.exists("/etc/private4.sh"):
        with open("/etc/private4.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi4 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi4 mtu" not in line
            ]

            with open("/etc/private4.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private4.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir5_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 5\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi5 mtu {mtu_value}\n"

    if os.path.exists("/etc/private5.sh"):
        with open("/etc/private5.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi5 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi5 mtu" not in line
            ]

            with open("/etc/private5.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private5.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir6_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 6\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"

    if os.path.exists("/etc/private6.sh"):
        with open("/etc/private6.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi6 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi6 mtu" not in line
            ]

            with open("/etc/private6.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private6.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir7_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 7\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi7 mtu {mtu_value}\n"

    if os.path.exists("/etc/private7.sh"):
        with open("/etc/private7.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi7 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi7 mtu" not in line
            ]

            with open("/etc/private7.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private7.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir8_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 8\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi8 mtu {mtu_value}\n"

    if os.path.exists("/etc/private8.sh"):
        with open("/etc/private8.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi8 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi8 mtu" not in line
            ]

            with open("/etc/private8.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private8.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir9_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 9\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi9 mtu {mtu_value}\n"

    if os.path.exists("/etc/private9.sh"):
        with open("/etc/private9.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi9 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi9 mtu" not in line
            ]

            with open("/etc/private9.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private9.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def priv_ir10_mtu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m             Server 10\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi10 mtu {mtu_value}\n"

    if os.path.exists("/etc/private10.sh"):
        with open("/etc/private10.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi10 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi10 mtu" not in line
            ]

            with open("/etc/private10.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/private10.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")

## gre6 mtu Kharej
def gre6_kh1_mtu():
    priv_kh1_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre61.sh"):
        with open("/etc/gre61.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig61 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig61 mtu" not in line
            ]

            with open("/etc/gre61.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre61.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh2_mtu():
    priv_kh2_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre62.sh"):
        with open("/etc/gre62.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig62 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig62 mtu" not in line
            ]

            with open("/etc/gre62.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre62.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh3_mtu():
    priv_kh3_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre63.sh"):
        with open("/etc/gre63.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig63 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig63 mtu" not in line
            ]

            with open("/etc/gre63.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre63.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh4_mtu():
    priv_kh4_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre64.sh"):
        with open("/etc/gre64.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig64 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig64 mtu" not in line
            ]

            with open("/etc/gre64.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre64.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh5_mtu():
    priv_kh5_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre65.sh"):
        with open("/etc/gre65.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig65 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig65 mtu" not in line
            ]

            with open("/etc/gre65.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre65.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh6_mtu():
    priv_kh6_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre66.sh"):
        with open("/etc/gre66.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig66 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig66 mtu" not in line
            ]

            with open("/etc/gre66.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre66.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh7_mtu():
    priv_kh7_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre67.sh"):
        with open("/etc/gre67.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig67 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig67 mtu" not in line
            ]

            with open("/etc/gre67.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre67.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh8_mtu():
    priv_kh8_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre68.sh"):
        with open("/etc/gre68.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig68 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig68 mtu" not in line
            ]

            with open("/etc/gre68.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre68.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh9_mtu():
    priv_kh9_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre69.sh"):
        with open("/etc/gre69.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig69 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig69 mtu" not in line
            ]

            with open("/etc/gre69.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre69.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh10_mtu():
    priv_kh10_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre610.sh"):
        with open("/etc/gre610.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig610 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig610 mtu" not in line
            ]

            with open("/etc/gre610.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre610.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


##gre6 mtu iran
def gre6_ir1_mtu():
    priv_ir1_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre61.sh"):
        with open("/etc/gre61.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig61 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig61 mtu" not in line
            ]

            with open("/etc/gre61.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre61.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir2_mtu():
    priv_ir2_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre62.sh"):
        with open("/etc/gre62.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig62 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig62 mtu" not in line
            ]

            with open("/etc/gre62.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre62.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir3_mtu():
    priv_ir3_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre63.sh"):
        with open("/etc/gre63.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig63 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig63 mtu" not in line
            ]

            with open("/etc/gre63.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre63.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir4_mtu():
    priv_ir4_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre64.sh"):
        with open("/etc/gre64.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig64 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig64 mtu" not in line
            ]

            with open("/etc/gre64.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre64.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir5_mtu():
    priv_ir5_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre65.sh"):
        with open("/etc/gre65.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig65 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig65 mtu" not in line
            ]

            with open("/etc/gre65.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre65.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir6_mtu():
    priv_ir6_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre66.sh"):
        with open("/etc/gre66.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig66 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig66 mtu" not in line
            ]

            with open("/etc/gre66.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre66.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir7_mtu():
    priv_ir7_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre67.sh"):
        with open("/etc/gre67.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig67 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig67 mtu" not in line
            ]

            with open("/etc/gre67.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre67.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir8_mtu():
    priv_ir8_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre68.sh"):
        with open("/etc/gre68.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig68 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig68 mtu" not in line
            ]

            with open("/etc/gre68.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre68.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir9_mtu():
    priv_ir9_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre69.sh"):
        with open("/etc/gre69.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig69 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig69 mtu" not in line
            ]

            with open("/etc/gre69.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre69.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir10_mtu():
    priv_ir10_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre610.sh"):
        with open("/etc/gre610.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig610 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig610 mtu" not in line
            ]

            with open("/etc/gre610.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre610.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


# gretapnative


def gre6_kh1tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre61.sh"):
        with open("/etc/gre61.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig61 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig61 mtu" not in line
            ]

            with open("/etc/gre61.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre61.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh2tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre62.sh"):
        with open("/etc/gre62.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig62 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig62 mtu" not in line
            ]

            with open("/etc/gre62.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre62.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh3tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre63.sh"):
        with open("/etc/gre63.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig63 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig63 mtu" not in line
            ]

            with open("/etc/gre63.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre63.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh4tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre64.sh"):
        with open("/etc/gre64.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig64 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig64 mtu" not in line
            ]

            with open("/etc/gre64.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre64.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh5tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre65.sh"):
        with open("/etc/gre65.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig65 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig65 mtu" not in line
            ]

            with open("/etc/gre65.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre65.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh6tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre66.sh"):
        with open("/etc/gre66.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig66 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig66 mtu" not in line
            ]

            with open("/etc/gre66.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre66.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh7tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre67.sh"):
        with open("/etc/gre67.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig67 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig67 mtu" not in line
            ]

            with open("/etc/gre67.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre67.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh8tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre68.sh"):
        with open("/etc/gre68.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig68 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig68 mtu" not in line
            ]

            with open("/etc/gre68.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre68.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh9tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre69.sh"):
        with open("/etc/gre69.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig69 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig69 mtu" not in line
            ]

            with open("/etc/gre69.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre69.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_kh10tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre610.sh"):
        with open("/etc/gre610.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig610 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig610 mtu" not in line
            ]

            with open("/etc/gre610.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre610.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


##gre6 mtu iran
def gre6_ir1tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig61 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre61.sh"):
        with open("/etc/gre61.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig61 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig61 mtu" not in line
            ]

            with open("/etc/gre61.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre61.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir2tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig62 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre62.sh"):
        with open("/etc/gre62.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig62 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig62 mtu" not in line
            ]

            with open("/etc/gre62.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre62.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir3tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig63 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre63.sh"):
        with open("/etc/gre63.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig63 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig63 mtu" not in line
            ]

            with open("/etc/gre63.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre63.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir4tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig64 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre64.sh"):
        with open("/etc/gre64.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig64 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig64 mtu" not in line
            ]

            with open("/etc/gre64.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre64.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir5tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig65 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre65.sh"):
        with open("/etc/gre65.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig65 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig65 mtu" not in line
            ]

            with open("/etc/gre65.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre65.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir6tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig66 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre66.sh"):
        with open("/etc/gre66.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig66 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig66 mtu" not in line
            ]

            with open("/etc/gre66.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre66.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir7tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig67 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre67.sh"):
        with open("/etc/gre67.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig67 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig67 mtu" not in line
            ]

            with open("/etc/gre67.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre67.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir8tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig68 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre68.sh"):
        with open("/etc/gre68.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig68 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig68 mtu" not in line
            ]

            with open("/etc/gre68.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre68.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir9tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig69 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre69.sh"):
        with open("/etc/gre69.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig69 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig69 mtu" not in line
            ]

            with open("/etc/gre69.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre69.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_ir10tap_mtu():

    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig610 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre610.sh"):
        with open("/etc/gre610.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumig610 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumig610 mtu" not in line
            ]

            with open("/etc/gre610.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/gre610.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


##
def i6to4any2_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96m6to4 anycast \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumi6 mtu {mtu_value}\n"

    if os.path.exists("/etc/6to4.sh"):
        with open("/etc/6to4.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumi6 mtu" in line for line in sh_contents):
            sh_contents = [
                line for line in sh_contents if "link set dev azumi6 mtu" not in line
            ]

            with open("/etc/6to4.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/etc/6to4.sh", "a") as file:
            file.write(mtu_command)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


## original mtu
def mtu_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mEdit MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mPrivate IP\033[0m")
    print("2. \033[93mIP6IP6 \033[0m")
    print("3. \033[96mGRE \033[0m")
    print("4. \033[92mGRE6 \033[0m")
    print("5. \033[92mGRE6tap \033[0m")
    print("6. \033[93m6to4 \033[0m")
    print("7. \033[96m6to4 anycast \033[0m")
    print("8. \033[92mGeneve \033[0m")
    print("9. \033[93mErspan \033[0m")
    print("10. \033[92mVxlan [IPsec too] \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_mtu()
            break
        elif server_type == "2":
            ipip_mtu()
            break
        elif server_type == "3":
            gre_mtu()
            break
        elif server_type == "4":
            gre6_mtu()
            break
        elif server_type == "5":
            gre6tap_mtu()
            break
        elif server_type == "6":
            i6to4_mtu()
            break
        elif server_type == "7":
            i6to4any_mtu()
            break
        elif server_type == "8":
            gen_mtu()
            break
        elif server_type == "9":
            erspan_mtu()
            break
        elif server_type == "10":
            vxlan_mtu()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def erspan_mtu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mErspan MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan\033[0m")
    print("2. \033[97mErspan + Native\033[0m")
    print("3. \033[93mGRE6 + IPV4 Erspan  \033[0m")
    print("4. \033[96mGRE6 + Native Erspan \033[0m")
    print("5. \033[93mGRE6tap + IPV4 Erspan  \033[0m")
    print("6. \033[96mGRE6tap + Native Erspan \033[0m")
    print("7. \033[92mIPsec Tunnels \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn1_mtu()
            break
        elif server_type == "2":
            spn1_mtu()
            break
        elif server_type == "3":
            spn3_mtu()
            break
        elif server_type == "4":
            spn4_mtu()
            break
        elif server_type == "5":
            spn5_mtu()
            break
        elif server_type == "6":
            spn6_mtu()
            break
        elif server_type == "7":
            spn7_mtu()
            break
        elif server_type == "0":
            clear()
            mtu_menu()
            break
        else:
            print("Invalid choice.")


def spn7_mtu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mErspan + IPsec MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + IPsec\033[0m")
    print("2. \033[97mErspan + GRE6 IPV4\033[0m")
    print("3. \033[93mErspan + GRE6 Native  \033[0m")
    print("4. \033[96mErspan + GRE6tap IPV4 \033[0m")
    print("5. \033[92mErspan + GRE6tap Native \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            spn1_mtu()
            break
        elif server_type == "2":
            spn3_mtu()
            break
        elif server_type == "3":
            spn4_mtu()
            break
        elif server_type == "4":
            spn5_mtu()
            break
        elif server_type == "5":
            spn6_mtu()
            break
        elif server_type == "0":
            clear()
            erspan_mtu()
            break
        else:
            print("Invalid choice.")


def gre6tap21_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6tap \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre6.sh"):
        with open("/etc/gre6.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumig6 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/gre6.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6tap_mtu():
    private_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6tap \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre6.sh"):
        with open("/etc/gre6.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumig6 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/gre6.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def spn1_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mErspan \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"

    if os.path.exists("/etc/spn.sh"):
        with open("/etc/spn.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumiespn mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/spn.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def spn3_mtu():
    private_mtu()
    gre621_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mErspan \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"

    if os.path.exists("/etc/spn.sh"):
        with open("/etc/spn.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumiespn mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/spn.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def spn4_mtu():
    gre621_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mErspan \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"

    if os.path.exists("/etc/spn.sh"):
        with open("/etc/spn.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumiespn mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/spn.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def spn5_mtu():

    gre6tap_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mErspan \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"

    if os.path.exists("/etc/spn.sh"):
        with open("/etc/spn.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumiespn mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/spn.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def spn6_mtu():
    private_mtu()
    gre6tap21_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mErspan \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"

    if os.path.exists("/etc/spn.sh"):
        with open("/etc/spn.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumiespn mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/spn.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen_mtu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGENEVE MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGENEVE\033[0m")
    print("2. \033[97mGENEVE + Native\033[0m")
    print("3. \033[93mGRE6 + IPV4 GENEVE  \033[0m")
    print("4. \033[96mGRE6 + Native GENEVE \033[0m")
    print("5. \033[92mGENEVE + IP6tnl + GRE6 \033[0m")
    print("0. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen1_mtu()
            break
        elif server_type == "2":
            gen1_mtu()
            break
        elif server_type == "3":
            gen4_mtu()
            break
        elif server_type == "4":
            gen2_mtu()
            break
        elif server_type == "5":
            gen3_mtu()
            break
        elif server_type == "0":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


def gen4_mtu():
    private_mtu()
    gre621_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"

    if os.path.exists("/etc/sys.sh"):
        with open("/etc/sys.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen1_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"

    if os.path.exists("/etc/sys.sh"):
        with open("/etc/sys.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen2_mtu():
    gre621_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"

    if os.path.exists("/etc/sys.sh"):
        with open("/etc/sys.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gen3_mtu():
    private2_mtu()
    gre621_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGeneve \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"

    if os.path.exists("/etc/sys.sh"):
        with open("/etc/sys.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumigen mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/sys.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def private2_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[\033[96mIP6tnl\033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"

    if os.path.exists("/etc/private.sh"):
        with open("/etc/private.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumi mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/private.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def private_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mPrivate IP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"

    if os.path.exists("/etc/private.sh"):
        with open("/etc/private.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumi mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/private.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre621_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre6.sh"):
        with open("/etc/gre6.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumig6 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/gre6.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre6_mtu():
    private_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE6 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"

    if os.path.exists("/etc/gre6.sh"):
        with open("/etc/gre6.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumig6 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/gre6.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def gre_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mGRE \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumig mtu {mtu_value}\n"

    if os.path.exists("/etc/gre.sh"):
        with open("/etc/gre.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumig mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/gre.sh", "w") as file:
            file.writelines(sh_contents)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def i6to4_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96m6to4 \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumi6 mtu {mtu_value}\n"

    if os.path.exists("/etc/6to4.sh"):
        with open("/etc/6to4.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumi6 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/6to4.sh", "w") as file:
            file.writelines(sh_contents)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def i6to4any_mtu():
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96m6to4 anycast \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumi6 mtu {mtu_value}\n"

    if os.path.exists("/etc/6to4.sh"):
        with open("/etc/6to4.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumi6 mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/6to4.sh", "w") as file:
            file.writelines(sh_contents)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ipip_mtu():
    private_mtu()
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mIP6IP6 \033[93m]:\033[0m "
    )
    mtu_command = f"/sbin/ip -6 link set dev azumip mtu {mtu_value}\n"

    if os.path.exists("/etc/ipip.sh"):
        with open("/etc/ipip.sh", "r") as file:
            sh_contents = file.readlines()

        mtu_exists = False
        for i in range(len(sh_contents)):
            if "link set dev azumip mtu" in sh_contents[i]:
                sh_contents[i] = mtu_command
                mtu_exists = True
                break

        if not mtu_exists:
            sh_contents.append(mtu_command)

        with open("/etc/ipip.sh", "w") as file:
            file.writelines(sh_contents)

        display_checkmark("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def ip_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIPIP Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("3. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_ip_menu()
            break
        elif server_type == "2":
            iran_ip_menu()
            break
        elif server_type == "3":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


def ip_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip.service"])
    subprocess.run(["systemctl", "start", "ping_ip.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip.service"])


def ip_ping_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ip_iran():
    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    sleep(1)

    ip_address = remote_prefix
    max_pings = 3
    interval = 2
    ip_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()

    print(ping_result)

    ip_service()

    print("\033[92mIPIP6 Configuration Completed!\033[0m")


def ip_kharej():
    remote_ipv4 = input(
        "\033[93mEnter \033[92mIran IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    sleep(1)

    ip_address = remote_prefix
    max_pings = 3
    interval = 2
    ip_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()

    print(ping_result)

    ip_service()

    print("\033[92mIPIP6 Configuration Completed!\033[0m")


# isata
# import os
import re
import subprocess
import time
import sys


def ipsec_statuscheck(service_name):
    try:
        status = (
            subprocess.check_output(f"systemctl is-active {service_name}", shell=True)
            .decode("utf-8")
            .strip()
        )
        return status == "active"
    except subprocess.CalledProcessError:
        return False


def check_global(interface):
    try:
        output = subprocess.check_output(
            f"ip -6 addr show {interface}", shell=True
        ).decode("utf-8")
        inet6_addresses = re.findall(
            r"inet6 (2001:db8::5efe:[\da-fA-F:]+)/64 scope global", output
        )
        return inet6_addresses if inet6_addresses else None
    except subprocess.CalledProcessError:
        return None


def isatap_status():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mISATAP Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭─────────────────────────────────────────────────╮\033[0m")
    print("\033[93mYou are viewing the status of your current tunnel:\033[0m")
    print("\033[93m────────────────────────────────────────\033[0m")

    interfaces = ["azumiserver", "azumiclient"]
    active_int = []
    for interface in interfaces:
        if interface_ex(interface):
            status = interface_check(interface)
            if status:
                active_int.append(interface)

    if not active_int:
        print(" No Interfaces available.")
    elif "azumiserver" in active_int:
        with open("/etc/port.sh", "r") as file:
            contents = file.read()

        print(
            " \033[97mServer \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumiserver\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mISATAP\033[0m")

        ipsec_status = ipsec_statuscheck("strong-azumi1")
        if ipsec_status:
            print(" \033[93mIPsec Status: \033[92mActive\033[0m")
        else:
            print(" \033[93mIPsec Status: \033[91mInactive\033[0m")
        print("\033[93m────────────────────────────────────────\033[0m")
        inet6_addresses = check_global("azumiserver")
        if inet6_addresses:
            for addr in inet6_addresses:
                print(f" \033[93mPrivate IPV6 address: \033[97m{addr}\033[0m")
        else:
            print(" \033[91mServer has no IPV6 address\033[0m")

        remote_ips = re.findall(r"REMOTE_IPV4_(\d+)=(\S+)", contents)
        if remote_ips:
            for idx, ip in remote_ips:
                print(f" \033[93mClient IP \033[96m{idx}\033[93m: \033[97m{ip}\033[0m")
        else:
            print(" \033[91mNo remote IP found\033[0m")

    elif "azumiclient" in active_int:
        with open("/etc/port.sh", "r") as file:
            contents = file.read()

        client_displayed = False
        for i in range(1, 6):
            server_file = f"/etc/server{i}.sh"
            if os.path.exists(server_file):
                print(
                    f" \033[97mClient \033[96m{i}\033[93m Status: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumiclient\033[0m"
                )
                client_displayed = True

        if not client_displayed:
            print(
                " \033[97mClient\033[93m Status: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumiclient\033[0m"
            )

        print(" \033[93mTunnel Method: \033[97mISATAP\033[0m")

        ipsec_status = ipsec_statuscheck("strong-azumi1")
        if ipsec_status:
            print(" \033[93mIPsec Status: \033[92mActive\033[0m")
        else:
            print(" \033[93mIPsec Status: \033[91mInactive\033[0m")
        print("\033[93m────────────────────────────────────────\033[0m")
        inet6_addresses = check_global("azumiclient")
        if inet6_addresses:
            for addr in inet6_addresses:
                print(f" \033[93mPrivate IPV6 address: \033[97m{addr}\033[0m")
        else:
            print(" \033[91mClient has no IPV6 address\033[0m")

        remote_ips = re.findall(r"REMOTE_IPV4=(\S+)", contents)
        if remote_ips:
            for ip in remote_ips:
                print(f" \033[93mServer IP : \033[97m{ip}\033[0m")
        else:
            print(" \033[91mNo remote IP found\033[0m")

    print("\033[93m────────────────────────────────────────\033[0m")
    secret_key = ipsec_secret()
    if secret_key != "Not found":
        print(" \033[93mIPsec Secret Key:\033[96m", secret_key, "\033[0m")
    else:
        print(" \033[93mIPSEC is not available\033[0m")
    print("\033[93m─────────────────────────────────────────────────\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰─────────────────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "0":
            os.system("clear")
            isatap_mnu()
            break
        else:
            print("Invalid choice.")


def isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("0. \033[91mISATAP STATUS\033[0m")
    print("1. \033[93mServer : Kharej | Client : IRAN\033[0m")
    print("2. \033[92mServer : IRAN   | Client : Kharej\033[0m")
    print("3. \033[96mEdit MTU\033[0m")
    print("4. \033[93mEdit Servers\033[0m")
    print("5. \033[91mUninstall\033[0m")
    print("0. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "0":
            isatap_status()
            break
        elif choice == "1":
            server_isatap_mnu()
            break
        elif choice == "2":
            client_isatap_mnu()
            break
        elif choice == "3":
            isatap_mtu_menu()
            break
        elif choice == "4":
            isatap_edit_server2()
            break
        elif choice == "5":
            isatap_remove_menu()
            break
        elif choice == "0":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


def isatap_edit_server2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Edit Server Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mServer : Kharej | Client : IRAN\033[0m")
    print("2  \033[92mServer : IRAN   | Client : Kharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            server_isatap_editmnu()
            break
        elif choice == "2":
            client_isatap_editmnu()
            break
        elif choice == "0":
            clear()
            isatap_mnu()
            break
        else:
            print("Invalid choice.")


def server_isatap_editmnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : Kharej | Client : IRAN | ISATAP\033[93m Edit Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mWhich one to edit:\033[0m")
    print("1.  \033[92m Kharej Server [1]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("2.  \033[93m IRAN Client [1]\033[0m")
    print("3.  \033[93m IRAN Client [2]\033[0m")
    print("4.  \033[93m IRAN Client [3]\033[0m")
    print("5.  \033[93m IRAN Client [4]\033[0m")
    print("6.  \033[93m IRAN Client [5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            server_isatap_rmvmnu()
            kharej1server_isatap_mnu()
            break
        elif choice == "2":
            client_isatap_rmvmnu()
            iranclient1_isatap_mnu()
            break
        elif choice == "3":
            client_isatap_rmvmnu()
            iranclient2_isatap_mnu()
            break
        elif choice == "4":
            client_isatap_rmvmnu()
            iranclient3_isatap_mnu()
            break
        elif choice == "5":
            client_isatap_rmvmnu()
            iranclient4_isatap_mnu()
            break
        elif choice == "6":
            client_isatap_rmvmnu()
            iranclient5_isatap_mnu()
            break
        elif choice == "0":
            clear()
            isatap_edit_server2()
            break
        else:
            print("Invalid choice.")


def client_isatap_editmnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : Kharej | Client : IRAN | ISATAP\033[93m Edit Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mWhich one to edit:\033[0m")
    print("1.  \033[92m IRAN Server [1]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("2.  \033[93m Kharej Client [1]\033[0m")
    print("3.  \033[93m Kharej Client [2]\033[0m")
    print("4.  \033[93m Kharej Client [3]\033[0m")
    print("5.  \033[93m Kharej Client [4]\033[0m")
    print("6.  \033[93m Kharej Client [5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            server_isatap_rmvmnu()
            iran1server_isatap_mnu()
            break
        elif choice == "2":
            client_isatap_rmvmnu()
            kharejclient1_isatap_mnu()
            break
        elif choice == "3":
            client_isatap_rmvmnu()
            kharejclient2_isatap_mnu()
            break
        elif choice == "4":
            client_isatap_rmvmnu()
            kharejclient3_isatap_mnu()
            break
        elif choice == "5":
            client_isatap_rmvmnu()
            kharejclient4_isatap_mnu()
            break
        elif choice == "6":
            client_isatap_rmvmnu()
            kharejclient5_isatap_mnu()
            break
        elif choice == "0":
            clear()
            isatap_edit_server2()
            break
        else:
            print("Invalid choice.")


def isatap_mtu_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m MTU Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mServer : Kharej | Client : IRAN\033[0m")
    print("2  \033[92mServer : IRAN   | Client : Kharej\033[0m")
    print("0. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            server_isatap_mtumnu()
            break
        elif choice == "2":
            client_isatap_mtumnu()
            break
        elif choice == "0":
            clear()
            isatap_mnu()
            break
        else:
            print("Invalid choice.")


def client_isatap_mtumnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : IRAN | Client : Kharej | MTU\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1.  \033[92m IRAN Server [1]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("2.  \033[93m Kharej Client [1]\033[0m")
    print("3.  \033[93m Kharej Client [2]\033[0m")
    print("4.  \033[93m Kharej Client [3]\033[0m")
    print("5.  \033[93m Kharej Client [4]\033[0m")
    print("6.  \033[93m Kharej Client [5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            kharej1server_mtuisa_mnu()
            break
        elif choice == "2":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "3":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "4":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "5":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "6":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "0":
            clear()
            isatap_mtu_menu()
            break
        else:
            print("Invalid choice.")


def server_isatap_mtumnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : Kharej | Client : IRAN | MTU\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1.  \033[92m Kharej Server [1]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("2.  \033[93m IRAN Client [1]\033[0m")
    print("3.  \033[93m IRAN Client [2]\033[0m")
    print("4.  \033[93m IRAN Client [3]\033[0m")
    print("5.  \033[93m IRAN Client [4]\033[0m")
    print("6.  \033[93m IRAN Client [5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            kharej1server_mtuisa_mnu()
            break
        elif choice == "2":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "3":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "4":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "5":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "6":
            iranclient1_mtuisa_mnu()
            break
        elif choice == "0":
            clear()
            isatap_mtu_menu()
            break
        else:
            print("Invalid choice.")


def kharej1server_mtuisa_mnu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m              Server \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mISATAP\033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumiserver mtu {mtu_value}\n"

    if os.path.exists("/usr/local/bin/isatap.sh"):
        with open("/usr/local/bin/isatap.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumiserver mtu" in line for line in sh_contents):
            sh_contents = [
                line
                for line in sh_contents
                if "link set dev azumiserver mtu" not in line
            ]

            with open("/usr/local/bin/isatap.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/usr/local/bin/isatap.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def iranclient1_mtuisa_mnu():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93m              Client \033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    mtu_value = input(
        "\033[93mEnter the \033[92mMTU value \033[93m[ \033[96mISATAP \033[93m]:\033[0m "
    )
    mtu_command = f"ip link set dev azumiclient mtu {mtu_value}\n"

    if os.path.exists("/usr/local/bin/isatap.sh"):
        with open("/usr/local/bin/isatap.sh", "r") as file:
            sh_contents = file.readlines()

        if any("link set dev azumiclient mtu" in line for line in sh_contents):
            sh_contents = [
                line
                for line in sh_contents
                if "link set dev azumiclient mtu" not in line
            ]

            with open("/usr/local/bin/isatap.sh", "w") as file:
                file.writelines(sh_contents)

        with open("/usr/local/bin/isatap.sh", "a") as file:
            file.write(mtu_command)

        print("\033[92mMTU command edited successfully\033[0m")
        subprocess.run(mtu_command, shell=True)
    else:
        print("\033[91mCommand file doesn't exist\033[0m")


def isatap_remove_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Remove Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mServer\033[0m")
    print("2  \033[92mClient\033[0m")
    print("0. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            server_isatap_rmvmnu()
            break
        elif choice == "2":
            client_isatap_rmvmnu()
            break
        elif choice == "0":
            clear()
            isatap_mnu()
            break
        else:
            print("Invalid choice.")


def client_isatap_rmvmnu():
    delete_cron3()
    delete_cron4()
    ipsec_service_remove()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving ISATAP + \033[92mIpsec \033[93mClient\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving cronjob & other stuff...\033[0m")

        commands = [
            'crontab -l | grep -v "@reboot /bin/bash /usr/local/bin/isatap.sh" | crontab -',
            "sudo rm /etc/ipsec1.conf",
            "sudo rm /etc/ipsec2.sh",
            "sudo rm /etc/server1.sh",
            "sudo rm /etc/server2.sh",
            "sudo rm /etc/server3.sh",
            "sudo rm /etc/server4.sh",
            "sudo rm /etc/server5.sh",
            "sudo rm /usr/local/bin/ping_keepalive.sh",
            "sudo rm /etc/ipsec.secrets",
            "sudo rm /usr/bin/local/isatap.sh",
            "sudo rm /etc/resetbasedonping1.sh",
            "systemctl disable azumireset1",
            "systemctl stop azumireset1",
            "sudo rm /etc/systemd/system/azumireset1.service",
            "systemctl disable isatapreset",
            "systemctl stop isatapreset",
            "sudo rm /etc/systemd/system/isatapreset.service",
            "sudo rm /etc/reset_isatap.sh",
            "sudo rm /usr/local/bin/isatap_daemon.sh",
            "systemctl disable isa",
            "systemctl stop isa",
            "sudo rm /etc/systemd/system/isa.service",
            "systemctl disable radvd",
            "systemctl stop radvd",
            "systemctl disable strong-azumi1",
            "systemctl stop strong-azumi1",
            "sudo rm /etc/systemd/system/strong-azumi1.service",
            "ip link set dev azumiclient down",
            "ip link delete azumiclient",
            "ip link delete sit0",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        hide("apt purge strongswan -y")
        hide("apt purge radvd -y")

        ports = []
        if os.path.exists("/etc/port.sh"):
            with open("/etc/port.sh", "r") as f:
                content = f.read().strip()
                for line in content.split("\n"):
                    if line.startswith("PORT="):
                        ports.append(line.split("=")[1])

        for port in ports:
            subprocess.run(f"sudo ufw delete allow {port}", shell=True)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def server_isatap_rmvmnu():
    delete_cron3()
    delete_cron4()
    ipsec_service_remove()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving ISATAP + \033[92mIpsec \033[93mServer\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        display_notification("\033[93mRemoving cronjob & other stuff...\033[0m")

        commands = [
            'crontab -l | grep -v "@reboot /bin/bash /usr/local/bin/isatap.sh" | crontab -',
            "sudo rm /etc/ipsec1.conf",
            "sudo rm /etc/ipsec2.sh",
            "sudo rm /etc/server1.sh",
            "sudo rm /usr/local/bin/ping_keepalive.sh",
            "sudo rm /usr/local/bin/ping_keepalive_1.sh",
            "sudo rm /usr/local/bin/ping_keepalive_2.sh",
            "sudo rm /usr/local/bin/ping_keepalive_3.sh",
            "sudo rm /usr/local/bin/ping_keepalive_4.sh",
            "sudo rm /usr/local/bin/ping_keepalive_5.sh",
            "sudo rm /etc/ipsec.secrets",
            "sudo rm /usr/bin/local/isatap.sh",
            "sudo rm /etc/resetbasedonping1.sh",
            "systemctl disable azumireset1",
            "systemctl stop azumireset1",
            "sudo rm /etc/systemd/system/azumireset1.service",
            "systemctl disable isatapreset",
            "systemctl stop isatapreset",
            "sudo rm /etc/systemd/system/isatapreset.service",
            "sudo rm /etc/reset_isatap.sh",
            "sudo rm /usr/local/bin/isatap_daemon.sh",
            "systemctl disable isa_1",
            "systemctl stop isa_1",
            "sudo rm /etc/systemd/system/isa_1.service",
            "systemctl disable isa_2",
            "systemctl stop isa_2",
            "sudo rm /etc/systemd/system/isa_2.service",
            "systemctl disable isa_3",
            "systemctl stop isa_3",
            "sudo rm /etc/systemd/system/isa_3.service",
            "systemctl disable isa_4",
            "systemctl stop isa_4",
            "sudo rm /etc/systemd/system/isa_4.service",
            "systemctl disable isa_5",
            "systemctl stop isa_5",
            "sudo rm /etc/systemd/system/isa_5.service",
            "systemctl disable radvd",
            "systemctl stop radvd",
            "systemctl disable strong-azumi1",
            "systemctl stop strong-azumi1",
            "sudo rm /etc/systemd/system/strong-azumi1.service",
            "ip link set dev azumiserver down",
            "ip link delete azumiserver",
            "ip link delete sit0",
            "systemctl daemon-reload",
        ]

        for command in commands:
            subprocess.run(command, shell=True, stdout=devnull, stderr=devnull)

        hide("apt purge strongswan -y")
        hide("apt purge radvd -y")

        ports = []
        if os.path.exists("/etc/port.sh"):
            with open("/etc/port.sh", "r") as f:
                content = f.read().strip()
                for line in content.split("\n"):
                    if line.startswith("PORT="):
                        ports.append(line.split("=")[1])

        for port in ports:
            subprocess.run(f"sudo ufw delete allow {port}", shell=True)

        devnull.close()

        print("Progress: ", end="")
        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def server_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : Kharej | Client : IRAN | ISATAP\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93m[1] Kharej [5]IRAN\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            kharej1_isatap_mnu()
            break
        elif choice == "0":
            clear()
            isatap_mnu()
            break
        else:
            print("Invalid choice.")


def kharej1_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : Kharej | Client : IRAN | ISATAP\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1.  \033[92m Kharej Server [1]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("2.  \033[93m IRAN Client [1]\033[0m")
    print("3.  \033[93m IRAN Client [2]\033[0m")
    print("4.  \033[93m IRAN Client [3]\033[0m")
    print("5.  \033[93m IRAN Client [4]\033[0m")
    print("6.  \033[93m IRAN Client [5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            kharej1server_isatap_mnu()
            break
        elif choice == "2":
            iranclient1_isatap_mnu()
            break
        elif choice == "3":
            iranclient2_isatap_mnu()
            break
        elif choice == "4":
            iranclient3_isatap_mnu()
            break
        elif choice == "5":
            iranclient4_isatap_mnu()
            break
        elif choice == "6":
            iranclient5_isatap_mnu()
            break
        elif choice == "0":
            clear()
            server_isatap_mnu()
            break
        else:
            print("Invalid choice.")


def client_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : IRAN | Client : Client | ISATAP\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93m[1] IRAN [5]Kharej\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            iran1_isatap_mnu()
            break
        elif choice == "0":
            clear()
            isatap_mnu
            break
        else:
            print("Invalid choice.")


def iran1_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mServer : Kharej | Client : IRAN | ISATAP\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1.  \033[92m IRAN Server [1]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("2.  \033[93m Kharej Client [1]\033[0m")
    print("3.  \033[93m Kharej Client [2]\033[0m")
    print("4.  \033[93m Kharej Client [3]\033[0m")
    print("5.  \033[93m Kharej Client [4]\033[0m")
    print("6.  \033[93m Kharej Client [5]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "1":
            iran1server_isatap_mnu()
            break
        elif choice == "2":
            kharejclient1_isatap_mnu()
            break
        elif choice == "3":
            kharejclient2_isatap_mnu()
            break
        elif choice == "4":
            kharejclient3_isatap_mnu()
            break
        elif choice == "5":
            kharejclient4_isatap_mnu()
            break
        elif choice == "6":
            kharejclient5_isatap_mnu()
            break
        elif choice == "0":
            clear()
            client_isatap_mnu()
            break
        else:
            print("Invalid choice.")


def animate(message):
    for char in message:
        print(char, end="", flush=True)
        time.sleep(0.05)
    print()


def anime():
    animation = [
        "[=     ]",
        "[==    ]",
        "[===   ]",
        "[====  ]",
        "[===== ]",
        "[======]",
        "[===== ]",
        "[====  ]",
        "[===   ]",
        "[==    ]",
        "[=     ]",
    ]
    for i in range(20):
        time.sleep(0.1)
        sys.stdout.write(f"\r{animation[i % len(animation)]}")
        sys.stdout.flush()
    sys.stdout.write("\r")
    sys.stdout.flush()


def hide(command):
    process = subprocess.Popen(
        command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE
    )
    while process.poll() is None:
        anime()
    _, stderr = process.communicate()
    if process.returncode != 0:
        print(f"\033[91merror: {stderr.decode()}\033[0m")


def forward():
    with open("/proc/sys/net/ipv4/ip_forward", "r") as f:
        ipv4_forwarding = f.read().strip()

    with open("/proc/sys/net/ipv6/conf/all/forwarding", "r") as f:
        ipv6_forwarding = f.read().strip()

    if ipv4_forwarding == "0":
        display_notification("\033[93mEnabling IPv4 forwarding..\033[0m")
        os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
    else:
        print("\033[93mIPv4 forwarding is already enabled\033[0m")

    if ipv6_forwarding == "0":
        display_notification("\033[93mEnabling IPv6 forwarding..\033[0m")
        os.system("echo 1 > /proc/sys/net/ipv6/conf/all/forwarding")
    else:
        print("\033[93mIPv6 forwarding is already enabled\033[0m")


def isa_cronjob():
    try:
        subprocess.run(
            "crontab -l | grep -v '/usr/local/bin/isatap.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )
        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /usr/local/bin/isatap.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )
        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_isatap_client(local_ipv4, remote_ipv4):
    client_path = "/usr/local/bin/isatap.sh"
    mtu_command = ""
    set_mtu = input(
        "\033[93mDo you want to set MTU? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if set_mtu in ["yes", "y"]:
        mtu_value = input("\033[93mEnter the MTU value: \033[0m")
        mtu_command = f"ip link set dev azumiclient mtu {mtu_value}\n"

    script_content = f"""#!/bin/bash

ip tunnel add azumiclient mode isatap local {local_ipv4} remote {remote_ipv4} ttl 64
ip link set azumiclient up
ip addr add 2001:db8::5efe:{local_ipv4}/64 dev azumiclient
{mtu_command}
"""

    with open(client_path, "w") as file:
        file.write(script_content)

    subprocess.run(["chmod", "+x", client_path], check=True)
    subprocess.run(["bash", client_path], check=True)


def create_isatap_server(local_ipv4):
    server_path = "/usr/local/bin/isatap.sh"
    mtu_command = ""
    set_mtu = input(
        "\033[93mDo you want to set MTU? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if set_mtu in ["yes", "y"]:
        mtu_value = input("\033[93mEnter the MTU value: \033[0m")
        mtu_command = f"ip link set dev azumiserver mtu {mtu_value}\n"
    script_content = f"""#!/bin/bash

ip tunnel add azumiserver mode isatap local {local_ipv4} ttl 64
ip link set azumiserver up
ip addr add 2001:db8::5efe:{local_ipv4}/64 dev azumiserver
{mtu_command}
"""

    with open(server_path, "w") as file:
        file.write(script_content)

    subprocess.run(["chmod", "+x", server_path], check=True)
    subprocess.run(["bash", server_path], check=True)


def ping_keepalive(client_ip, client_index):
    file_path = f"/usr/local/bin/ping_keepalive_{client_index}.sh"

    script_content = f"""#!/bin/bash

ip_address="{client_ip}"

max_pings=5
interval=2

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" '{{print $2}}' | awk -F " " '{{print $1}}' | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    subprocess.run(["chmod", "+x", file_path], check=True)


def ping_keepalive2(server_ipv6):
    file_path = f"/usr/local/bin/ping_keepalive.sh"

    script_content = f"""#!/bin/bash

ip_address="{server_ipv6}"

max_pings=5
interval=2

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" '{{print $2}}' | awk -F " " '{{print $1}}' | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    subprocess.run(["chmod", "+x", file_path], check=True)


def ufwport(port):
    subprocess.run(["sudo", "ufw", "allow", port])


def isa_service2():
    service_content = f"""[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /usr/local/bin/ping_keepalive.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = f"/etc/systemd/system/isa.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "isa.service"])
    subprocess.run(["systemctl", "start", "isa"])
    time.sleep(1)
    subprocess.run(["systemctl", "restart", "isa"])


def isa_service(client_index):
    service_content = f"""[Unit]
Description=keepalive_{client_index}
After=network.target

[Service]
ExecStart=/bin/bash /usr/local/bin/ping_keepalive_{client_index}.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = f"/etc/systemd/system/isa_{client_index}.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", f"isa_{client_index}.service"])
    subprocess.run(["systemctl", "start", f"isa_{client_index}"])
    time.sleep(1)
    subprocess.run(["systemctl", "restart", f"isa_{client_index}"])


def isatap_client(local_ipv4, remote_ipv4):
    os.system(
        f"ip tunnel add azumiclient mode isatap local {local_ipv4} remote {remote_ipv4} ttl 64"
    )
    os.system("ip link set azumiclient up")
    os.system(f"ip addr add 2001:db8::5efe:{local_ipv4}/64 dev azumiclient")


def isatap_server(local_ipv4):
    os.system(f"ip tunnel add azumiserver mode isatap local {local_ipv4} ttl 64")
    os.system("ip link set azumiserver up")
    os.system(f"ip addr add 2001:db8::5efe:{local_ipv4}/64 dev azumiserver")


def install_radvd():
    animate("\033[93mInstalling rad..\033[0m")
    hide("sudo apt-get install radvd -y")
    animate("\033[92mInstallation was successful!\033[0m")

    radvd_config = """interface azumiserver {
    AdvSendAdvert on;
    UnicastOnly on;
    AdvHomeAgentFlag off;

    prefix 2001:db8::/64 {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr off;
    };
};"""

    with open("/etc/radvd.conf", "w") as f:
        f.write(radvd_config)
    hide("systemctl daemon-reload")
    hide("systemctl enable radvd")
    hide("systemctl restart radvd")


def install_ipvsadm():
    animate("\033[93mInstalling ip..\033[0m")
    hide("sudo apt-get install ipvsadm -y")
    animate("\033[92mInstallation was successful!\033[0m")


def isaaddress(name):
    result = subprocess.run(
        ["ip", "-6", "addr", "show", name],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    if result.returncode != 0:
        return None

    output = result.stdout.decode()
    for line in output.splitlines():
        if "inet6" in line and "scope global" in line:
            return line.split()[1].split("/")[0]
    return None


def service_exists(service_name):
    result = subprocess.run(
        ["systemctl", "list-units", "--full", "--all", service_name],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    return service_name in result.stdout.decode()


def config_server(psk, server_ipv6, iran_servers):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    animate("\033[93mInstalling IPSEC..\033[0m")
    hide("sudo apt install strongswan -y")
    animate("\033[92mIPSEC Installation is completed!\033[0m")

    if service_exists("strongswan-starter.service"):
        cmd("sudo systemctl disable strongswan-starter")
        cmd("sudo systemctl stop strongswan-starter")

    if service_exists("strongswan.service"):
        cmd("sudo systemctl disable strongswan")
        cmd("sudo systemctl stop strongswan")

    cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")

    ipsec_conf = """config setup
##azumiisinyourarea
 charondebug="all"
 uniqueids=no
"""
    secrets_conf = ""

    for i, (client_ip, _) in enumerate(iran_servers, start=1):
        unique_server_ipv6 = f"{server_ipv6[:-2]}{i:02x}/64"
        ipsec_conf += f"""
conn ISATAP_server{i}
  left=%defaultroute
  leftsubnet={unique_server_ipv6}
  leftid={unique_server_ipv6[:-3]}
  right={client_ip}
  rightsubnet={client_ip}/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no
"""
        secrets_conf += f'{client_ip} {unique_server_ipv6[:-3]} : PSK "{psk}"\n'

    with open("/etc/ipsec1.conf", "w") as f:
        f.write(ipsec_conf)

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(secrets_conf)

    service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(service_content)

    cmd("sudo systemctl daemon-reload")
    cmd("sudo systemctl enable strong-azumi1")
    cmd("sudo systemctl restart strong-azumi1")


def config_client(psk, server_ipv6, client_ipv6):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    animate("\033[93mInstalling IPSEC..\033[0m")
    hide("sudo apt install strongswan -y")
    animate("\033[92mIPSEC Installation is completed!\033[0m")

    if service_exists("strongswan-starter.service"):
        cmd("sudo systemctl disable strongswan-starter")
        cmd("sudo systemctl stop strongswan-starter")

    if service_exists("strongswan.service"):
        cmd("sudo systemctl disable strongswan")
        cmd("sudo systemctl stop strongswan")

    cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")

    ipsec_conf = f"""config setup
##azumiisinyourarea
  
conn localtun_server
  left=%defaultroute
  leftsubnet={client_ipv6}/64
  leftid={client_ipv6}
  right={server_ipv6}
  rightsubnet={server_ipv6}/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no
"""

    with open("/etc/ipsec1.conf", "w") as f:
        f.write(ipsec_conf)

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{server_ipv6} {client_ipv6} : PSK "{psk}"\n')

    service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target

[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""

    with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
        f.write(service_content)

    cmd("sudo systemctl daemon-reload")
    cmd("sudo systemctl enable strong-azumi1")
    cmd("sudo systemctl restart strong-azumi1")


def load_balance(server_ipv6, iran_servers):
    file_path = "/usr/local/bin/isatap.sh"
    lb_script = "\n\n# Azumi at your service\n"

    for i, (client_ip, port) in enumerate(iran_servers, start=1):
        lb_script += f"""
ipvsadm -A -t [{server_ipv6}]:{port} -s wrr
ipvsadm -a -t [{server_ipv6}]:{port} -r [{client_ip}]:{port} -g
"""

    with open(file_path, "a") as file:
        file.write(lb_script)


def ipv6_box_iran(interface):
    ipv6_address = isaaddress(interface)
    if ipv6_address:
        print(
            "\033[93m─────────────────────────────────────────────────────────\033[0m"
        )
        print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
        print("\033[92m+---------------------------+\033[0m")
        print(f"\033[92m| {ipv6_address}   |\033[0m")
        print("\033[92m+---------------------------+\033[0m")


def ipv6_box_kharej(interface):
    ipv6_address = isaaddress(interface)
    if ipv6_address:
        print(
            "\033[93m─────────────────────────────────────────────────────────\033[0m"
        )
        print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
        print("\033[92m+---------------------------+\033[0m")
        print(f"\033[92m| {ipv6_address}   |\033[0m")
        print("\033[92m+---------------------------+\033[0m")


def ping_server(server_ipv6):
    display_notification("\033[96mAzumi is pinging..\033[0m")
    result = subprocess.run(
        ["ping", "-c", "2", server_ipv6], capture_output=True, text=True
    )
    if result.returncode == 0:
        print(result.stdout)
        return True
    else:
        print(f"\033[91mPing failed: {result.stderr}\033[0m")
        return False


def choose_reset3():
    print("\033[93mChoose IPSEC reset timer:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1. \033[92mHour\033[0m")
    print("2. \033[93mMinute\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    reset_unit = input("\033[93mEnter your choice (1 or 2): \033[0m")
    if reset_unit == "1":
        reset2_hour()
    elif reset_unit == "2":
        reset2_minutes()
    else:
        print("\033[91mInvalid choice. Please enter 1 or 2.\033[0m")


def reset_local(interval):
    service_name = "isatapreset.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_isatap.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/isatap_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/isatap_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom IPSEC Daemon

[Service]
ExecStart=/usr/local/bin/isatap_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link delete azumiserver
/bin/bash /usr/local/bin/isatap.sh
sudo systemctl restart strong-azumi1
"""

    with open("/etc/reset_isatap.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_isatap.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "--now", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_local2(interval):
    service_name = "isatapreset.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/reset_isatap.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/isatap_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/isatap_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom IPSEC Daemon

[Service]
ExecStart=/usr/local/bin/isatap_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
ip link delete azumiclient
/bin/bash /usr/local/bin/isatap.sh
sudo systemctl restart strong-azumi1
"""

    with open("/etc/reset_isatap.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/reset_isatap.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "--now", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def reset_ping_isatapclient(client_ipv6_list):
    ping_commands = "\n".join(
        [f"    ping -c 2 {ipv6} >/dev/null 2>&1" for ipv6 in client_ipv6_list]
    )
    script_content = f"""#!/bin/bash

while true; do
{ping_commands}
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_isatap.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def resetping_service_isatap():
    service_content = """[Unit]
Description=Azumi local Service reset
After=network.target

[Service]
Type=simple
Restart=always    
LimitNOFILE=1048576
ExecStart=/etc/resetbasedonping1.sh

[Install]
WantedBy=multi-user.target
"""
    with open("/etc/systemd/system/azumireset1.service", "w") as f:
        f.write(service_content)
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "azumireset1"])
    subprocess.run(["systemctl", "restart", "azumireset1"])


def iran1server_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m IRAN Server\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    install_radvd()
    install_ipvsadm()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input("\033[93mEnter \033[92mIRAN\033[93m Server IPV4: \033[0m")
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    create_isatap_server(local_ipv4)
    isa_cronjob()
    interface = "azumiserver"
    ipv6_box_kharej(interface)
    print("\033[93m────────────────────────────────────────\033[0m")

    kharej_servers_count = int(
        input("\033[93mHow many \033[92mKharej \033[93mClients do you have? \033[0m")
    )

    kharej_servers_data = []
    client_ipv6_list = []
    for i in range(1, kharej_servers_count + 1):
        remote_ipv4 = input(
            f"\033[93mEnter \033[92mKharej \033[96m{i} \033[93mIPv4 address:\033[0m "
        )
        client_ipv6 = prefix(remote_ipv4)
        client_ipv6_list.append(client_ipv6)
        port = input(
            f"\033[93mEnter the port for \033[92mKharej \033[96m{i}\033[93m: \033[0m"
        )
        with open("/etc/port.sh", "a") as f:
            f.write(f"REMOTE_IPV4_{i}={remote_ipv4}\n")
            f.write(f"PORT={port}\n")
        ufwport(port)
        kharej_servers_data.append((client_ipv6, port))

    server_ipv6 = isaaddress("azumiserver")
    if not server_ipv6:
        print("\033[91mNo IPv6 address for azumiserver found\033[0m")
        return

    load_balance(server_ipv6, kharej_servers_data)
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_server(psk, server_ipv6, kharej_servers_data)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
        print("\033[93m────────────────────────────────────────\033[0m")
    for index, (client_ipv6, _) in enumerate(kharej_servers_data, start=1):
        ping_keepalive(client_ipv6, index)
        isa_service(index)
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local(interval_seconds)
        reset_ping_isatapclient(client_ipv6_list)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")

    animate("\033[92mIRAN Server Configuration is completed!\033[0m")


def kharej1server_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Kharej Server\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    install_radvd()
    install_ipvsadm()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input("\033[93mEnter \033[92mKharej\033[93m Server IPV4: \033[0m")
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    create_isatap_server(local_ipv4)
    isa_cronjob()
    interface = "azumiserver"
    ipv6_box_kharej(interface)
    print("\033[93m────────────────────────────────────────\033[0m")

    iran_servers_count = int(
        input("\033[93mHow many \033[92mIRAN \033[93mClients do you have? \033[0m")
    )

    iran_servers_data = []
    client_ipv6_list = []
    for i in range(1, iran_servers_count + 1):
        remote_ipv4 = input(
            f"\033[93mEnter \033[92mIRAN \033[96m{i} \033[93mIPv4 address:\033[0m "
        )
        client_ipv6 = prefix(remote_ipv4)
        client_ipv6_list.append(client_ipv6)
        port = input(
            f"\033[93mEnter the port for \033[92mIRAN \033[96m{i}\033[93m: \033[0m"
        )
        with open("/etc/port.sh", "a") as f:
            f.write(f"REMOTE_IPV4_{i}={remote_ipv4}\n")
            f.write(f"PORT={port}\n")
        ufwport(port)
        iran_servers_data.append((client_ipv6, port))

    server_ipv6 = isaaddress("azumiserver")
    if not server_ipv6:
        print("\033[91mNo IPv6 address for azumiserver found\033[0m")
        return

    load_balance(server_ipv6, iran_servers_data)
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_server(psk, server_ipv6, iran_servers_data)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()

    for index, (client_ipv6, _) in enumerate(iran_servers_data, start=1):
        ping_keepalive(client_ipv6, index)
        isa_service(index)
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local(interval_seconds)
        reset_ping_isatapclient(client_ipv6_list)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mKharej Server Configuration is completed!\033[0m")


def prefix(ipv4):
    octets = ipv4.split(".")
    hex_parts = [format(int(octet), "02x") for octet in octets]
    return f"2001:db8::5efe:{hex_parts[0]}{hex_parts[1]}:{hex_parts[2]}{hex_parts[3]}"


def iranclient1_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m IRAN Client [1]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mIRAN \033[96m[1]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mKharej\033[93m Server IPV4: \033[0m")
    port = input(f"\033[93mEnter the port for \033[92mIRAN \033[96m1\033[93m: \033[0m")
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")

    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)

    interface = "azumiclient"
    ipv6_box_iran(interface)

    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server1.sh"):
        os.remove("/etc/server1.sh")
    with open("/etc/server1.sh", "w") as f:
        f.write(f"server=1\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mIRAN Client 1 Configuration is completed!\033[0m")


def reset_ping_isatapserver(server_ipv6):
    script_content = f"""#!/bin/bash

while true; do
    ping -c 2 {server_ipv6} >/dev/null 2>&1 
    if [ $? -ne 0 ]; then
        /bin/bash /etc/reset_isatap.sh
    fi
    sleep 5
done
"""
    with open("/etc/resetbasedonping1.sh", "w") as f:
        f.write(script_content)
    os.chmod("/etc/resetbasedonping1.sh", 0o755)


def iranclient2_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m IRAN Client [2]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mIRAN \033[96m[2]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mKharej\033[93m Server IPV4: \033[0m")
    port = input(f"\033[93mEnter the port for \033[92mIRAN \033[96m2\033[93m: \033[0m")
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)

    interface = "azumiclient"
    ipv6_box_iran(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server1.sh"):
        os.remove("/etc/server2.sh")
    with open("/etc/server2.sh", "w") as f:
        f.write(f"server=2\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mIRAN Client 2 Configuration is completed!\033[0m")


def iranclient3_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m IRAN Client [3]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mIRAN \033[96m[3]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mKharej\033[93m Server IPV4: \033[0m")
    port = input(f"\033[93mEnter the port for \033[92mIRAN \033[96m3\033[93m: \033[0m")
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_iran(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server3.sh"):
        os.remove("/etc/server3.sh")
    with open("/etc/server3.sh", "w") as f:
        f.write(f"server=3\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mIRAN Client 3 Configuration is completed!\033[0m")


def iranclient4_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m IRAN Client [4]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mIRAN \033[96m[4]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mKharej\033[93m Server IPV4: \033[0m")
    port = input(f"\033[93mEnter the port for \033[92mIRAN \033[96m4\033[93m: \033[0m")
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_iran(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server4.sh"):
        os.remove("/etc/server4.sh")
    with open("/etc/server4.sh", "w") as f:
        f.write(f"server=4\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mIRAN Client 4 Configuration is completed!\033[0m")


def iranclient5_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m IRAN Client [5]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mIRAN \033[96m[5]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mKharej\033[93m Server IPV4: \033[0m")
    port = input(f"\033[93mEnter the port for \033[92mIRAN \033[96m5\033[93m: \033[0m")
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_iran(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server5.sh"):
        os.remove("/etc/server5.sh")
    with open("/etc/server5.sh", "w") as f:
        f.write(f"server=5\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mIRAN Client 5 Configuration is completed!\033[0m")


# kharej client
def kharejclient1_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Kharej Client [1]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mKharej \033[96m[1]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mIRAN\033[93m Server IPV4: \033[0m")
    port = input(
        f"\033[93mEnter the port for \033[92mKharej \033[96m1\033[93m: \033[0m"
    )
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_kharej(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server1.sh"):
        os.remove("/etc/server1.sh")
    with open("/etc/server1.sh", "w") as f:
        f.write(f"server=1\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mKharej Client 1 Configuration is completed!\033[0m")


def kharejclient2_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Kharej Client [2]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mKharej \033[96m[2]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mIRAN\033[93m Server IPV4: \033[0m")
    port = input(
        f"\033[93mEnter the port for \033[92mKharej \033[96m2\033[93m: \033[0m"
    )
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_kharej(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server2.sh"):
        os.remove("/etc/server2.sh")
    with open("/etc/server2.sh", "w") as f:
        f.write(f"server=2\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mKharej Client 2 Configuration is completed!\033[0m")


def kharejclient3_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Kharej Client [3]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mKharej \033[96m[3]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mIRAN\033[93m Server IPV4: \033[0m")
    port = input(
        f"\033[93mEnter the port for \033[92mKharej \033[96m3\033[93m: \033[0m"
    )
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_kharej(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server3.sh"):
        os.remove("/etc/server3.sh")
    with open("/etc/server3.sh", "w") as f:
        f.write(f"server=3\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mKharej Client 3 Configuration is completed!\033[0m")


def kharejclient4_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Kharej Client [4]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mKharej \033[96m[4]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mIRAN\033[93m Server IPV4: \033[0m")
    port = input(
        f"\033[93mEnter the port for \033[92mKharej \033[96m4\033[93m: \033[0m"
    )
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_kharej(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m):\033[0m "
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server4.sh"):
        os.remove("/etc/server4.sh")
    with open("/etc/server4.sh", "w") as f:
        f.write(f"server=4\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mKharej Client 4 Configuration is completed!\033[0m")


def kharejclient5_isatap_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mISATAP\033[93m Kharej Client [5]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    forward()
    print("\033[93m────────────────────────────────────────\033[0m")
    local_ipv4 = input(
        "\033[93mEnter \033[92mKharej \033[96m[5]\033[93m Client IPV4: \033[0m"
    )
    remote_ipv4 = input("\033[93mEnter \033[92mIRAN\033[93m Server IPV4: \033[0m")
    port = input(
        f"\033[93mEnter the port for \033[92mKharej \033[96m5\033[93m: \033[0m"
    )
    if os.path.exists("/etc/port.sh"):
        os.remove("/etc/port.sh")
    with open("/etc/port.sh", "a") as f:
        f.write(f"REMOTE_IPV4={remote_ipv4}\n")
        f.write(f"PORT={port}\n")
    ufwport(port)
    if os.path.exists("/usr/local/bin/isatap.sh"):
        os.remove("/usr/local/bin/isatap.sh")
    create_isatap_client(local_ipv4, remote_ipv4)
    isa_cronjob()
    server_ipv6 = prefix(remote_ipv4)
    interface = "azumiclient"
    ipv6_box_kharej(interface)
    client_ipv6 = isaaddress("azumiclient")
    if not client_ipv6:
        print("\033[91mNo IPv6 address for azumiclient found\033[0m")
        return
    print("\033[93m────────────────────────────────────────\033[0m")
    ipsec_enable = input(
        "\033[93mDo you want \033[92mIPSEC Encryption \033[93mto be enabled ? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if ipsec_enable in ["yes", "y"]:
        psk = input("\033[93mEnter \033[92mIPSEC \033[93mSecret Key :\033[0m ")
        config_client(psk, server_ipv6, client_ipv6)
        print("\033[93m────────────────────────────────────────\033[0m")
        enable_reset_ipsec()
    print("\033[93m────────────────────────────────────────\033[0m")
    ping_server(server_ipv6)
    ping_keepalive2(server_ipv6)
    isa_service2()
    if os.path.exists("/etc/server5.sh"):
        os.remove("/etc/server5.sh")
    with open("/etc/server5.sh", "w") as f:
        f.write(f"server=5\n")
    print("\033[93m────────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable \033[96mISATAP \033[92mreset time\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_local2(interval_seconds)
        reset_ping_isatapserver(server_ipv6)
        resetping_service_isatap()
        print("\033[93m────────────────────────────────────────\033[0m")
    animate("\033[92mKharej Client 5 Configuration is completed!\033[0m")


def cmd(command):
    subprocess.run(command, shell=True, check=True)


## kharej ip
def server_ipv4():

    command = "curl -s https://api.ipify.org"
    process = subprocess.run(command, shell=True, capture_output=True, text=True)
    if process.returncode != 0:
        print("Error retrieving server's IPv4 address.")
        return None
    ipv4 = process.stdout.strip()
    return ipv4


def kharej_ip_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIPIP \033[92mKharej\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    file_path = "/etc/ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPv4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPv4 address: \033[0m")

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(input("Enter the number of additional IPv6 addresses: "))

    command = f"echo '/sbin/modprobe sit' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip tunnel add azumii mode ipip remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip addr add {ipv6}/16 dev azumii' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    for i in range(2, num_additional_ips + 2):
        ip_address = f"{ipv6[:-1]}{i}/16"
        command = f"echo 'ip addr add {ip_address} dev azumii' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumii up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    config_file_path = "/etc/ip.sh"

    subprocess.run(
        f"(crontab -l | grep -v -F '{file_path}') | crontab -", shell=True, check=True
    )

    cronjob_command = (
        f"(crontab -l 2>/dev/null; echo '@reboot sh {config_file_path}') | crontab -"
    )
    subprocess.run(cronjob_command, shell=True, check=True)

    print("GRE tunnel created and configured successfully.")
    print("Configuration saved to /etc/ip.sh.")
    print("Cronjob added to execute /etc/ip.sh on every reboot.")

    ip_kharej()


# iran ip


def iran_ip_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIPIP \033[92mIRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    file_path = "/etc/ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPv4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPv4 address: \033[0m")

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(input("Enter the number of additional IPv6 addresses: "))

    command = f"echo '/sbin/modprobe sit' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip tunnel add azumii mode ipip remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip addr add {ipv6}/16 dev azumii' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    for i in range(2, num_additional_ips + 2):
        ip_address = f"{ipv6[:-1]}{i}/16"
        command = f"echo 'ip addr add {ip_address} dev azumii' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumii up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    config_file_path = "/etc/ip.sh"

    subprocess.run(
        f"(crontab -l | grep -v -F '{file_path}') | crontab -", shell=True, check=True
    )

    cronjob_command = (
        f"(crontab -l 2>/dev/null; echo '@reboot sh {config_file_path}') | crontab -"
    )
    subprocess.run(cronjob_command, shell=True, check=True)

    print("GRE tunnel created and configured successfully.")
    print("Configuration saved to /etc/ip.sh.")
    print("Cronjob added to execute /etc/ip.sh on every reboot.")
    ip_iran()


###menu ipip
def ipip_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIPIP Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnussingle()
            kharej_ipip6_menu()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnussingle()
            iran_ipip6_menu()
            break
        elif server_type == "3":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def run_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b481::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v6_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v6.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v6.service"])
    subprocess.run(["systemctl", "start", "ping_v6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v6.service"])


def display_kharej_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "fd1d:fc98:b73e:b481::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron_job():
    file_path = "/etc/private.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


##ipip6 kharej
def ping_ipip_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip.service"])
    subprocess.run(["systemctl", "start", "ping_ip.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip.service"])


def ipip6_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a220::1/64 dev azumip' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:0db8:1234:a22{i}::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumip' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a220::1\n".format(
                interface
            )
        with open("/etc/ipip.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip mtu {mtu_value}\n"
        with open("/etc/ipip.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses :\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a220::1    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip6_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ipip' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumip mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 addr add 2002:0db8:1234:a220::1/64 dev azumip' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumip up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = (
        f"echo 'ip -6 route add 2002:0db8:1234:a220::2/64 dev azumip' >> {file_path}"
    )
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a220::1\n".format(
                interface
            )
        with open("/etc/ipip.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip mtu {mtu_value}\n"
        with open("/etc/ipip.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses :\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:0db8:1234:a220::1    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def create_ping_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip_kharej():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip6_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a220::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip_service()

    ipip_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip_kharejsec():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip6_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a220::2"  # iranip
    max_pings = 3
    interval = 2
    create_ping_script(ip_address, max_pings, interval)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_ipip_service()

    ipip_cronjob()
    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit kharej
def kharej_ipip6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::2/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip_kharej()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##### IRAN IPIP6
def iran_pingg():
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b481::1"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def display_iran_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "fd1d:fc98:b73e:b481::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


##ipip6 iran


def iran_ipip_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip.service"])
    subprocess.run(["systemctl", "start", "ping_ip.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip.service"])


def ipip6_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/ipip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a220::2/64 dev azumip\n")
        f.write("ip link set azumip up\n")
        f.write("ip -6 route add 2002::/16 dev azumip\n")
        created_ips = []
        for i in range(2, num_additional_ips + 2):
            ip_address = f"2002:0db8:1234:a22{i}::2"
            created_ips.append(ip_address)
            f.write(f"ip -6 addr add {ip_address}/64 dev azumip\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a220::2\n".format(
                interface
            )
        with open("/etc/ipip.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip mtu {mtu_value}\n"
        with open("/etc/ipip.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a220::2    |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip6_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/ipip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    with open(file_path, "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumip mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 addr add 2002:0db8:1234:a220::2/64 dev azumip\n")
        f.write("ip link set azumip up\n")
        f.write("ip -6 route add 2002:0db8:1234:a220::1/64 dev azumip\n")

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:0db8:1234:a220::2\n".format(
                interface
            )
        with open("/etc/ipip.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [IP6IP6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumip mtu {mtu_value}\n"
        with open("/etc/ipip.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "| 2002:0db8:1234:a220::2    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def ipip_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/ipip.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/ipip.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def iran_ping_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def ipip_iran():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej-ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("\033[93mHow many \033[92madditional ips\033[93m do you need? \033[0m")
    )
    ipip6_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:0db8:1234:a220::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip_service()

    ipip_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


def ipip_iransec():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej-ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipip6_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:0db8:1234:a220::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_ipip_service()

    ipip_cronjob()

    display_checkmark("\033[92mIPIP6 Configuration Completed!\033[0m")


# sit iran
def iran_ipip6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::1/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_pingg()

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip_iran()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    ##### PRIVATE & NATIVE


def private_ip_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mPrivate IP Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_reset_rmvmnusingle()
            kharej_private_menu()
            break
        elif server_type == "2":
            private_reset_rmvmnusingle()
            iran_private_menu()
            break
        elif server_type == "3":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def run_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "2002:831b::2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def run_ping_iran():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "2002:831b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v6_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v6.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v6.service"])
    subprocess.run(["systemctl", "start", "ping_v6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v6.service"])


def kharej_private_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  There is also a cronjob and a ping service that automatically installs"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "-6", "addr", "add", initial_ip, "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    num_ips = int(
        input("\033[93mHow many \033[92mprivate IPs\033[93m do you need? \033[0m")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1/64"

        result = subprocess.run(
            ["ip", "-6", "addr", "show", "dev", "azumi"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "-6", "addr", "add", ip_addr, "dev", "azumi"],
                stdout=subprocess.DEVNULL,
            )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip -6 addr add 2002:831b::1/64 dev azumi\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:83{ip_suffix}b::1/64"
            f.write(f"ip -6 addr add {ip_addr} dev azumi\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831b::1\n".format(
                interface
            )
        with open("/etc/private.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::1"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def iran_private_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Iran server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  There is also a cronjob and a ping service that automatically installs"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "-6", "addr", "add", initial_ip, "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    num_ips = int(
        input("\033[93mHow many \033[92mprivate IPs\033[93m do you need? \033[0m")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::2/64"

        result = subprocess.run(
            ["ip", "-6", "addr", "show", "dev", "azumi"], capture_output=True, text=True
        )
        if ip_addr in result.stdout:
            print(f"IP address {ip_addr} already exists. Skipping...")
        else:
            subprocess.run(
                ["ip", "-6", "addr", "add", ip_addr, "dev", "azumi"],
                stdout=subprocess.DEVNULL,
            )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip -6 addr add 2002:831b::2/64 dev azumi\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi\n")
        for i in range(1, num_ips + 1):
            ip_suffix = hex(i)[2:]
            ip_addr = f"2002:83{ip_suffix}b::2/64"
            f.write(f"ip -6 addr add {ip_addr} dev azumi\n")
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831b::2\n".format(
                interface
            )
        with open("/etc/private.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron_job()

    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")
    for i in range(1, num_ips + 1):
        ip_suffix = hex(i)[2:]
        ip_addr = f"2002:83{ip_suffix}b::2"
        print("\033[92m" + "+---------------------------+" + "\033[0m")
        print("\033[92m" + f" {ip_addr}    " + "\033[0m")
        print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:831b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()


## Native


def Native_menu():
    subprocess.run("clear", shell=True)
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mNative IP Menu\033[0m")
    print('\033[92m "-"\033[93m═════════════════════\033[0m')
    
    print(
        "\033[93m.-------------------------------------------------------------------------------------------------------.\033[0m"
    )
    print(
        "\033[93m| \033[92mIf it didn't work, please uninstall it and add extra IP manually  \033[0m"
    )
    print(
        "\033[93m|\033[0m  If you don't have native IPv6, please use a private IP instead.                                             \033[0m"
    )
    print(
        "\033[93m'-------------------------------------------------------------------------------------------------------'\033[0m"
    )
    display_notification("\033[93mAdding extra Native IPv6 [Kharej]...\033[0m")
    print("\033[93m╭──────────────────────────────────────────────────────────╮\033[0m")

    try:
        interface = subprocess.run(
            "ip route | awk '/default/ {print $5; exit}'",
            shell=True,
            capture_output=True,
            text=True,
        ).stdout.strip()
        ipv6_addresses = (
            subprocess.run(
                f"ip -6 addr show dev {interface} | awk '/inet6 .* global/ {{print $2}}' | cut -d'/' -f1",
                shell=True,
                capture_output=True,
                text=True,
            )
            .stdout.strip()
            .split("\n")
        )

        print("\033[92mCurrent IPv6 addresses on", interface + ":\033[0m")
        for address in ipv6_addresses:
            print(address)

        confirm = input("\033[93mAre these your current IPv6 addresses? (y/n): \033[0m")
        if confirm.lower() != "y":
            display_error(
                "\033[91mAborted. Please manually configure the correct IPv6 addresses.\033[0m"
            )
            return

        sorted_addresses = sorted(ipv6_addresses, reverse=True)
        additional_address = ""
        for i in range(len(sorted_addresses)):
            current_last_part = sorted_addresses[i].split(":")[-1]
            modified_last_part_hex = format(int(current_last_part, 16) + 1, "04x")
            modified_address = (
                ":".join(sorted_addresses[i].split(":")[:-1])
                + ":"
                + modified_last_part_hex
            )

            if modified_address not in sorted_addresses:
                additional_address = modified_address
                break

        if not additional_address:
            display_error("\033[91mNo additional address to add.\033[0m")
            return

        subprocess.run(
            ["ip", "addr", "add", f"{additional_address}/64", "dev", interface]
        )

        script_file = "/etc/ipv6.sh"
        with open(script_file, "a") as file:
            file.write(f"ip addr add {additional_address}/64 dev {interface}\n")

        subprocess.run(["chmod", "+x", script_file])

        subprocess.run("crontab -l | grep -v '/etc/ipv6.sh' | crontab -", shell=True)

        display_notification("\033[93mAdding cronjob for the server..\033[0m")
        subprocess.run(
            '(crontab -l 2>/dev/null; echo "@reboot /bin/bash /etc/ipv6.sh") | crontab -',
            shell=True,
        )

        display_checkmark("\033[92mIPv6 addresses added successfully!\033[0m")
    except ValueError as e:
        display_error(
            "\033[91mAn error occurred while adding IPv6 addresses:", str(e), "\033[0m"
        )


###menu gre
def gre_gre6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE | GRE6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE\033[0m")
    print("2. \033[93mGRE6 \033[0m")
    print("3. \033[94mback to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre_menu()
            break
        elif server_type == "2":
            gre6_menu()
            break
        elif server_type == "3":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


def gre_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("3. \033[94mback to previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_gre_menu()
            break
        elif server_type == "2":
            iran_gre_menu()
            break
        elif server_type == "3":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def gre6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE6 Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("3. \033[94mback to previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnusingle()
            kharej_gre6_menu()
            break
        elif server_type == "2":
            gre6_reset_rmvmnusingle()
            iran_gre6_menu()
            break
        elif server_type == "3":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


##gre6
def run_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        subprocess.run(
            ["ping", "-c", "2", "fd1d:fc98:b73e:b481::2"],
            check=True,
            stdout=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_v6_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_v6.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v6.service"])
    subprocess.run(["systemctl", "start", "ping_v6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v6.service"])


def display_kharej_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "fd1d:fc98:b73e:b481::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def add_cron_job():
    file_path = "/etc/private.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


##gre6 kharej


def gre6_cronjob():
    try:

        subprocess.run(
            "crontab -l | grep -v '/etc/gre6.sh' | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            "(crontab -l ; echo '@reboot /bin/bash /etc/gre6.sh') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ping_gre6_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip.service"])
    subprocess.run(["systemctl", "start", "ping_ip.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip.service"])


def gre6_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::1"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig6' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::1               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def create_ping_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre6_kharej():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre6_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    gre6_cronjob()


def gre6_kharejsec():
    remote_ip = "fd1d:fc98:b73e:b481::2"  # iran-ip
    local_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    gre6_cronjob()


# espn_gre
def kharej1_gre6_menu():
    global local_ip, remote_ip
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
        f.write("ip -6 route add fd1d::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre6_kharej()
    sleep(1)


# sit kharej
def kharej_gre6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::2/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre6_kharej()
    sleep(1)


##### IRAN gre6


def display_iran_ip():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")
    ip_addr = "fd1d:fc98:b73e:b481::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| {ip_addr}    |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_gre6_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip.service"])
    subprocess.run(["systemctl", "start", "ping_ip.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip.service"])


def gre6_iran_tunnel(remote_ip, local_ip, num_additional_ips):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    created_ips = []
    for i in range(2, num_additional_ips + 2):
        ip_address = f"2002:83{i}a::2"
        created_ips.append(ip_address)
        command = f"echo 'ip -6 addr add {ip_address}/64 dev azumig6' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    for ip_address in created_ips:
        print("\033[92m" + f"| {ip_address}               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def gre6_iran_tunnelsec(remote_ip, local_ip):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IPv6 Addresses:\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f"| 2002:831a::2               |" + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def iran_ping_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre6_iran():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input(
            "\033[97mEnter the number of \033[92madditional IPs\033[97m for the \033[92mGRE6\033[97m tunnel: "
        )
    )
    gre6_iran_tunnel(remote_ip, local_ip, num_additional_ips)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    gre6_cronjob()


def gre6_iransec():
    remote_ip = "fd1d:fc98:b73e:b481::1"  # kharej ip
    local_ip = "fd1d:fc98:b73e:b481::2"  # iran ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gre6_iran_tunnelsec(remote_ip, local_ip)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    gre6_cronjob()


## gre6 erspan iran
def iran1_gre6_menu():
    global local_ip, remote_ip
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
        f.write("ip -6 route add fd1d::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_pingg()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre6_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


# sit iran
def iran_gre6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::1/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_pingg()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre6_iran()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


## gre
def gre_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_ip.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_ip.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_ip.service"])
    subprocess.run(["systemctl", "start", "ping_ip.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_ip.service"])


def gre_ping_script(ip_address, max_pings, interval):
    file_path = "/etc/ping_ip.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    script_content = f"""#!/bin/bash

ip_address="{ip_address}"

max_pings={max_pings}

interval={interval}

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open(file_path, "w") as file:
        file.write(script_content)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)


def gre_iran():
    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    sleep(1)

    ip_address = remote_prefix
    max_pings = 3
    interval = 2
    gre_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()

    print(ping_result)

    gre_service()


def gre_kharej():
    remote_ipv4 = input(
        "\033[93mEnter \033[92mIran IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    sleep(1)

    ip_address = remote_prefix
    max_pings = 3
    interval = 2
    gre_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()

    print(ping_result)

    gre_service()


## kharej gre
def server_ipv4():

    command = "curl -s https://api.ipify.org"
    process = subprocess.run(command, shell=True, capture_output=True, text=True)
    if process.returncode != 0:
        print("Error retrieving server's IPv4 address.")
        return None
    ipv4 = process.stdout.strip()
    return ipv4


def kharej_gre_menu():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE \033[92mKharej\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print("\033[97m  For ping service, enter \033[92mIRAN\033[97m IPV4 address")
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    file_path = "/etc/gre.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────╮\033[0m")

    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPv4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPv4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────╯\033[0m")

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("Enter the number of \033[92madditional IPv6\033[93m addresses: ")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    command = f"echo '/sbin/modprobe gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip tunnel add azumig mode gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip addr add {ipv6}/16 dev azumig' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    for i in range(2, num_additional_ips + 2):
        ip_address = f"{ipv6[:-1]}{i}/16"
        command = f"echo 'ip addr add {ip_address} dev azumig' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("Error: No network interface with IPv6 address.")
        else:
            print("Interface:", interface)
            rt_command = (
                "ip -6 route replace default via fe80::1 dev {} src {}\n".format(
                    interface, ipv6_address
                )
            )
        with open("/etc/gre.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig mtu {mtu_value}\n"
        with open("/etc/gre.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    config_file_path = "/etc/gre.sh"

    subprocess.run(
        f"(crontab -l | grep -v -F '{file_path}') | crontab -", shell=True, check=True
    )

    cronjob_command = (
        f"(crontab -l 2>/dev/null; echo '@reboot sh {config_file_path}') | crontab -"
    )
    subprocess.run(cronjob_command, shell=True, check=True)

    display_checkmark("\033[92mGRE Configuration Completed!\033[0m")

    gre_kharej()


# iran gre


def iran_gre_menu():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE \033[92mIRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print("\033[97m  For ping service, enter \033[92mKharej\033[97m IPV4 address")
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    file_path = "/etc/gre.sh"

    if os.path.exists(file_path):
        os.remove(file_path)
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────╮\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPv4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPv4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────╯\033[0m")

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_additional_ips = int(
        input("Enter the number of \033[92madditional IPv6\033[93m addresses: ")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    command = f"echo '/sbin/modprobe gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip tunnel add azumig mode gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip addr add {ipv6}/16 dev azumig' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    for i in range(2, num_additional_ips + 2):
        ip_address = f"{ipv6[:-1]}{i}/16"
        command = f"echo 'ip addr add {ip_address} dev azumig' >> {file_path}"
        subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("Error: No network interface with IPv6 address.")
        else:
            print("Interface:", interface)
            rt_command = (
                "ip -6 route replace default via fe80::1 dev {} src {}\n".format(
                    interface, ipv6_address
                )
            )
        with open("/etc/gre.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig mtu {mtu_value}\n"
        with open("/etc/gre.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    config_file_path = "/etc/gre.sh"

    subprocess.run(
        f"(crontab -l | grep -v -F '{file_path}') | crontab -", shell=True, check=True
    )

    cronjob_command = (
        f"(crontab -l 2>/dev/null; echo '@reboot sh {config_file_path}') | crontab -"
    )
    subprocess.run(cronjob_command, shell=True, check=True)

    display_checkmark("\033[92mGRE Configuration Completed!\033[0m")
    gre_iran()


def clear_screen():
    os.system("clear")


def i6to4_menu():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(O,O)\033[0m")
    print("\033[92m(   ) \033[93m6TO4 Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')

    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92m6to4 \033[0m")
    print("2. \033[93m6to4 Anycast\033[0m")
    print("3. \033[94mback to main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")

    if server_type == "1":
        i6to4_no()
    elif server_type == "2":
        i6to4_any()
    elif server_type == "3":
        clear_screen()
        main_menu()
    else:
        print("Invalid choice.")


def add_6to4_job():
    file_path = "/etc/6to4.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def i6to4_no():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m6TO4 \033[92m[Not Anycast]\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            i6to4_kharej()
            break
        elif server_type == "2":
            i6to4_iran()
            break
        elif server_type == "3":
            clear_screen()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def ipv6_int():
    interfaces = netifaces.interfaces()
    for iface in interfaces:
        if iface != "lo" and netifaces.AF_INET6 in netifaces.ifaddresses(iface):
            return iface
    return None


def i6to4_kharej():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m6TO4 \033[92mKharej\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print("\033[97m  For ping service, enter \033[92mIRAN\033[97m IPV4 address")
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )

    if (
        subprocess.run(["test", "-f", "/etc/6to4.sh"], capture_output=True).returncode
        == 0
    ):
        subprocess.run(["rm", "/etc/6to4.sh"])

    display_notification("\033[93mConfiguring...\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    sleep(1)
    print("\033[93m╭────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPv4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPv4 address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()

    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    if prefix.endswith("::1"):
        gateway = prefix[:-3] + "::2"
    else:
        gateway = prefix[:-3] + "::1"

    with open("/etc/6to4.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe sit\n")
        f.write(
            "/sbin/ip tunnel add azumi6 mode sit remote {} local {} ttl 255\n".format(
                remote_ip, local_ip
            )
        )

        set_mtu = input(
            "\033[93mDo you want to set \033[92m MTU?\033[93m (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
        )
        if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
            mtu_value = input(
                "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
            )
            f.write("/sbin/ip -6 link set dev azumi6 mtu {}\n".format(mtu_value))
        else:
            f.write("/sbin/ip -6 link set dev azumi6 mtu 1480\n")

        f.write("/sbin/ip link set dev azumi6 up\n")
        f.write("/sbin/ip -6 addr add {}/16 dev azumi6\n".format(prefix))
        f.write(
            "/sbin/ip -6 route add 2000::/3 via {} dev azumi6 metric 1\n".format(
                gateway
            )
        )
        f.write("ip -6 route add ::/0 dev azumi6\n")
        answer = input(
            "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
        )
        if answer.lower() in ["yes", "y"]:
            interface = ipv6_int()
            if interface is None:
                print("Error: No network interface with IPv6 address.")
            else:
                print("Interface:", interface)
                f.write(
                    "ip -6 route replace default via fe80::1 dev {} src {}\n".format(
                        interface, prefix
                    )
                )
        else:
            print("Skipping changing the default route.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input("\033[93mHow many \033[92madditional IPs\033[93m do you need? \033[0m")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    start_index = 3

    with open("/etc/6to4.sh", "a") as f:
        for i in range(start_index, start_index + num_ips):
            ip_addr = "2002:{:02x}{:02x}:{:02x}{:02x}::{:02x}/16".format(
                *map(int, ipv4.split(".")), i
            )
            f.write("ip -6 addr add {} dev azumi6\n".format(ip_addr))

    display_notification("\033[93mAdding cronjob!\033[0m")

    add_6to4_job()

    display_notification("\033[93mStarting 6to4...\033[0m")
    subprocess.run(["/bin/bash", "/etc/6to4.sh"])

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIran IPv4 address\033[93m [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )

    sleep(1)

    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()

    print(ping_result)

    script_content = (
        '''#!/bin/bash


ip_address="'''
        + remote_prefix
        + """"

max_pings=5

interval=2

while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F"time=" "{print $1}" | cut -d "." -f1)
       
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done"""
    )

    with open("/etc/ping_v6.sh", "w") as f:
        f.write(script_content)

    subprocess.run(["chmod", "+x", "/etc/ping_v6.sh"])

    service_content = """[Unit]
Description=Ping Service
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v6.sh
Restart=always

[Install]
WantedBy=multi-user.target"""

    with open("/etc/systemd/system/ping_v6.service", "w") as f:
        f.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v6.service"])
    subprocess.run(["systemctl", "start", "ping_v6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v6.service"])

    display_checkmark("\033[92m6to4 Service has been added successfully!\033[0m")


def i6to4_iran():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m6TO4 \033[92mIRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print("\033[97m  For ping service, enter \033[92mKharej\033[97m IPV4 address")
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )

    if (
        subprocess.run(["test", "-f", "/etc/6to4.sh"], capture_output=True).returncode
        == 0
    ):
        subprocess.run(["rm", "/etc/6to4.sh"])

    display_notification("\033[93mConfiguring...\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    sleep(1)
    print("\033[93m╭────────────────────────────────────────────────────────╮\033[0m")

    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPv4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPv4 address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()

    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    if prefix.endswith("::1"):
        gateway = prefix[:-3] + "::2"
    else:
        gateway = prefix[:-3] + "::1"

    with open("/etc/6to4.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe sit\n")
        f.write(
            "/sbin/ip tunnel add azumi6 mode sit remote {} local {} ttl 255\n".format(
                remote_ip, local_ip
            )
        )
        set_mtu = input(
            "\033[93mDo you want to set \033[92m MTU?\033[93m (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
        )
        if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
            mtu_value = input(
                "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
            )
            f.write("/sbin/ip -6 link set dev azumi6 mtu {}\n".format(mtu_value))
        else:
            f.write("/sbin/ip -6 link set dev azumi6 mtu 1480\n")
        f.write("/sbin/ip link set dev azumi6 up\n")
        f.write("/sbin/ip -6 addr add {}/16 dev azumi6\n".format(prefix))
        f.write(
            "/sbin/ip -6 route add 2000::/3 via {} dev azumi6 metric 1\n".format(
                gateway
            )
        )
        answer = input(
            "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
        )
        if answer.lower() in ["yes", "y"]:
            interface = ipv6_int()
            if interface is None:
                print("Error: No network interface with IPv6 address.")
            else:
                print("Interface:", interface)
                f.write(
                    "ip -6 route replace default via fe80::1 dev {} src {}\n".format(
                        interface, prefix
                    )
                )
        else:
            print("Skipping changing the default route.")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input("\033[93mHow many \033[92madditional IPs\033[93m do you need? \033[0m")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    start_index = 3

    with open("/etc/6to4.sh", "a") as f:
        for i in range(start_index, start_index + num_ips):
            ip_addr = "2002:{:02x}{:02x}:{:02x}{:02x}::{:02x}/16".format(
                *map(int, ipv4.split(".")), i
            )
            f.write("ip -6 addr add {} dev azumi6\n".format(ip_addr))

    display_notification("\033[93mAdding cronjob!\033[0m")

    add_6to4_job()

    display_notification("\033[93mStarting 6to4...\033[0m")
    subprocess.run(["/bin/bash", "/etc/6to4.sh"])

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4 address\033[93m [Ping Service]: \033[0m"
    )

    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )

    sleep(1)

    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()

    print(ping_result)

    script_content = (
        '''#!/bin/bash


ip_address="'''
        + remote_prefix
        + """"

max_pings=5

interval=2

while true
do
  
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F"time=" "{print $1}" | cut -d "." -f1)
       
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done"""
    )

    with open("/etc/ping_v6.sh", "w") as f:
        f.write(script_content)

    subprocess.run(["chmod", "+x", "/etc/ping_v6.sh"])

    service_content = """[Unit]
Description=Ping Service
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v6.sh
Restart=always

[Install]
WantedBy=multi-user.target"""

    with open("/etc/systemd/system/ping_v6.service", "w") as f:
        f.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v6.service"])
    subprocess.run(["systemctl", "start", "ping_v6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v6.service"])

    display_checkmark("\033[92m6to4 Service has been added successfully!\033[0m")


def clear():
    subprocess.run(["clear"])


def i6to4_any():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m6to4 \033[92m[Anycast]\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')

    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")

    if server_type == "1":
        i6to4_any_kharej()
    elif server_type == "2":
        i6to4_any_iran()
    elif server_type == "3":
        clear()
        singleserver_mnu()
    else:
        print("Invalid choice.")


def i6to4_any_kharej():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6to4 \033[92mKharej\033[93m  Menu\033[92m[Anycast]\033[0m"
    )
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your \033[92mKharej\033[93m IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print("\033[97m  For ping service, enter \033[92mIRAN\033[97m IPV4 address")
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )

    if (
        subprocess.run(["test", "-f", "/etc/6to4.sh"], capture_output=True).returncode
        == 0
    ):
        subprocess.run(["rm", "/etc/6to4.sh"])

    display_notification("\033[93mConfiguring...\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej IPv4\033[93m address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()

    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    with open("/etc/6to4.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe sit\n")
        f.write(
            "/sbin/ip tunnel add azumi6 mode sit remote any local {} ttl 255\n".format(
                local_ip
            )
        )
        set_mtu = input(
            "\033[93mDo you want to set \033[92m MTU?\033[93m (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
        )
        if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
            mtu_value = input(
                "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
            )
            f.write("/sbin/ip -6 link set dev azumi6 mtu {}\n".format(mtu_value))
        else:
            f.write("/sbin/ip -6 link set dev azumi6 mtu 1480\n")
        f.write("/sbin/ip link set dev azumi6 up\n")
        f.write("/sbin/ip -6 addr add {}/16 dev azumi6\n".format(prefix))
        f.write(
            "/sbin/ip -6 route add 2000::/3 via ::192.88.99.1 dev azumi6 metric 1\n"
        )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = input(
        "\033[93mHow many \033[92madditional IPs\033[93m do you need? \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    start_index = 3

    with open("/etc/6to4.sh", "a") as f:
        for i in range(start_index, start_index + int(num_ips)):
            ip_addr = "2002:{:02x}{:02x}:{:02x}{:02x}::{:02x}/16".format(
                *map(int, ipv4.split(".")), i
            )
            f.write("ip -6 addr add {} dev azumi6\n".format(ip_addr))

    display_notification("\033[93mAdding cronjob!\033[0m")

    add_6to4_job()

    display_notification("\033[93mStarting 6to4...\033[0m")
    subprocess.run(["/bin/bash", "/etc/6to4.sh"])

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    sleep(1)
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()

    print(ping_result)

    script_content = """#!/bin/bash

ip_address="{}"

max_pings=5

interval=2

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
       
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""
    with open("/etc/ping_v6.sh", "w") as f:
        f.write(script_content)

    subprocess.run(["chmod", "+x", "/etc/ping_v6.sh"])

    with open("/etc/systemd/system/ping_v6.service", "w") as f:
        f.write("[Unit]\n")
        f.write("Description=Ping Service\n")
        f.write("After=network.target\n")
        f.write("\n")
        f.write("[Service]\n")
        f.write("ExecStart=/bin/bash /etc/ping_v6.sh\n")
        f.write("Restart=always\n")
        f.write("\n")
        f.write("[Install]\n")
        f.write("WantedBy=multi-user.target\n")

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v6.service"])
    subprocess.run(["systemctl", "start", "ping_v6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v6.service"])

    display_checkmark("\033[92m6to4 Service has been added successfully!\033[0m")


def i6to4_any_iran():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6to4 \033[92mIRAN\033[93m  Menu\033[92m[Anycast]\033[0m"
    )
    print('\033[92m"-"\033[93m════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your \033[92mIRAN\033[93m IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print("\033[97m  For ping service, enter \033[92mKharej\033[97m IPV4 address")
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )

    if (
        subprocess.run(["test", "-f", "/etc/6to4.sh"], capture_output=True).returncode
        == 0
    ):
        subprocess.run(["rm", "/etc/6to4.sh"])

    display_notification("\033[93mConfiguring...\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIran IPv4\033[93m address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()

    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    with open("/etc/6to4.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe sit\n")
        f.write(
            "/sbin/ip tunnel add azumi6 mode sit remote any local {} ttl 255\n".format(
                local_ip
            )
        )
        set_mtu = input(
            "\033[93mDo you want to set \033[92m MTU?\033[93m (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
        )
        if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
            mtu_value = input(
                "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
            )
            f.write("/sbin/ip -6 link set dev azumi6 mtu {}\n".format(mtu_value))
        else:
            f.write("/sbin/ip -6 link set dev azumi6 mtu 1480\n")
        f.write("/sbin/ip link set dev azumi6 up\n")
        f.write("/sbin/ip -6 addr add {}/16 dev azumi6\n".format(prefix))
        f.write(
            "/sbin/ip -6 route add 2000::/3 via ::192.88.99.1 dev azumi6 metric 1\n"
        )
        answer = input(
            "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
        )
        if answer.lower() in ["yes", "y"]:
            interface = ipv6_int()
            if interface is None:
                print("Error: No network interface with IPv6 address.")
            else:
                print("Interface:", interface)
                f.write(
                    "ip -6 route replace default via fe80::1 dev {} src {}\n".format(
                        interface, prefix
                    )
                )
        else:
            print("Skipping changing the default route.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input("\033[93mHow many \033[92madditional IPs\033[93m do you need? \033[0m")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    start_index = 3

    with open("/etc/6to4.sh", "a") as f:
        for i in range(start_index, start_index + num_ips):
            ip_addr = "2002:{:02x}{:02x}:{:02x}{:02x}::{:02x}/16".format(
                *map(int, ipv4.split(".")), i
            )
            f.write("ip -6 addr add {} dev azumi6\n".format(ip_addr))

    display_notification("\033[93mAdding cronjob!\033[0m")

    add_6to4_job()

    display_notification("\033[93mStarting 6to4...\033[0m")
    subprocess.run(["/bin/bash", "/etc/6to4.sh"])

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )
    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )

    subprocess.run(["sleep", "1"])
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    script_content = """#!/bin/bash

ip_address="{}"
max_pings=5
interval=2

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
       
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix
    )

    with open("/etc/ping_v6.sh", "w") as f:
        f.write(script_content)

    subprocess.run(["chmod", "+x", "/etc/ping_v6.sh"])

    with open("/etc/systemd/system/ping_v6.service", "w") as f:
        f.write(
            """[Unit]
Description=Ping Service
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_v6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""
        )

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_v6.service"])
    subprocess.run(["systemctl", "start", "ping_v6.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_v6.service"])

    display_checkmark("\033[92m6to4 Service has been added successfully!\033[0m")


# test gre gen ipsec
def gengre_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mGeneve \033[93m+ \033[96mGRE6 \033[93m+\033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mMethod 1[Server Address]\033[0m")
    print("2. \033[93mMethod 2[Gre6 Address]\033[0m")
    print("3. \033[96mMethod 3[Geneve Address]\033[0m")
    print("4. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gengre_ipsec1()
            break
        elif server_type == "2":
            gengre_ipsec2()
            break
        elif server_type == "3":
            gengre_ipsec3()
            break
        elif server_type == "4":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


# method 1
def gengre_ipsec1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mGeneve \033[93m+ \033[96mGRE6 \033[93m+ \033[92mIPV4 \033[93m Menu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej_ipgen_menu()
            break
        elif server_type == "2":
            iran_ipgen_menu()
            break
        elif server_type == "3":
            clear()
            main_menu()
            break
        else:
            print("Invalid choice.")


def kharej_ipgen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipgen_ipvers()


def ipgen_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipgen_ipk_version1()
            break
        elif server_type == "2":
            ipgen_ipk_version2()
            break
        else:
            print("Invalid choice.")


def ipgen_ipk_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("66.200.1.1")
    ufw("66.200.2.1")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def ipgen_ipk_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("2001:db8::1")
    ufw("2001:db8::2")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def iran_ipgen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipgen2_ipvers()


def ipgen2_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipgen_ipi_version1()
            break
        elif server_type == "2":
            ipgen_ipi_version2()
            break
        else:
            print("Invalid choice.")


def ipgen_ipi_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def ipgen_ipi_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("2001:db8::1")
    ufw("2001:db8::2")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# method 2
def gengre_ipsec2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mGeneve \033[93m+ \033[96mGRE6 \033[93m+ \033[92mIPV4 \033[93m M2\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejm2_ipgen_menu()
            break
        elif server_type == "2":
            iranm2_ipgen_menu()
            break
        elif server_type == "3":
            clear()
            gengre_ipsec()
        else:
            print("Invalid choice.")


def kharejm2_ipgen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipgenm2_ipvers()


def ipgenm2_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipgenm2_ipk_version1()
            break
        elif server_type == "2":
            ipgenm2_ipk_version2()
            break
        else:
            print("Invalid choice.")


# for method 2 geneve
def configm2_strongsw_simkh1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:832a::1/64
  leftid=2002:832a::1
  right=2002:832a::2
  rightsubnet=2002:832a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:832a::2 2002:832a::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


##
def ipgenm2_ipk_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("66.200.1.1")
    ufw("66.200.2.1")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm2_strongsw_simkh1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def ipgenm2_ipk_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("2001:db8::1")
    ufw("2001:db8::2")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm2_strongsw_simkh1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# for method 2 geneve
def configm2_strongsw_simih1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:832a::2/64
  leftid=2002:832a::2
  right=2002:832a::1
  rightsubnet=2002:832a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:832a::1 2002:832a::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


##
def iranm2_ipgen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipgen2m2_ipvers()


def ipgen2m2_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipgenm2_ipi_version1()
            break
        elif server_type == "2":
            ipgenm2_ipi_version2()
            break
        else:
            print("Invalid choice.")


def ipgenm2_ipi_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("66.200.2.1")
    ufw("66.200.1.1")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm2_strongsw_simih1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def ipgenm2_ipi_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2002:831::1")
    ufw("2002:831::2")
    ufw("2001:db8::2")
    ufw("2001:db8::1")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm2_strongsw_simih1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# method 3


def gengre_ipsec3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[92mGeneve \033[93m+ \033[96mGRE6 \033[93m+ \033[92mIPV4 \033[93m M3\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejm3_ipgen_menu()
            break
        elif server_type == "2":
            iranm3_ipgen_menu()
            break
        elif server_type == "3":
            clear()
            gengre_ipsec()
        else:
            print("Invalid choice.")


def kharejm3_ipgen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipgenm3_ipvers()


def ipgenm3_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipgenm3_ipk_version1()
            break
        elif server_type == "2":
            ipgenm3_ipk_version2()
            break
        else:
            print("Invalid choice.")


# for method 3 geneve
def configm31_strongsw_simk1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.1.1/32
  leftid=66.200.1.1
  right=66.200.2.1
  rightsubnet=66.200.2.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.2.1 66.200.1.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


##


def configm32_strongsw_simk1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::1/64
  leftid=2001:db8::1
  right=2001:db8::2
  rightsubnet=2001:db8::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::2 2001:db8::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


##


## icmp test
def icmp_erspan4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmpV4 + Erspan + IPsec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + IPsec Method 1 [Server Address] \033[0m")
    print("2. \033[96mErspan + IPsec Method 2 [Erspan Address] \033[0m")
    print("3. \033[94mBack to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp_ipsec1()
            break
        elif server_type == "2":
            icmp_ipsec2()
            break
        elif server_type == "3":
            os.system("clear")
            main_menu()
            break
        else:
            print("Invalid choice.")


# icmp erspan ipv4 and ipv6 server address


def icmp_ipsec1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmpV4 + Erspan Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp_kharej_espnV4()
            break
        elif server_type == "2":
            icmp_iran_espnV4()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_erspan4()
            break
        else:
            print("Invalid choice.")


def install_icmp4():
    display_notification("\033[93mInstalling \033[92mIcmpV4\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_loading()

    ipv4_forward_status = subprocess.run(
        ["sysctl", "-n", "net.ipv4.ip_forward"], capture_output=True, text=True
    )
    if int(ipv4_forward_status.stdout) != 1:
        subprocess.run(["sysctl", "net.ipv4.ip_forward=1"])

    subprocess.run(
        ["sudo", "apt", "install", "-y", "git"], capture_output=True, text=True
    )

    if os.path.exists("/root/icmpv4"):
        shutil.rmtree("/root/icmpv4")

    clone_command = "git clone https://github.com/miyugundam/icmp.git icmpv4"
    clone_result = os.system(clone_command)
    if clone_result != 0:
        print("Error: Failed to clone Repo.")
        return

    if os.path.exists("/root/icmpv4"):
        os.chdir("/root/icmpv4")

        subprocess.run(
            ["sudo", "apt", "install", "-y", "net-tools"],
            capture_output=True,
            text=True,
        )
        subprocess.run(
            ["sudo", "apt", "install", "-y", "make"], capture_output=True, text=True
        )
        subprocess.run(
            ["sudo", "apt-get", "install", "-y", "libssl-dev"],
            capture_output=True,
            text=True,
        )
        subprocess.run(
            ["sudo", "apt", "install", "-y", "g++"], capture_output=True, text=True
        )

        subprocess.run(["make"], capture_output=True, text=True)

        os.chdir("..")
    else:
        display_error("\033[91micmp folder not found.\033[0m")
    pass


def icmp41_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "70.0.0.2"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def start_ic4_kharej():
    display_notification("\033[93mConfiguring \033[92mKharej\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()

    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/root/icmpv4/icmptunnel -s -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.1 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated ICMP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          70.0.0.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def icmp42_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "70.0.0.1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def start_ic4_iran():
    display_notification("\033[93mConfiguring \033[92mIRAN \033[93m...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/icmpv4")

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write(f"/root/icmpv4/icmptunnel {remote_ip} -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.2 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp2_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated ICMP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          70.0.0.2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def icmp_kharej_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    icmpv4_spn_kharej()


def icmpv4_spn_kharej():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp4_simpk1()
            break
        elif server_type == "2":
            icmp4_simk2()
            break
        else:
            print("Invalid choice.")


def icmp4_simpk1():

    start_ic4_kharej()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.1",
            "remote",
            "70.0.0.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.1 remote 70.0.0.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def icmp4_simk2():

    start_ic4_kharej()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.1",
            "remote",
            "70.0.0.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.1 remote 70.0.0.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def icmp_iran_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_icmp4_iran()


def spn_icmp4_iran():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp4_simpi1()
            break
        elif server_type == "2":
            icmp4_simpi2()
            break
        else:
            print("Invalid choice.")


def icmp4_simpi1():

    start_ic4_iran()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.2",
            "remote",
            "70.0.0.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.2 remote 70.0.0.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def icmp4_simpi2():

    start_ic4_iran()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.2",
            "remote",
            "70.0.0.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.2 remote 70.0.0.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def up_up():
    ulimit_setting = "ulimit -n 65535"
    bashrc_path = os.path.expanduser("~/.bashrc")

    with open(bashrc_path, "r") as f:
        existing_bashrc = f.read()

    if ulimit_setting not in existing_bashrc:
        with open(bashrc_path, "a") as f:
            f.write("\n")
            f.write(ulimit_setting)
            f.write("\n")

    sysctl_conf_path = "/etc/sysctl.conf"
    sysctl_params = [
        "net.core.rmem_max=26214400",
        "net.core.rmem_default=26214400",
        "net.core.wmem_max=26214400",
        "net.core.wmem_default=26214400",
        "net.core.netdev_max_backlog=2048",
    ]

    with open(sysctl_conf_path, "r") as f:
        existing_sysctl_conf = f.read()

    params_to_add = []
    for param in sysctl_params:
        if param not in existing_sysctl_conf:
            params_to_add.append(param)

    if params_to_add:
        with open(sysctl_conf_path, "a") as f:
            f.write("\n")
            f.write("\n".join(params_to_add))
            f.write("\n")
        try:
            subprocess.run(
                ["sudo", "sysctl", "-p"], stderr=subprocess.DEVNULL, check=True
            )
            display_checkmark("\033[92mIt is Done!\033[0m")
        except subprocess.CalledProcessError:
            print("\033[91mAn error occurred while setting it up.\033[0m")
    else:
        display_checkmark("\033[92mIt was already Done.\033[0m")


# icmpv4 erspan erspan address
def icmp_ipsec2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmpV4 + Erspan Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmpm2_kharej_espnV4()
            break
        elif server_type == "2":
            icmpm2_iran_espnV4()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_erspan4()
            break
        else:
            print("Invalid choice.")


# prequisite


def startm2_ic4_kharej1():
    display_notification("\033[93mConfiguring \033[92mKharej\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp4k1(psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()

    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/root/icmpv4/icmptunnel -s -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.1 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")


def startm2_ic4_kharej2():
    display_notification("\033[93mConfiguring \033[92mKharej\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp4k2(psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()

    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/root/icmpv4/icmptunnel -s -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.1 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")


def startm2_ic4_iran1():
    display_notification("\033[93mConfiguring \033[92mIRAN \033[93m...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp4i1(psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/icmpv4")

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write(f"/root/icmpv4/icmptunnel {remote_ip} -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.2 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp2_ping()


def startm2_ic4_iran2():
    display_notification("\033[93mConfiguring \033[92mIRAN \033[93m...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp4i2(psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/icmpv4")

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write(f"/root/icmpv4/icmptunnel {remote_ip} -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.2 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp2_ping()


def icmpm2_kharej_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    icmpv4m2_spn_kharej()


def icmpv4m2_spn_kharej():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp4m2_simpk1()
            break
        elif server_type == "2":
            icmp4m2_simk2()
            break
        else:
            print("Invalid choice.")


def icmp4m2_simpk1():

    startm2_ic4_kharej1()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.1",
            "remote",
            "70.0.0.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.1 remote 70.0.0.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def icmp4m2_simk2():

    startm2_ic4_kharej2()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.1",
            "remote",
            "70.0.0.2",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.1 remote 70.0.0.2 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def icmpm2_iran_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spnm2_icmp4_iran()


def spnm2_icmp4_iran():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp4m2_simpi1()
            break
        elif server_type == "2":
            icmp4m2_simpi2()
            break
        else:
            print("Invalid choice.")


def icmp4m2_simpi1():

    startm2_ic4_iran1()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.2",
            "remote",
            "70.0.0.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.2 remote 70.0.0.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def icmp4m2_simpi2():

    startm2_ic4_iran2()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "70.0.0.2",
            "remote",
            "70.0.0.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 70.0.0.2 remote 70.0.0.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def config_strongsw_icmp4k1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.1.1/32
  leftid=66.200.1.1
  right=66.200.2.1
  rightsubnet=66.200.2.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.2.1 66.200.1.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_icmp4k2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::1/64
  leftid=2001:db8::1
  right=2001:db8::2
  rightsubnet=2001:db8::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::2 2001:db8::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_icmp4i1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.2.1/32
  leftid=66.200.2.1
  right=66.200.1.1
  rightsubnet=66.200.1.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.1.1 66.200.2.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_icmp4i2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::2/64
  leftid=2001:db8::2
  right=2001:db8::1
  rightsubnet=2001:db8::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::1 2001:db8::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


##
def ipgenm3_ipk_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm31_strongsw_simk1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def ipgenm3_ipk_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw("2001:db8::2")
    ufw("fd1d:fc98:b73e:b481::2")
    ufw("2002:831a::1")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    kharej1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm32_strongsw_simk1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


# for method 3 geneve
def configm31_strongsw_simi1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.2.1/32
  leftid=66.200.2.1
  right=66.200.1.1
  rightsubnet=66.200.1.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.1.1 66.200.2.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


# for method 3 geneve
def configm32_strongsw_simi1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::2/64
  leftid=2001:db8::2
  right=2001:db8::1
  rightsubnet=2001:db8::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::1 2001:db8::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


##
def iranm3_ipgen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ipgen2m3_ipvers()


def ipgen2m3_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipgenm3_ipi_version1()
            break
        elif server_type == "2":
            ipgenm3_ipi_version2()
            break
        else:
            print("Invalid choice.")


def ipgenm3_ipi_version1():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm31_strongsw_simi1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def ipgenm3_ipi_version2():
    global local_ip, remote_ip
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw("2001:db8::1")
    ufw("2002:831a::1")
    ufw("fd1d:fc98:b73e:b481::1")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    iran1_gre6_menu()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm32_strongsw_simi1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::2/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## hans icmp test
def icmp_erspan5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mHans + Erspan + IPsec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan + IPsec Method 1 [Server Address] \033[0m")
    print("2. \033[96mErspan + IPsec Method 2 [Erspan Address] \033[0m")
    print("3. \033[94mBack to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hanz_ipsec1()
            break
        elif server_type == "2":
            hanz_ipsec2()
            break
        elif server_type == "3":
            os.system("clear")
            main_menu()
            break
        else:
            print("Invalid choice.")


# hans erspan ipv4 and ipv6 server address


def hanz_ipsec1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mHans + Erspan Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hanz_kharej_espnV4()
            break
        elif server_type == "2":
            hanz_iran_espnV4()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_erspan5()
            break
        else:
            print("Invalid choice.")


def hanss_install_menu():
    display_notification("\033[93mInstalling \033[92mHans\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_loading()

    ipv4_forward_status = subprocess.run(
        ["sysctl", "-n", "net.ipv4.ip_forward"], capture_output=True, text=True
    )
    if int(ipv4_forward_status.stdout) != 1:
        subprocess.run(["sysctl", "net.ipv4.ip_forward=1"])

    subprocess.run(
        [
            "wget",
            "https://sourceforge.net/projects/hanstunnel/files/source/hans-1.1.tar.gz",
        ],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        check=True,
    )
    subprocess.run(
        ["tar", "-xzf", "hans-1.1.tar.gz"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        check=True,
    )
    os.chdir("/root/hans-1.1")

    subprocess.run(["apt", "install", "-y", "make"], check=True)
    subprocess.run(["apt", "install", "-y", "g++"], check=True)
    subprocess.run(["make"], check=True)

    display_checkmark("\033[92mHans installed successfully!\033[0m")

    os.remove("/root/hans-1.1.tar.gz")
    pass


def icmp3_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "80.1.2.100"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def hns_icmp_kharej1():
    display_notification("\033[93mConfiguring Kharej ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )
    hans_directory = "/root/hans-1.1"

    os.chdir(hans_directory)
    os.system(f"./hans -s 80.1.2.0 -p azumi86chwan -d icmp")

    hans_kharej_command = f"{hans_directory}/hans -s 80.1.2.0 -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_kharej_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_kharej_command}\n")

    subprocess.run(
        ["chmod", "700", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp3_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          80.1.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def icmp4_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "80.1.2.1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def hns_icmp_iran1():
    display_notification("\033[93mConfiguring IRAN ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/hans-1.1")
    os.system(f"./hans -c {remote_ip} -p azumi86chwan -d icmp")

    subprocess.call(["rm", "-f", "/etc/cron.d/hans"])

    hans_command = f"/root/hans-1.1/hans -c {remote_ip} -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_command}\n")
    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp4_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          80.1.2.100\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def hanz_kharej_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    hanz_spn_kharej()


def hanz_spn_kharej():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hanz_simpk1()
            break
        elif server_type == "2":
            hanz_simk2()
            break
        else:
            print("Invalid choice.")


def hanz_simpk1():

    hns_icmp_kharej1()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.1",
            "remote",
            "80.1.2.100",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.1 remote 80.1.2.100 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def hanz_simk2():

    hns_icmp_kharej1()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.1",
            "remote",
            "80.1.2.100",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.1 remote 80.1.2.100 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def hanz_iran_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_hanz_iran()


def spn_hanz_iran():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hanz_simpi1()
            break
        elif server_type == "2":
            hanz_simpi2()
            break
        else:
            print("Invalid choice.")


def hanz_simpi1():

    hns_icmp_iran1()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.100",
            "remote",
            "80.1.2.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.100 remote 80.1.2.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def hanz_simpi2():

    hns_icmp_iran1()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.100",
            "remote",
            "80.1.2.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.100 remote 80.1.2.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# erspan address
def config_strongsw_hanzk1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.1.1/32
  leftid=66.200.1.1
  right=66.200.2.1
  rightsubnet=66.200.2.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.2.1 66.200.1.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_hanzk2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::1/64
  leftid=2001:db8::1
  right=2001:db8::2
  rightsubnet=2001:db8::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::2 2001:db8::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def hanz_ipsec2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mHans + Erspan Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hanz2_kharej_espnV4()
            break
        elif server_type == "2":
            hanz2_iran_espnV4()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_erspan5()
            break
        else:
            print("Invalid choice.")


def hanss_install_menu():
    display_notification("\033[93mInstalling \033[92mHans\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_loading()

    ipv4_forward_status = subprocess.run(
        ["sysctl", "-n", "net.ipv4.ip_forward"], capture_output=True, text=True
    )
    if int(ipv4_forward_status.stdout) != 1:
        subprocess.run(["sysctl", "net.ipv4.ip_forward=1"])

    subprocess.run(
        [
            "wget",
            "https://sourceforge.net/projects/hanstunnel/files/source/hans-1.1.tar.gz",
        ],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        check=True,
    )
    subprocess.run(
        ["tar", "-xzf", "hans-1.1.tar.gz"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        check=True,
    )
    os.chdir("/root/hans-1.1")

    subprocess.run(["apt", "install", "-y", "make"], check=True)
    subprocess.run(["apt", "install", "-y", "g++"], check=True)
    subprocess.run(["make"], check=True)

    display_checkmark("\033[92mHans installed successfully!\033[0m")

    os.remove("/root/hans-1.1.tar.gz")
    pass


def icmp3_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "80.1.2.100"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def hns2_icmp_kharej1():
    display_notification("\033[93mConfiguring Kharej ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_hanzk1(psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )
    hans_directory = "/root/hans-1.1"

    os.chdir(hans_directory)
    os.system(f"./hans -s 80.1.2.0 -p azumi86chwan -d icmp")

    hans_kharej_command = f"{hans_directory}/hans -s 80.1.2.0 -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_kharej_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_kharej_command}\n")

    subprocess.run(
        ["chmod", "700", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp3_ping()


def hns3_icmp_kharej1():
    display_notification("\033[93mConfiguring Kharej ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_hanzk2(psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )
    hans_directory = "/root/hans-1.1"

    os.chdir(hans_directory)
    os.system(f"./hans -s 80.1.2.0 -p azumi86chwan -d icmp")

    hans_kharej_command = f"{hans_directory}/hans -s 80.1.2.0 -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_kharej_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_kharej_command}\n")

    subprocess.run(
        ["chmod", "700", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp3_ping()


def icmp4_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "80.1.2.1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def config_strongsw_hanzi1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.2.1/32
  leftid=66.200.2.1
  right=66.200.1.1
  rightsubnet=66.200.1.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.1.1 66.200.2.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_hanzi2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::2/64
  leftid=2001:db8::2
  right=2001:db8::1
  rightsubnet=2001:db8::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::2 2001:db8::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def hns2_icmp_iran1():
    display_notification("\033[93mConfiguring IRAN ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()

    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_hanzi1(psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/hans-1.1")
    os.system(f"./hans -c {remote_ip} -p azumi86chwan -d icmp")

    subprocess.call(["rm", "-f", "/etc/cron.d/hans"])

    hans_command = f"/root/hans-1.1/hans -c {remote_ip} -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_command}\n")
    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp4_ping()


def hns3_icmp_iran1():
    display_notification("\033[93mConfiguring IRAN ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()

    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_hanzi2(psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/hans-1.1")
    os.system(f"./hans -c {remote_ip} -p azumi86chwan -d icmp")

    subprocess.call(["rm", "-f", "/etc/cron.d/hans"])

    hans_command = f"/root/hans-1.1/hans -c {remote_ip} -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_command}\n")
    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp4_ping()


def hanz2_kharej_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    hanz2_spn_kharej()


def hanz2_spn_kharej():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hanz2_simpk1()
            break
        elif server_type == "2":
            hanz2_simk2()
            break
        else:
            print("Invalid choice.")


def hanz2_simpk1():

    hns2_icmp_kharej1()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.1",
            "remote",
            "80.1.2.100",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.1 remote 80.1.2.100 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def hanz2_simk2():

    hns3_icmp_kharej1()
    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.1",
            "remote",
            "80.1.2.100",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.1 remote 80.1.2.100 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def hanz2_iran_espnV4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    spn_hanz2_iran()


def spn_hanz2_iran():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Erspan IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hanz2_simpi1()
            break
        elif server_type == "2":
            hanz2_simpi2()
            break
        else:
            print("Invalid choice.")


def hanz2_simpi1():

    hns2_icmp_iran1()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.100",
            "remote",
            "80.1.2.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.100 remote 80.1.2.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumiespn\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def hanz2_simpi2():

    hns3_icmp_iran1()

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "dev",
            "azumiespn",
            "type",
            "erspan",
            "local",
            "80.1.2.100",
            "remote",
            "80.1.2.1",
            "seq",
            "key",
            "100",
            "erspan_ver",
            "1",
            "erspan",
            "1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumiespn", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumiespn"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add dev azumiespn type erspan local 80.1.2.100 remote 80.1.2.1 seq key 100 erspan_ver 1 erspan 1\n"
        )
        f.write("sudo ip link set azumiespn up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumiespn\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Erspan]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumiespn mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")
    ##


# test gen ipsec
def gen4_ipsec_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGeneve \033[93m+ IPV4 + \033[92mIPsec \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve + IPsec\033[0m")
    print("2. \033[93mGeneve + GRE6 + IPsec\033[0m")
    print("3. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen4_ipsec()
            break
        elif server_type == "2":
            gengre_ipsec()
            break
        elif server_type == "3":
            choose_reset()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def gen4_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGeneve \033[93m+ IPV4 + \033[92mIPsec \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mMethod 1[Server Address]\033[0m")
    print("2. \033[93mMethod 2[Geneve Address]\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen41_ipsec()
            break
        elif server_type == "2":
            gen42_ipsec()
            break
        elif server_type == "3":
            clear()
            gen4_ipsec_mnu()
            break
        else:
            print("Invalid choice.")


# method1 gen41
def gen41_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGeneve \033[93m+ IPV4 + \033[92mIPsec M[1] \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_ipseck()
            break
        elif server_type == "2":
            gen_ipseci()
            break
        elif server_type == "3":
            clear()
            gen4_ipsec()
            break
        else:
            print("Invalid choice.")


def gen_ipseck():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gen_simple1()


def gen_simple1():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_simpk1()
            break
        elif server_type == "2":
            gen_simpk2()
            break
        else:
            print("Invalid choice.")


def config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simk2(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_strongsw_simi2(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def gen_simpk1():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    ufw(local_ip)
    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_simk1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gen_simpk2():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    ufw(local_ip)
    ufw(remote_ip)
    ufw("2001:db8::1")
    ufw("2001:db8::2")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simk2(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gen_ipseci():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gen_simple2()


def gen_simple2():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_simpi1()
            break
        elif server_type == "2":
            gen_simpi2()
            break
        else:
            print("Invalid choice.")


def gen_simpi1():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    ufw(local_ip)
    ufw(remote_ip)
    ufw("66.200.2.1")
    ufw("66.200.1.1")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simi1(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def gen_simpi2():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    ufw(local_ip)
    ufw(remote_ip)
    ufw("2001:db8::1")
    ufw("2001:db8::2")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_simi2(local_ip, local_subnet, remote_ip, remote_subnet, psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


# method 2 gen42


def gen42_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGeneve \033[93m+ IPV4 + \033[92mIPsec M[2] \033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genm2_ipseck()
            break
        elif server_type == "2":
            genm2_ipseci()
            break
        elif server_type == "3":
            clear()
            gen4_ipsec()
            break
        else:
            print("Invalid choice.")


def genm2_ipseck():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    genm2_simple1()


def genm2_simple1():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genm2_simpk1()
            break
        elif server_type == "2":
            genm2_simpk2()
            break
        else:
            print("Invalid choice.")


def configm2_strongsw_simk1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.1.1/32
  leftid=66.200.1.1
  right=66.200.2.1
  rightsubnet=66.200.2.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.2.1 66.200.1.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def configm2_strongsw_simk2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::1/64
  leftid=2001:db8::1
  right=2001:db8::2
  rightsubnet=2001:db8::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::2 2001:db8::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def configm2_strongsw_simi1(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=66.200.2.1/32
  leftid=66.200.2.1
  right=66.200.1.1
  rightsubnet=66.200.1.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'66.200.1.1 66.200.2.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def configm2_strongsw_simi2(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2001:db8::2/64
  leftid=2001:db8::2
  right=2001:db8::1
  rightsubnet=2001:db8::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2001:db8::1 2001:db8::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def genm2_simpk1():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    configm2_strongsw_simk1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def genm2_simpk2():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db8::1")
    ufw("2001:db8::2")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    configm2_strongsw_simk2(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::1/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add 2001:db8::1/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan3_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def genm2_ipseci():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIRAN server \033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring IRAN server...\033[0m")

    if os.path.isfile("/etc/spn.sh"):
        os.remove("/etc/spn.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    genm2_simple2()


def genm2_simple2():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genm2_simpi1()
            break
        elif server_type == "2":
            genm2_simpi2()
            break
        else:
            print("Invalid choice.")


def genm2_simpi1():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("66.200.2.1")
    ufw("66.200.1.1")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    configm2_strongsw_simi1(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan2_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def ipsecs_uninstall():
    delete_cron1()
    delete_cron2()
    remove_private()
    remove_gre621()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Erspan + \033[92mIpsec \033[93m+ Tunnels\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/spn.sh", shell=True) == 0:
            subprocess.run("rm /etc/spn.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/spn.sh" | crontab -',
            shell=True,
        )
        devnull = open(os.devnull, "w")
        subprocess.run(
            "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)

        subprocess.run("apt purge strongswan -y", shell=True)
        subprocess.run(
            "systemctl disable ping_espan.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_espan.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("sudo ip link delete azumiespn > /dev/null", shell=True)
        devnull.close()
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


##ipip + ipsec
def ipip__ipsec_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIP6IP6 IPSEC Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("3. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            ipip6_reset_rmvmnussingle()
            kharej_ipip6sec_menu()
            break
        elif server_type == "2":
            ipip6_reset_rmvmnussingle()
            iran_ipip6sec_menu()
            break
        elif server_type == "3":
            choose_reset()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def azumi_ip6ip6_k(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a220::1/64
  leftid=2002:0db8:1234:a220::1
  right=2002:0db8:1234:a220::2
  rightsubnet=2002:0db8:1234:a220::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:0db8:1234:a220::2 2002:0db8:1234:a220::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def azumi_ip6ip6_ir(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:0db8:1234:a220::2/64
  leftid=2002:0db8:1234:a220::2
  right=2002:0db8:1234:a220::1
  rightsubnet=2002:0db8:1234:a220::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:0db8:1234:a220::1 2002:0db8:1234:a220::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def kharej_ipip6sec_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mKharej\033[93m server\033[0m"
    )
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_ip6ip6_k(psk)
    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::2/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip_kharejsec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


def iran_ipip6sec_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring IPIP6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_ip6ip6_ir(psk)
    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::1/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_pingg()

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    ipip_iransec()
    sleep(1)
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")


##Private ip + ipsec
def private_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mPrivate IP +IPSec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            private_reset_rmvmnusingle()
            kharej_private_ipsec()
            break
        elif server_type == "2":
            private_reset_rmvmnusingle()
            iran_private_ipsec()
            break
        elif server_type == "3":
            choose_reset()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def azumi_private_k(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831b::1/64
  leftid=2002:831b::1
  right=2002:831b::2
  rightsubnet=2002:831b::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831b::2 2002:831b::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def azumi_private_ir(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831b::2/64
  leftid=2002:831b::2
  right=2002:831b::1
  rightsubnet=2002:831b::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831b::1 2002:831b::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def kharej_private_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Kharej server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  There is also a cronjob and a ping service that automatically installs"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_private_k(psk)
    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "-6", "addr", "add", initial_ip, "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::2/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip -6 addr add 2002:831b::1/64 dev azumi\n")
        f.write("ip -6 route add 2002:831b::2/64 dev azumi\n")

    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831b::1\n".format(
                interface
            )
        with open("/etc/private.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (Kharej):\033[0m")

    ip_addr = f"2002:831b::1"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def iran_private_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring Iran server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  There is also a cronjob and a ping service that automatically installs"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_private_ir(psk)

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "-6", "addr", "add", initial_ip, "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    subprocess.run(
        ["ip", "-6", "route", "add", "2002:831b::1/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip -6 addr add 2002:831b::2/64 dev azumi\n")
        f.write("ip -6 route add 2002:831b::1/64 dev azumi\n")

    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831b::2\n".format(
                interface
            )
        with open("/etc/private.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")

    add_cron_job()

    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    run_ping_iran()
    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated Private IP Addresses (IRAN):\033[0m")

    ip_addr = f"2002:831b::2"
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + f" {ip_addr}    " + "\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="2002:831b::1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()


def genm2_simpi2():

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("2001:db8::2")
    ufw("2001:db8::1")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    configm2_strongsw_simi2(psk)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "2001:db8::2/64", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/spn.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 2001:db8::2/64 dev azumigen\n")
        f.write("systemctl restart strongswan-starter\n")
        f.write("systemctl restart strongswan\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/spn.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    espan_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    espan4_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "       2001:db8::2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="2001:db8::1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_espan.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_espan.sh", 0o755)
    ping_gengre_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def gre6sec_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGRE6 + IPSec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN \033[0m")
    print("3. \033[93mIPsec Reset Timer \033[0m")
    print("0. \033[94mback to previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gre6_reset_rmvmnusingle()
            kharej_gre6_sec()
            break
        elif server_type == "2":
            gre6_reset_rmvmnusingle()
            iran_gre6_sec()
            break
        elif server_type == "3":
            choose_reset()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def azumi_private_k(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831b::1/64
  leftid=2002:831b::1
  right=2002:831b::2
  rightsubnet=2002:831b::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831b::2 2002:831b::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def azumi_private_ir(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831b::2/64
  leftid=2002:831b::2
  right=2002:831b::1
  rightsubnet=2002:831b::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831b::1 2002:831b::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def azumi_gre6_k(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831a::1/64
  leftid=2002:831a::1
  right=2002:831a::2
  rightsubnet=2002:831a::2/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::2 2002:831a::1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def azumi_gre6_ir(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=2002:831a::2/64
  leftid=2002:831a::2
  right=2002:831a::1
  rightsubnet=2002:831a::1/64
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'2002:831a::1 2002:831a::2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


# sit kharej
def kharej_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mKharej\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    
    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Kharej server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_gre6_k(psk)
    initial_ip = "fd1d:fc98:b73e:b481::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::2/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")
    gre6_kharejsec()
    sleep(1)


# sit iran
def iran_gre6_sec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfiguring GRE6 \033[92mIran\033[93m server\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')

    print(
        "\033[93m╭───────────────────────────────────────────────────────────────────────────────────────╮"
    )
    print(
        "\033[92m  Please make sure to remove any private IPs that you have created before proceeding"
    )
    print(
        "\033[93m  Enter your Kharej and Iran IPV4 address, it will automatically configure your server"
    )
    print(
        "\033[96m  If you need additional IP address, you can enter the desired number"
    )
    print(
        "\033[93m╰───────────────────────────────────────────────────────────────────────────────────────╯\033[0m"
    )
    display_notification(
        "\033[93mAdding private IP addresses for Iran server...\033[0m"
    )

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    azumi_gre6_ir(psk)
    initial_ip = "fd1d:fc98:b73e:b481::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["ip", "-6", "route", "add", "fd1d:fc98:b73e:b481::1/64", "dev", "azumi"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add fd1d:fc98:b73e:b481::2/64 dev azumi\n")
        f.write("ip -6 route add fd1d:fc98:b73e:b481::1/64 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_pingg()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="fd1d:fc98:b73e:b481::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gre6_iransec()
    sleep(1)
    display_checkmark("\033[92mGRE6 Configuration Completed!\033[0m")


def remove_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[91mUninstall\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mUninstall IP6IP6\033[0m")
    print("2. \033[96mUninstall IP6IP6 + IPSec\033[0m")
    print("3. \033[93mUninstall 6to4\033[0m")
    print("4. \033[92mUninstall 6to4 \033[96manycast\033[0m")
    print("5. \033[96mUninstall Gre\033[0m")
    print("42.\033[97mUninstall erspan ip6ip6 [test]\033[0m")
    print("6. \033[92mUninstall Gre6\033[0m")
    print("7. \033[93mUninstall Gre6 + IPSec\033[0m")
    print("8. \033[97mUninstall Gre6tap\033[0m")
    print("9. \033[96mUninstall Gre6tap + IPSec\033[0m")
    print("10. \033[93mUninstall Private IP\033[0m")
    print("11. \033[92mUninstall Private IP + IPSec\033[0m")
    print("12. \033[96mUninstall Extra Native IP\033[0m")
    print("13. \033[92mUninstall Geneve | IPsec\033[0m")
    print("14. \033[93mUninstall Erspan\033[0m")
    print("15.\033[96mUninstall icmp + ipsec & erspan & hans\033[0m")
    print("16.\033[93mUninstall Vxlan\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_ipip6()
            break
        elif server_type == "2":
            remove_ipip6sec()
            break
        elif server_type == "3":
            remove_6to4()
            break
        elif server_type == "4":
            remove_6to4()
            break
        elif server_type == "5":
            remove_gre()
            break
        elif server_type == "42":
            gre6test_uninstall()
            break
        elif server_type == "15":
            icmp_uninstall()
            break
        elif server_type == "16":
            vxlan_uninstall()
            break
        elif server_type == "6":
            remove_gre6()
            break
        elif server_type == "7":
            remove_gre6sec()
            break
        elif server_type == "10":
            remove_private()
            break
        elif server_type == "11":
            remove_privatesec()
            break
        elif server_type == "12":
            extra_uninstall()
            break
        elif server_type == "13":
            genx_ip()
            break
        elif server_type == "14":
            erspan_remove()
            break
        elif server_type == "8":
            gre6tap_remove()
            break
        elif server_type == "9":
            gre6tapsec_remove()
            break
        elif server_type == "0":
            clear()
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


# erspan remove
def erspan_remove():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mErspan\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mErspan \033[0m")
    print("2. \033[93mErspan + Native \033[0m")
    print("3. \033[96mErspan + Gre6 \033[0m")
    print("4. \033[92mErspan + Gre6tap \033[0m")
    print("5. \033[97mErspan + IPsec Tunnels  \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            espn_uninstall()
            break
        elif server_type == "2":
            espn_uninstall()
            break
        elif server_type == "3":
            gre6espn_uninstall()
            break
        elif server_type == "4":
            gre6tapespn_uninstall()
            break
        elif server_type == "5":
            ipsecs_uninstall()
            break
        elif server_type == "0":
            clear()
            remove_menu()
            break
        else:
            print("Invalid choice.")


##
def ipsecs_uninstall():
    delete_cron1()
    delete_cron2()
    remove_private()
    remove_gre621()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Erspan + \033[92mIpsec \033[93m+ Tunnels\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/spn.sh", shell=True) == 0:
            subprocess.run("rm /etc/spn.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/spn.sh" | crontab -',
            shell=True,
        )
        devnull = open(os.devnull, "w")
        subprocess.run(
            "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)

        subprocess.run("apt purge strongswan -y", shell=True)
        subprocess.run(
            "systemctl disable ping_espan.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_espan.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("sudo ip link delete azumiespn > /dev/null", shell=True)
        devnull.close()
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def ipsecs_uninstall_private():
    delete_cron1()
    delete_cron2()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIpsec \033[93m+ Tunnels\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    display_notification("\033[93mRemoving cronjob...\033[0m")
    subprocess.run(
        'crontab -l | grep -v "@reboot /bin/bash /etc/spn.sh" | crontab -', shell=True
    )
    devnull = open(os.devnull, "w")
    subprocess.run(
        "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
    )
    subprocess.run(
        "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
    )
    subprocess.run("systemctl disable strongswan-starter > /dev/null 2>&1", shell=True)
    subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
    subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
    subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)

    subprocess.run("apt purge strongswan -y", shell=True)
    subprocess.run("systemctl daemon-reload", shell=True)

    devnull.close()
    print("Progress: ", end="")

    frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
    delay = 0.1
    duration = 1
    end_time = time.time() + duration

    try:
        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")

    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# gen ipsec
def ipsecs_uninstall_gen():
    delete_cron1()
    delete_cron2()
    remove_private()
    remove_gre621()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Gen + \033[92mIpsec \033[93m+ Tunnels\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/spn.sh", shell=True) == 0:
            subprocess.run("rm /etc/spn.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/spn.sh" | crontab -',
            shell=True,
        )
        devnull = open(os.devnull, "w")
        subprocess.run(
            "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)

        subprocess.run("apt purge strongswan -y", shell=True)
        subprocess.run(
            "systemctl disable ping_espan.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_espan.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)

        devnull.close()
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# ip6ip6 ipsec
def ipsecs_uninstall_ipip():
    delete_cron1()
    delete_cron2()
    remove_private()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving IP6IP6 + \033[92mIpsec \033[93m+ Tunnels\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        subprocess.run(
            "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)

        subprocess.run("apt purge strongswan -y", shell=True)
        subprocess.run(
            "systemctl disable ping_espan.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_espan.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)

        devnull.close()
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


# test icmp


def config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet={local_subnet}
  leftid={local_ip}
  right={remote_ip}
  rightsubnet={remote_subnet}
  ike=aes256-sha256-modp3072!
  esp=aes128gcm16-modp3072!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'{remote_ip} {local_ip} : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_kharej_icmp(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=70.0.0.1/32
  leftid=70.0.0.1
  right=70.0.0.2
  rightsubnet=70.0.0.2/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'70.0.0.2 70.0.0.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_iran_icmp(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=70.0.0.2/32
  leftid=70.0.0.2
  right=70.0.0.1
  rightsubnet=70.0.0.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'70.0.0.1 70.0.0.2 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def icmp_ip_mnu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmp + IPsec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIcmp V4 \033[0m")
    print("2. \033[96mIcmp V6[Not yet added] \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp_ipgov4_menu()
            break
        elif server_type == "2":
            icmp_ipgov6_menu()
            break
        elif server_type == "3":
            os.system("clear")
            singleserver_mnu()
            break
        else:
            print("Invalid choice.")


def icmp_ipgov4_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmpV4 + IPsec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIcmp + IPsec\033[0m")
    print("2. \033[96mHans + Erspan + IPsec \033[0m")
    print("3. \033[93mICMP + Erspan + IPsec \033[0m")
    print("4. \033[97mIPsec Reset Timer \033[0m")
    print("0. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp_ipsec()
            break
        elif server_type == "2":
            icmp_erspan4()
            break
        elif server_type == "3":
            icmp_erspan5()
            break
        elif server_type == "4":
            choose_reset()
            break
        elif server_type == "0":
            os.system("clear")
            icmp_ip_mnu()
            break
        else:
            print("Invalid choice.")


def icmp_ipsec():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmp + IPsec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIcmp Method 1 \033[0m")
    print("2. \033[96mHans Method 2 \033[0m")
    print("3. \033[94mBack to the main menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp_v4_menu()
            break
        elif server_type == "2":
            hans_v4_menu()
            break
        elif server_type == "3":
            os.system("clear")
            main_menu()
            break
        else:
            print("Invalid choice.")


def icmp_v4_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmp + IPsec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mMethod 1[Server Address] \033[0m")
    print("2. \033[96mMethod 2[Icmp Address] \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            icmp_socat1_menu()
            break
        elif server_type == "2":
            icmp_socat2_menu()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_ipsec()
            break
        else:
            print("Invalid choice.")


# server address
def icmp_socat1_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmptunnel Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            start_ic_kharej3()
            break
        elif server_type == "2":
            start_ic_iran3()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_v4_menu()
            break
        else:
            print("Invalid choice.")


def install_icmp():
    display_notification("\033[93mInstalling \033[92mIcmptunnel\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_loading()

    ipv4_forward_status = subprocess.run(
        ["sysctl", "-n", "net.ipv4.ip_forward"], capture_output=True, text=True
    )
    if int(ipv4_forward_status.stdout) != 1:
        subprocess.run(["sysctl", "net.ipv4.ip_forward=1"])

    subprocess.run(
        ["sudo", "apt", "install", "-y", "git"], capture_output=True, text=True
    )

    if os.path.exists("/root/icmpv4"):
        shutil.rmtree("/root/icmpv4")

    clone_command = "git clone https://github.com/miyugundam/icmp.git icmpv4"
    clone_result = os.system(clone_command)
    if clone_result != 0:
        print("Error: Failed to clone Repo.")
        return

    if os.path.exists("/root/icmpv4"):
        os.chdir("/root/icmpv4")

        subprocess.run(
            ["sudo", "apt", "install", "-y", "net-tools"],
            capture_output=True,
            text=True,
        )
        subprocess.run(
            ["sudo", "apt", "install", "-y", "make"], capture_output=True, text=True
        )
        subprocess.run(
            ["sudo", "apt-get", "install", "-y", "libssl-dev"],
            capture_output=True,
            text=True,
        )
        subprocess.run(
            ["sudo", "apt", "install", "-y", "g++"], capture_output=True, text=True
        )

        subprocess.run(["make"], capture_output=True, text=True)

        os.chdir("..")
    else:
        display_error("\033[91micmp folder not found.\033[0m")
    pass


def icmp1_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "70.0.0.2"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def icmp2_cron_job():
    file_path = "/etc/hans.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def icmp_cron_job():
    file_path = "/etc/icmp.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def start_ic_kharej3():
    display_notification("\033[93mConfiguring \033[92mKharej\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()

    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/root/icmpv4/icmptunnel -s -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.1 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp1_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          70.0.0.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def icmp2_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "70.0.0.1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def start_ic_iran3():
    display_notification("\033[93mConfiguring \033[92mIRAN \033[93m...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/icmpv4")

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write(f"/root/icmpv4/icmptunnel {remote_ip} -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.2 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp2_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          70.0.0.2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# icmp address
def icmp_socat2_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmptunnel Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            start_ic2_kharej()
            break
        elif server_type == "2":
            start_ic2_iran()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_v4_menu()
            break
        else:
            print("Invalid choice.")


def start_ic2_kharej():
    display_notification("\033[93mConfiguring \033[92mKharej\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()

    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_kharej_icmp(psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()

    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/root/icmpv4/icmptunnel -s -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.1 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp1_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          70.0.0.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def start_ic2_iran():
    display_notification("\033[93mConfiguring \033[92mIRAN \033[93m...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_iran_icmp(psk)
    if not os.path.exists("/root/icmpv4"):
        install_icmp()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/icmpv4")

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write(f"/root/icmpv4/icmptunnel {remote_ip} -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.2 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    icmp_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp2_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          70.0.0.2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def hans_v4_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mHans + IPsec Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mMethod 1[Server Address] \033[0m")
    print("2. \033[96mMethod 2[Icmp Address] \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hans_V41()
            break
        elif server_type == "2":
            hans_V42()
            break
        elif server_type == "3":
            os.system("clear")
            icmp_ipsec()
            break
        else:
            print("Invalid choice.")


# server address
def hans_V41():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mHans Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hns_icmp_kharej1()
            break
        elif server_type == "2":
            hns_icmp_iran1()
            break
        elif server_type == "3":
            os.system("clear")
            hans_V41()
            break
        else:
            print("Invalid choice.")


def hanss_install_menu():
    display_notification("\033[93mInstalling \033[92mHans\033[93m ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_loading()

    ipv4_forward_status = subprocess.run(
        ["sysctl", "-n", "net.ipv4.ip_forward"], capture_output=True, text=True
    )
    if int(ipv4_forward_status.stdout) != 1:
        subprocess.run(["sysctl", "net.ipv4.ip_forward=1"])

    subprocess.run(
        [
            "wget",
            "https://sourceforge.net/projects/hanstunnel/files/source/hans-1.1.tar.gz",
        ],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        check=True,
    )
    subprocess.run(
        ["tar", "-xzf", "hans-1.1.tar.gz"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        check=True,
    )
    os.chdir("/root/hans-1.1")

    subprocess.run(["apt", "install", "-y", "make"], check=True)
    subprocess.run(["apt", "install", "-y", "g++"], check=True)
    subprocess.run(["make"], check=True)

    display_checkmark("\033[92mHans installed successfully!\033[0m")

    os.remove("/root/hans-1.1.tar.gz")
    pass


def icmp3_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "80.1.2.100"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def hns_icmp_kharej1():
    display_notification("\033[93mConfiguring Kharej ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )
    hans_directory = "/root/hans-1.1"

    os.chdir(hans_directory)
    os.system(f"./hans -s 80.1.2.0 -p azumi86chwan -d icmp")

    hans_kharej_command = f"{hans_directory}/hans -s 80.1.2.0 -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_kharej_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_kharej_command}\n")

    subprocess.run(
        ["chmod", "700", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp3_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          80.1.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def icmp4_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        result = subprocess.run(
            ["ping", "-c", "2", "80.1.2.1"], capture_output=True, text=True
        )
        if result.returncode == 0:
            print(result.stdout)
        else:
            print("\033[91mPinging failed:\033[0m", result.stderr)
    except subprocess.CalledProcessError as e:
        print("\033[91mPinging failed:\033[0m", e)


def hns_icmp_iran1():
    display_notification("\033[93mConfiguring IRAN ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    local_subnet = input("\033[93mEnter \033[92mIRAN\033[93m Subnet: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    remote_subnet = input("\033[93mEnter \033[92mkharej\033[93m Subnet: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_strongsw_icmp(local_ip, local_subnet, remote_ip, remote_subnet, psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/hans-1.1")
    os.system(f"./hans -c {remote_ip} -p azumi86chwan -d icmp")

    subprocess.call(["rm", "-f", "/etc/cron.d/hans"])

    hans_command = f"/root/hans-1.1/hans -c {remote_ip} -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_command}\n")
    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp4_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          80.1.2.100\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


# icmp address
def hans_V42():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mHans Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[96mIRAN \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            hns_icmp_kharej2()
            break
        elif server_type == "2":
            hns_icmp_iran2()
            break
        elif server_type == "3":
            os.system("clear")
            hans_V41()
            break
        else:
            print("Invalid choice.")


def config_hansk_icmp(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=80.1.2.1/32
  leftid=80.1.2.1
  right=80.1.2.100
  rightsubnet=80.1.2.100/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'80.1.2.100 80.1.2.1 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def config_hansi_icmp(psk):
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mInstalling IPSEC..\033[0m")
    install_process = subprocess.Popen(["sudo", "apt", "install", "strongswan", "-y"])
    install_process.wait()
    print("IPSEC Installation complete.")
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.conf"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "rm", "/etc/ipsec.secrets"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )

    with open("/etc/ipsec.conf", "w") as f:
        f.write(
            f"""config setup
##azumiisinyouarea
conn ipsecsit
  left=%defaultroute
  leftsubnet=80.1.2.100/32
  leftid=80.1.2.100
  right=80.1.2.1
  rightsubnet=80.1.2.1/32
  ike=aes256gcm16-sha512-ecp384!
  esp=aes256gcm16-sha512-ecp384!
  keyexchange=ikev2
  auto=start
  authby=secret
  keyingtries=%forever
  dpdaction=restart
  dpddelay=30s
  dpdtimeout=120s
  rekeymargin=3m
  rekeyfuzz=100%
  reauth=no"""
        )

    with open("/etc/ipsec.secrets", "w") as f:
        f.write(f'80.1.2.1 80.1.2.100 : PSK "{psk}"\n')
    permissions()
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan-starter"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "enable", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "systemctl", "restart", "strongswan"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )


def hns_icmp_kharej2():
    display_notification("\033[93mConfiguring Kharej ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")
    config_hansk_icmp(psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )
    hans_directory = "/root/hans-1.1"

    os.chdir(hans_directory)
    os.system(f"./hans -s 80.1.2.0 -p azumi86chwan -d icmp")

    hans_kharej_command = f"{hans_directory}/hans -s 80.1.2.0 -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_kharej_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_kharej_command}\n")

    subprocess.run(
        ["chmod", "700", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp3_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          80.1.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def hns_icmp_iran2():
    display_notification("\033[93mConfiguring IRAN ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    up_up()
    remote_ip = input("\033[93mEnter \033[92mkharej\033[93m IPV4 address: \033[0m")
    psk = input("\033[93mEnter the \033[92mSecret key\033[93m: \033[0m")

    config_hansi_icmp(psk)
    if not os.path.exists("/root/hans-1.1"):
        hanss_install_menu()
    subprocess.run(
        ["echo", "1", ">", "/proc/sys/net/ipv4/icmp_echo_ignore_all"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.chdir("/root/hans-1.1")
    os.system(f"./hans -c {remote_ip} -p azumi86chwan -d icmp")

    subprocess.call(["rm", "-f", "/etc/cron.d/hans"])

    hans_command = f"/root/hans-1.1/hans -c {remote_ip} -p azumi86chwan -d icmp"
    subprocess.run(
        ["sed", "-i", f"/{hans_command}/d", "/etc/hans.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=False,
    )

    if os.path.exists("/etc/hans.sh"):
        os.remove("/etc/hans.sh")

    with open("/etc/hans.sh", "w") as f:
        f.write(f"{hans_command}\n")
    icmp2_cron_job()

    display_checkmark("\033[92mCronjob added successfully!\033[0m")
    icmp4_ping()
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "          80.1.2.100\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")


def up_up():
    ulimit_setting = "ulimit -n 65535"
    bashrc_path = os.path.expanduser("~/.bashrc")

    with open(bashrc_path, "r") as f:
        existing_bashrc = f.read()

    if ulimit_setting not in existing_bashrc:
        with open(bashrc_path, "a") as f:
            f.write("\n")
            f.write(ulimit_setting)
            f.write("\n")

    sysctl_conf_path = "/etc/sysctl.conf"
    sysctl_params = [
        "net.core.rmem_max=26214400",
        "net.core.rmem_default=26214400",
        "net.core.wmem_max=26214400",
        "net.core.wmem_default=26214400",
        "net.core.netdev_max_backlog=2048",
    ]

    with open(sysctl_conf_path, "r") as f:
        existing_sysctl_conf = f.read()

    params_to_add = []
    for param in sysctl_params:
        if param not in existing_sysctl_conf:
            params_to_add.append(param)

    if params_to_add:
        with open(sysctl_conf_path, "a") as f:
            f.write("\n")
            f.write("\n".join(params_to_add))
            f.write("\n")
        try:
            subprocess.run(
                ["sudo", "sysctl", "-p"], stderr=subprocess.DEVNULL, check=True
            )
            display_checkmark("\033[92mIt is Done!\033[0m")
        except subprocess.CalledProcessError:
            print("\033[91mAn error occurred while setting it up.\033[0m")
    else:
        display_checkmark("\033[92mIt was already Done.\033[0m")


def icmp_uninstall():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmp Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mIcmpV4 Method 1 \033[0m")
    print("2. \033[96mHans Method 2 \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove2_icmp()
            break
        elif server_type == "2":
            remove2_hans()
            break
        elif server_type == "3":
            os.system("clear")
            remove_menu()
            break
        else:
            print("Invalid choice.")


def icmp_uninstall_later():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIcmp Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mNo IPsec \033[0m")
    print("2. \033[96m/w IPsec \033[0m")
    print("3. \033[94mBack to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_vxlan()
            break
        elif server_type == "2":
            remove_vxlansec()
            break
        elif server_type == "3":
            os.system("clear")
            remove_menu()
            break
        else:
            print("Invalid choice.")


def ipsecs3_uninstall():
    delete_cron1()
    delete_cron2()

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Erspan + \033[92mIpsec \033[93m+ Tunnels\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    devnull = open(os.devnull, "w")

    subprocess.run(
        "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
    )
    subprocess.run(
        "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
    )
    subprocess.run(
        "systemctl disable strongswan-starter > /dev/null 2>&1",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run(
        "systemctl stop strongswan-starter > /dev/null 2>&1",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run(
        "systemctl disable strongswan > /dev/null 2>&1",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run(
        "systemctl stop strongswan > /dev/null 2>&1",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run(
        "apt purge strongswan -y", shell=True, stdout=devnull, stderr=devnull
    )
    subprocess.run(
        "systemctl disable ping_espan.service > /dev/null 2>&1",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run(
        "systemctl stop ping_espan.service > /dev/null 2>&1",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run(
        "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run(
        "systemctl daemon-reload", shell=True, stdout=devnull, stderr=devnull
    )
    subprocess.run(
        "sudo ip link delete azumiespn > /dev/null",
        shell=True,
        stdout=devnull,
        stderr=devnull,
    )
    subprocess.run("apt purge strongswan -y", shell=True)

    devnull.close()

    display_checkmark("\033[92mUninstall completed!\033[0m")


def remove2_hans():
    os.system("clear")
    display_notification("\033[93mRemoving Hans ...\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    reset_icmp()
    ipsecs3_uninstall()
    espn_uninstall()
    try:
        if subprocess.call("test -f /etc/hans.sh", shell=True) == 0:
            subprocess.run("rm /etc/hans.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/hans.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            "rm /etc/systemd/system/azumifrps1.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)
        subprocess.run("ip link set dev icmp down > /dev/null", shell=True)
        subprocess.run("ip link set dev icmp down > /dev/null", shell=True)
        print("Progress: ", end="")

        try:

            lsof_process = subprocess.Popen(
                ["lsof", "/root/hans-1.1/hans"],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            )
            lsof_output, lsof_error = lsof_process.communicate()

            if lsof_output:
                pid = lsof_output.decode().split("\n")[1].split()[1]
                subprocess.run(["kill", pid])

            subprocess.run(["rm", "-rf", "/root/hans-1.1"])
        except FileNotFoundError:
            print("Error: Directory '/root/hans-1.1' does not exist.")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except Exception as e:
        print("An error occurred during uninstallation:", str(e))
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove2_icmp():
    os.system("clear")
    display_notification("\033[93mRemoving icmp...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    reset_icmp()
    ipsecs3_uninstall()
    espn_uninstall()
    try:
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/icmp.sh" | crontab -',
            shell=True,
        )
        subprocess.run("ip link set dev tun0 down > /dev/null", shell=True)
        subprocess.run("ip link set dev tun1 down > /dev/null", shell=True)
        subprocess.run("systemctl daemon-reload", shell=True)

        print("Progress: ", end="")

        try:
            lsof_process = subprocess.Popen(
                ["lsof", "-t", "/root/icmpv4/icmptunnel"],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            )
            lsof_output, lsof_error = lsof_process.communicate()

            if lsof_output:
                pids = lsof_output.decode().split("\n")[:-1]
                for pid in pids:
                    subprocess.run(["kill", pid])

            subprocess.run(["rm", "-rf", "/root/icmpv4"])
        except FileNotFoundError:
            print("Error: Directory '/root/icmpv4' does not exist.")

        subprocess.run(
            'crontab -l | grep -v "/bin/bash /etc/icmp.sh" | crontab -', shell=True
        )
        display_checkmark("\033[92mUninstall completed!\033[0m")

        if os.path.isfile("/etc/icmp.sh"):
            os.remove("/etc/icmp.sh")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def gre6tapespn_uninstall():
    delete_cron1()
    delete_cron2()
    remove_private()
    remove_gre6tap21()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Erspan + \033[92mGRE6tap Tunnel\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/spn.sh", shell=True) == 0:
            subprocess.run("rm /etc/spn.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/spn.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ping_espan.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_espan.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_espan.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("sudo ip link delete azumiespn > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def gre6test_uninstall():
    delete_cron1()
    delete_cron2()
    remove_private()
    remove_gre621()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Erspan + \033[92mGRE6 Tunnel\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/spn.sh", shell=True) == 0:
            subprocess.run("rm /etc/spn.sh", shell=True)
        if subprocess.call("test -f /etc/sys.sh", shell=True) == 0:
            subprocess.run("rm /etc/sys.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/spn.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ping_espan.sh", shell=True)

        subprocess.run(
            "systemctl disable ping_espan.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_espan.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("sudo ip link delete azumiespn > /dev/null", shell=True)
        subprocess.run("sudo ip link delete azumip6 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def espn_uninstall():
    delete_cron1()
    delete_cron2()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Erspan Tunnel\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/spn.sh", shell=True) == 0:
            subprocess.run("rm /etc/spn.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/spn.sh" | crontab - > /dev/null 2>&1',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ping_espan.sh > /dev/null 2>&1", shell=True)

        subprocess.run(
            "systemctl disable ping_espan.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_espan.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_espan.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload > /dev/null 2>&1", shell=True)

        subprocess.run("sudo ip link delete azumiespn > /dev/null 2>&1", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


## gre6tap remove


def gre6tapsec_remove():  # inja
    remove_private()
    remove_gre6tap21()
    ipsecs_uninstall_gre6tap()


def gre6tap_remove():
    remove_private()
    remove_gre6tap21()


####
def genx_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mGeneve\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve \033[0m")
    print("2. \033[93mGeneve + Native \033[0m")
    print("3. \033[96mGeneve + Gre6 + Native \033[0m")
    print("4. \033[92mGeneve + Gre6 + IPV4 \033[0m")
    print("5. \033[93mGeneve + IP6tnl + Gre6 + Native  \033[0m")
    print("6. \033[92mGeneve + IPsec  \033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genz_uninstall()
            break
        elif server_type == "2":
            genz_uninstall()
            break
        elif server_type == "3":
            gen2_uninstall()
            break
        elif server_type == "5":
            gen4_uninstall()
            break
        elif server_type == "6":
            remove_test()
            break
        elif server_type == "4":
            gen6_uninstall()
            break
        elif server_type == "0":
            clear()
            remove_menu()
            break
        else:
            print("Invalid choice.")


## gen ic
def reset_icmp():
    try:
        reset_ipv4 = False
        reset_ipv6 = False

        os.system("sysctl -w net.ipv4.icmp_echo_ignore_all=0")
        reset_ipv4 = True

        os.system("sudo sysctl -w net.ipv6.icmp.echo_ignore_all=0")
        reset_ipv6 = True

        if reset_ipv4 or reset_ipv6:
            display_checkmark("\033[92mICMP has been reset to default!\033[0m")
        else:
            display_notification("\033[93mICMP settings has been reset.\033[0m")
    except Exception as e:
        display_error("\033[91mAn error occurred: {}\033[0m".format(str(e)))


def install_icmp():
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_loading()

    subprocess.run(
        ["sudo", "tee", "/etc/resolv.conf"],
        input="nameserver 1.1.1.1\n",
        capture_output=True,
        text=True,
    )

    ipv4_forward_status = subprocess.run(
        ["sysctl", "net.ipv4.ip_forward"], capture_output=True, text=True
    )
    if "net.ipv4.ip_forward = 0" not in ipv4_forward_status.stdout:
        subprocess.run(["sudo", "sysctl", "-w", "net.ipv4.ip_forward=1"])

    ipv6_forward_status = subprocess.run(
        ["sysctl", "net.ipv6.conf.all.forwarding"], capture_output=True, text=True
    )
    if "net.ipv6.conf.all.forwarding = 0" not in ipv6_forward_status.stdout:
        subprocess.run(["sudo", "sysctl", "-w", "net.ipv6.conf.all.forwarding=1"])

    if os.path.exists("/root/icmpv4"):
        shutil.rmtree("/root/icmpv4")

    clone_command = "git clone https://github.com/miyugundam/icmp.git icmpv4"
    clone_result = os.system(clone_command)
    if clone_result != 0:
        print("Error: Failed to clone Repo.")
        return

    if os.path.exists("/root/icmpv4"):

        os.chdir("/root/icmpv4")

        subprocess.run(
            ["sudo", "apt", "install", "-y", "net-tools"],
            capture_output=True,
            text=True,
        )
        subprocess.run(
            ["sudo", "apt", "install", "-y", "make"], capture_output=True, text=True
        )
        subprocess.run(
            ["sudo", "apt-get", "install", "-y", "libssl-dev"],
            capture_output=True,
            text=True,
        )
        subprocess.run(
            ["sudo", "apt", "install", "-y", "g++"], capture_output=True, text=True
        )

        subprocess.run(["make"], capture_output=True, text=True)

        os.chdir("..")
    else:
        display_error("\033[91micmptunnel folder not found.\033[0m")


def up_up():
    ulimit_setting = "ulimit -n 65535"
    bashrc_path = os.path.expanduser("~/.bashrc")

    with open(bashrc_path, "r") as f:
        existing_bashrc = f.read()

    if ulimit_setting not in existing_bashrc:
        with open(bashrc_path, "a") as f:
            f.write("\n")
            f.write(ulimit_setting)
            f.write("\n")

    sysctl_conf_path = "/etc/sysctl.conf"
    sysctl_params = [
        "net.core.rmem_max=26214400",
        "net.core.rmem_default=26214400",
        "net.core.wmem_max=26214400",
        "net.core.wmem_default=26214400",
        "net.core.netdev_max_backlog=2048",
    ]

    with open(sysctl_conf_path, "r") as f:
        existing_sysctl_conf = f.read()

    params_to_add = []
    for param in sysctl_params:
        if param not in existing_sysctl_conf:
            params_to_add.append(param)

    if params_to_add:
        with open(sysctl_conf_path, "a") as f:
            f.write("\n")
            f.write("\n".join(params_to_add))
            f.write("\n")
        try:
            subprocess.run(
                ["sudo", "sysctl", "-p"], stderr=subprocess.DEVNULL, check=True
            )
            display_checkmark("\033[92mLimit has been Set!\033[0m")
        except subprocess.CalledProcessError:
            print("\033[91mAn error occurred setting it up.\033[0m")
    else:
        display_checkmark("\033[92mLimit Increase was already Done.\033[0m")


def ic_kharej():
    if not os.path.exists("/root/icmpv4"):
        install_icmp()
    up_up()
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mConfiguring Kharej ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")

    if os.path.exists("/etc/icmp.sh"):
        os.remove("/etc/icmp.sh")

    with open("/etc/icmp.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/root/icmpv4/icmptunnel -s -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.1 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp.sh")

    cron_job_command = "@reboot root /bin/bash /etc/icmp.sh\n"
    with open("/etc/cron.d/icmp-kharej", "a") as f:
        f.write(cron_job_command)

    subprocess.call("crontab -u root /etc/cron.d/icmp-kharej", shell=True)

    display_checkmark("\033[92mCronjob added successfully!\033[0m")


def ic_iran():
    if not os.path.exists("/root/icmpv4"):
        install_icmp()
    up_up()
    print("\033[93m──────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mConfiguring IRAN ...\033[0m")
    print("\033[93m──────────────────────────────────────────────────\033[0m")

    os.chdir("/root/icmpv4")

    server_ipv4 = input("\033[93mEnter \033[92mKharej\033[93m IPv4 address:\033[0m ")

    if os.path.exists("/etc/icmp-iran.sh"):
        os.remove("/etc/icmp-iran.sh")

    with open("/etc/icmp-iran.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write(f"/root/icmpv4/icmptunnel {server_ipv4} -d\n")
        f.write("/sbin/ifconfig tun0 70.0.0.2 netmask 255.255.255.0\n")

    subprocess.run(
        ["chmod", "700", "/etc/icmp-iran.sh"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.PIPE,
        check=True,
    )

    os.system("/bin/bash /etc/icmp-iran.sh")

    cron_job_command = "@reboot root /bin/bash /etc/icmp-iran.sh\n"
    with open("/etc/cron.d/icmp-iran", "a") as f:
        f.write(cron_job_command)

    subprocess.call("crontab -u root /etc/cron.d/icmp-iran", shell=True)

    display_checkmark("\033[92mCronjob added successfully!\033[0m")


def gen_ipicmp():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_icmpk_version1()
            break
        elif server_type == "2":
            geneve_icmpk_version2()
            break
        else:
            print("Invalid choice.")


def geneve_icmpk_version1():
    ic_kharej()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("70.0.0.1")
    ufw("70.0.0.2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "70.0.0.2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def geneve_icmpk_version2():
    ic_kharej()
    ufw("70.0.0.1")
    ufw("70.0.0.2")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "70.0.0.2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gen_ipicmpi():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_icmpi_version1()
            break
        elif server_type == "2":
            geneve_icmpi_version2()
            break
        else:
            print("Invalid choice.")


def geneve_icmpi_version1():
    ic_iran()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("70.0.0.1")
    ufw("70.0.0.2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "70.0.0.1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def geneve_icmpi_version2():
    ic_iran()
    ufw("70.0.0.1")
    ufw("70.0.0.2")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "70.0.0.1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def rmv_limit():
    display_notification("\033[93mRestoring Limit ..\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    ulimit_setting = "ulimit -n 65535"
    bashrc_path = os.path.expanduser("~/.bashrc")

    with open(bashrc_path, "r") as f:
        existing_bashrc = f.read()

    if ulimit_setting in existing_bashrc:
        existing_bashrc = existing_bashrc.replace(ulimit_setting, "")

        with open(bashrc_path, "w") as f:
            f.write(existing_bashrc)

    sysctl_conf_path = "/etc/sysctl.conf"
    sysctl_params = [
        "net.core.rmem_max=26214400",
        "net.core.rmem_default=26214400",
        "net.core.wmem_max=26214400",
        "net.core.wmem_default=26214400",
        "net.core.netdev_max_backlog=2048",
    ]

    with open(sysctl_conf_path, "r") as f:
        existing_sysctl_conf = f.read()

    params_to_remove = []
    for param in sysctl_params:
        if param in existing_sysctl_conf:
            params_to_remove.append(param)

    if params_to_remove:
        for param in params_to_remove:
            existing_sysctl_conf = existing_sysctl_conf.replace(param, "")

        with open(sysctl_conf_path, "w") as f:
            f.write(existing_sysctl_conf)

        try:
            subprocess.run(
                ["sudo", "sysctl", "-p"], stderr=subprocess.DEVNULL, check=True
            )
            display_checkmark("\033[92mLimit removal was Successful!\033[0m")
        except subprocess.CalledProcessError:
            print("\033[91mAn error occurred.\033[0m")
    else:
        display_checkmark("\033[92mNothin was found! moving on..\033[0m")


def remove_icmp():

    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving icmp...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    try:
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/icmp.sh" | crontab -',
            shell=True,
        )
        subprocess.run("ip link set dev tun0 down > /dev/null", shell=True)
        subprocess.run("ip link set dev tun1 down > /dev/null", shell=True)
        subprocess.run("apt install lsof -y", shell=True)
        subprocess.run("systemctl daemon-reload", shell=True)

        print("Progress: ", end="")

        try:
            lsof_process = subprocess.Popen(
                ["lsof", "-t", "/root/icmpv4/icmptunnel"],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            )
            lsof_output, lsof_error = lsof_process.communicate()

            if lsof_output:
                pids = lsof_output.decode().split("\n")[:-1]
                for pid in pids:
                    subprocess.run(["kill", pid])

            subprocess.run(["rm", "-rf", "/root/icmpv4"])
        except FileNotFoundError:
            print("Error: Directory 'icmp' does not exist.")
        except Exception as e:
            print("Error:", e)

        subprocess.run(
            'crontab -l | grep -v "/bin/bash /etc/icmp.sh" | crontab -', shell=True
        )
        subprocess.run(
            'crontab -l | grep -v "/bin/bash /etc/icmp-iran.sh" | crontab -', shell=True
        )
        display_checkmark("\033[92mICMPtunnel Uninstallation completed!\033[0m")

        if os.path.isfile("/etc/icmp.sh"):
            os.remove("/etc/icmp.sh")
        if os.path.isfile("/etc/icmp-iran.sh"):
            os.remove("/etc/icmp-iran.sh")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", e)


def ipsecs_uninstall_gre6():
    delete_cron1()
    delete_cron2()
    remove_private()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving GRE6 + \033[92mIpsec \033[93m+ Tunnels\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        subprocess.run(
            "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)

        subprocess.run("apt purge strongswan -y", shell=True)

        subprocess.run("systemctl daemon-reload", shell=True)

        devnull.close()
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def ipsecs_uninstall_gre6tap():
    delete_cron1()
    delete_cron2()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving GRE6tap + \033[92mIpsec \033[93m+ Tunnels\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        devnull = open(os.devnull, "w")
        subprocess.run(
            "sudo rm /etc/ipsec.conf", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "sudo rm /etc/ipsec.secrets", shell=True, stdout=devnull, stderr=devnull
        )
        subprocess.run(
            "systemctl disable strongswan-starter > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop strongswan-starter > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl disable strongswan > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop strongswan > /dev/null 2>&1", shell=True)

        subprocess.run("apt purge strongswan -y", shell=True)

        subprocess.run("systemctl daemon-reload", shell=True)

        devnull.close()
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def remove_gre6sec():
    remove_gre6()
    ipsecs_uninstall_gre6()


def remove_ipip6sec():
    remove_ipip6()
    ipsecs_uninstall_ipip()


def remove_ipip6():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mIPIP6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/ipip.sh", shell=True) == 0:
            subprocess.run("rm /etc/ipip.sh", shell=True)
        if subprocess.call("test -f /etc/private.sh", shell=True) == 0:
            subprocess.run("rm /etc/private.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipip.sh" | crontab -',
            shell=True,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private.sh" | crontab -',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_v6.sh", shell=True)
        sleep(1)
        subprocess.run("sudo rm /etc/ping_ip.sh", shell=True)

        subprocess.run("systemctl disable ping_v6.service > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop ping_v6.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v6.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl disable ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip.service > /dev/null 2>&1", shell=True
        )
        sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumip down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumip > /dev/null", shell=True)
        sleep(1)
        subprocess.run("ip link set dev azumi down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 3
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def i6to41_any():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93m6to4 \033[92m[Anycast]\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')

    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")

    if server_type == "1":
        i6to41_any_kharej()
    elif server_type == "2":
        i6to41_any_iran()
    elif server_type == "3":
        clear()
        multiserver_mnu()
    else:
        print("Invalid choice.")


def i6to41_any_kharej():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6to4 \033[92mKharej\033[93m  Menu\033[92m[Anycast]\033[0m"
    )
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')

    if (
        subprocess.run(["test", "-f", "/etc/6to4.sh"], capture_output=True).returncode
        == 0
    ):
        subprocess.run(["rm", "/etc/6to4.sh"])

    display_notification("\033[93mConfiguring Kharej..\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej IPv4\033[93m address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()

    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    with open("/etc/6to4.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe sit\n")
        f.write(
            "/sbin/ip tunnel add azumi6 mode sit remote any local {} ttl 255\n".format(
                local_ip
            )
        )
        set_mtu = input(
            "\033[93mDo you want to set \033[92m MTU?\033[93m (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
        )
        if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
            mtu_value = input(
                "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
            )
            f.write("/sbin/ip -6 link set dev azumi6 mtu {}\n".format(mtu_value))
        else:
            f.write("/sbin/ip -6 link set dev azumi6 mtu 1480\n")
        f.write("/sbin/ip link set dev azumi6 up\n")
        f.write("/sbin/ip -6 addr add {}/16 dev azumi6\n".format(prefix))
        f.write(
            "/sbin/ip -6 route add 2000::/3 via ::192.88.99.1 dev azumi6 metric 1\n"
        )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = input(
        "\033[93mHow many \033[92madditional IPs\033[93m do you need? \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    start_index = 3

    with open("/etc/6to4.sh", "a") as f:
        for i in range(start_index, start_index + int(num_ips)):
            ip_addr = "2002:{:02x}{:02x}:{:02x}{:02x}::{:02x}/16".format(
                *map(int, ipv4.split(".")), i
            )
            f.write("ip -6 addr add {} dev azumi6\n".format(ip_addr))

    display_notification("\033[93mAdding cronjob!\033[0m")

    config_file_path = "/etc/6to4.sh"

    subprocess.run(
        f"(crontab -l | grep -v -F '{config_file_path}') | crontab -",
        shell=True,
        check=True,
    )

    cronjob_command = (
        f"(crontab -l 2>/dev/null; echo '@reboot sh {config_file_path}') | crontab -"
    )
    subprocess.run(cronjob_command, shell=True, check=True)

    display_notification("\033[93mStarting 6to4...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    subprocess.run(["/bin/bash", "/etc/6to4.sh"])
    num_servers = int(
        input(
            "\033[93mEnter the \033[92mnumber\033[93m of \033[96mServers\033[93m[Ping Service]? \033[0m"
        )
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(num_servers):
        remote_ipv4 = input(
            f"\033[93mEnter \033[96mIPv4 address\033[93m of server \033[92m{i+1} [Ping Service]: \033[0m"
        )

        remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
            *map(int, remote_ipv4.split("."))
        )
        sleep(1)
        print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
        ping_result = subprocess.run(
            ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
        ).stdout.strip()
        print(ping_result)

        script_content = """#!/bin/bash

ip_address="{}"

max_pings=5

interval=2

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
       
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

        script_filename = f"/etc/ping_v6{i+1}.sh"
        with open(script_filename, "w") as f:
            f.write(script_content)

        subprocess.run(["chmod", "+x", script_filename])

        service_filename = f"/etc/systemd/system/ping_v6{i+1}.service"
        with open(service_filename, "w") as f:
            f.write("[Unit]\n")
            f.write(f"Description=Ping Service {i+1}\n")
            f.write("After=network.target\n")
            f.write("\n")
            f.write("[Service]\n")
            f.write(f"ExecStart=/bin/bash {script_filename}\n")
            f.write("Restart=always\n")
            f.write("\n")
            f.write("[Install]\n")
            f.write("WantedBy=multi-user.target\n")

        subprocess.run(["systemctl", "daemon-reload"])
        subprocess.run(["systemctl", "enable", f"ping_v6{i+1}.service"])
        subprocess.run(["systemctl", "start", f"ping_v6{i+1}.service"])
        sleep(1)
        subprocess.run(["systemctl", "restart", f"ping_v6{i+1}.service"])

        print(
            f"\033[92mPing service for server {i+1} has been added successfully!\033[0m"
        )
        print(
            "\033[93m─────────────────────────────────────────────────────────\033[0m"
        )

    display_checkmark("\033[92m6to4 Service has been added successfully!\033[0m")


##### saki _ gretap


def gree6_tunnel(remote_ip, local_ip):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


def gree6_kharej():
    remote_ip = "2002:831b::2"  # iran-ip
    local_ip = "2002:831b::1"  # kharej ip
    gree6_tunnel(remote_ip, local_ip)
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    ping_gre6_service()

    gre6_cronjob()


# sit kharej
def kharej_gree6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve + GRE Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print(" \033[93mConfiguring \033[92mKharej\033[93m server\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add 2002:831b::1/64 dev azumi\n")
        f.write("ip -6 route add 2002::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gree6_kharej()
    sleep(1)


##### IRAN gre6
def iran_ping():
    try:
        subprocess.run(
            ["ping", "-c", "2", "2002:831b::1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def gree6_iran_tunnel(remote_ip, local_ip):
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
        with open("/etc/gre6.sh", "a") as f:
            f.write(rt_command)
        subprocess.run(rt_command, shell=True, check=True)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


def gree6_iran():
    remote_ip = "2002:831b::1"  # kharej ip
    local_ip = "2002:831b::2"  # iran ip
    gree6_iran_tunnel(remote_ip, local_ip)

    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)

    iran_gre6_service()

    gre6_cronjob()


# sit iran
def iran_gree6_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve + GRE Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mConfiguring \033[92mIran\033[93m server\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "sit",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe sit\n")
        f.write(
            f"ip tunnel add azumi mode sit remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip link set dev azumi up\n")
        f.write("ip addr add 2002:831b::2/64 dev azumi\n")
        f.write("ip -6 route add 2002::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gree6_iran()
    sleep(1)


def genf_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGR6 + Geneve Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGRE + Native Geneve\033[0m")
    print("2. \033[96mIP6tnl + GRE + Native Geneve\033[0m")
    print("3. \033[93mGRE + IPV4 Geneve\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genfm_ip()
            break
        elif server_type == "2":
            genf3_ip()
            break
        elif server_type == "3":
            genf5_ip()
            break
        elif server_type == "0":
            clear()
            genz_ip()
            break
        else:
            print("Invalid choice.")


# sit gre gen
def kharej_gree61_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve + GRE Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print(" \033[93mConfiguring \033[92mKharej\033[93m server\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufw("2002:831b::2")
    ufw("2002:831b::1")

    subprocess.run(
        [
            "ip",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "ip6ip6",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::1/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumi mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 link set dev azumi up\n")
        f.write("ip -6 addr add 2002:831b::1/64 dev azumi\n")
        f.write("ip -6 route add 2002::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    run_ping()
    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::2"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()
    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gree61_kharej1()
    sleep(1)


def iran_gree61_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve + GRE Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mConfiguring \033[92mIran\033[93m server\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    if os.path.isfile("/etc/private.sh"):
        os.remove("/etc/private.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufw("2002:831b::2")
    ufw("2002:831b::1")

    subprocess.run(
        [
            "ip",
            "-6",
            "tunnel",
            "add",
            "azumi",
            "mode",
            "ip6ip6",
            "remote",
            remote_ip,
            "local",
            local_ip,
            "ttl",
            "255",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["ip", "-6", "link", "set", "dev", "azumi", "up"], stdout=subprocess.DEVNULL
    )

    initial_ip = "2002:831b::2/64"
    subprocess.run(
        ["ip", "addr", "add", initial_ip, "dev", "azumi"], stdout=subprocess.DEVNULL
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/private.sh", "w") as f:
        f.write("/sbin/modprobe ipip\n")
        f.write(
            f"ip -6 tunnel add azumi mode ip6ip6 remote {remote_ip} local {local_ip} ttl 255\n"
        )
        f.write("ip -6 link set dev azumi up\n")
        f.write("ip -6 addr add 2002:831b::2/64 dev azumi\n")
        f.write("ip -6 route add 2002::/16 dev azumi\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [6to4]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumi mtu {mtu_value}\n"
        with open("/etc/private.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mPrivate ip added successfully!\033[0m")
    file_path = "/etc/private.sh"
    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)

    sleep(1)
    add_cron_job()

    display_checkmark("\033[92mkeepalive service Configured!\033[0m")
    iran_ping()

    sleep(1)

    script_content1 = """#!/bin/bash


ip_address="2002:831b::1"

max_pings=5

interval=2

while true
do
    
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_v6.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_v6.sh", 0o755)
    ping_v6_service()

    display_notification("\033[93mConfiguring...\033[0m")
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gree61_iran1()
    sleep(1)


def gree61_kharej1_tunnel():
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote 2002:831b::2 local 2002:831b::1 ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


def gree61_kharej1():
    gree61_kharej1_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    gre6_cronjob()


def gree61_iran1_tunnel():
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote 2002:831b::1 local 2002:831b::2 ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


def gree61_iran1():
    gree61_iran1_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    gre6_cronjob()


def genf3_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mNative \033[93m+\033[92m Gre6 + IP6tnl \033[93mMenu\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen1_ipger()
            break
        elif server_type == "2":
            gen1_ipgeri()
            break
        elif server_type == "3":
            clear()
            genf_ip()
            break
        else:
            print("Invalid choice.")


def gen1_ipger():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_gerk1_version1()
            break
        elif server_type == "2":
            geneve_gerk1_version2()
            break
        else:
            print("Invalid choice.")


def geneve_gerk1_version1():
    kharej_gree61_menu()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def geneve_gerk1_version2():
    kharej_gree61_menu()

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gen1_ipgeri():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_geri1_version1()
            break
        elif server_type == "2":
            geneve_geri1_version2()
            break
        else:
            print("Invalid choice.")


def geneve_geri1_version1():
    iran_gree61_menu()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def geneve_geri1_version2():
    iran_gree61_menu()

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## method 1
def genfm_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGR6 + Geneve Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mMethod 1 [no route]\033[0m")
    print("2. \033[93mMethod 2 [/w route]\033[0m")
    print("0. \033[91mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genf1_ip()
            break
        elif server_type == "2":
            genf12_ip()
            break
        elif server_type == "0":
            clear()
            genf_ip()
            break
        else:
            print("Invalid choice.")


def genf12_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mNative \033[93m+\033[92m Gre6 \033[93mM[2]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genr_ipger()
            break
        elif server_type == "2":
            genr_ipgeri()
            break
        elif server_type == "3":
            clear()
            genf_ip()
            break
        else:
            print("Invalid choice.")


def genr_ipger():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_gerkr_version1()
            break
        elif server_type == "2":
            geneve_gerkr_version2()
            break
        else:
            print("Invalid choice.")


def gree6r_kharej1_tunnel():
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufw(remote_ip)
    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::1\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)

    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def gree6r_kharej1():
    gree6r_kharej1_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    gre6_cronjob()


def geneve_gerkr_version1():
    gree6r_kharej1()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def geneve_gerkr_version2():
    gree6r_kharej1()

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def genr_ipgeri():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_gerir_version1()
            break
        elif server_type == "2":
            geneve_gerir_version2()
            break
        else:
            print("Invalid choice.")


def gree6r_iran1_tunnel():
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufw(remote_ip)
    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    answer = input(
        "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
    )
    if answer.lower() in ["yes", "y"]:
        interface = ipv6_int()
        if interface is None:
            print("\033[91mError: No network interface with IPv6 address\033[0m")
        else:
            print("Interface:", interface)
            rt_command = "ip -6 route replace default via fe80::1 dev {} src 2002:831a::2\n".format(
                interface
            )
            with open("/etc/gre6.sh", "a") as f:
                f.write(rt_command)
    else:
        print("Skipping changing the default route.")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
    sleep(1)
    subprocess.run(f"bash {file_path}", shell=True, check=True)


def gree6r_iran1():
    gree6r_iran1_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    gre6_cronjob()


def geneve_gerir_version1():
    gree6r_iran1()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def geneve_gerir_version2():
    gree6r_iran1()

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def genf1_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mNative \033[93m+\033[92m Gre6 \033[93mM[1]\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_ipger()
            break
        elif server_type == "2":
            gen_ipgeri()
            break
        elif server_type == "3":
            clear()
            genf_ip()
            break
        else:
            print("Invalid choice.")


def genf2_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve + \033[96mIPV4 \033[93m+\033[92m Gre6 \033[93mMenu\033[0m"
    )
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            genf5_ip()
            break
        elif server_type == "2":
            gen5_ipgeri()
            break
        elif server_type == "3":
            clear()
            genf_ip()
            break
        else:
            print("Invalid choice.")


def genkh_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "66.200.2.1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def genir_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "66.200.1.1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_kh_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_sys.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_gen.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_gen.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_gen.service"])


def gen_job():
    file_path = "/etc/sys.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ufw(ip_address):
    subprocess.run(["sudo", "ufw", "allow", "from", ip_address])


def ufwport(port):
    subprocess.run(["sudo", "ufw", "allow", port])


def ufwr():
    subprocess.run(["sudo", "ufw", "reload"])


def ipv4_address():
    result = subprocess.run(
        ["curl", "-s", "https://ipinfo.io/ip"], capture_output=True, text=True
    )
    return result.stdout.strip()


def kharej1_gen_menu():
    kharej_gree6_menu()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")
    ufw("2002:831b::1")
    ufw("2002:831b::2")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m Configuring Kharej server Geneve\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    if os.path.isfile("/etc/sys.sh"):
        os.remove("/etc/sys.sh")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()
    genkh_ping()
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content1 = """#!/bin/bash


ip_address="66.200.2.1"


max_pings=5


interval=2


while true
do
   
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content1)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Geneve Configuration Completed!\033[0m")


def iran1_gen_menu():
    iran_gree6_menu()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")
    ufw("2002:831b::1")
    ufw("2002:831b::2")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m Configuring Iran server Geneve\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    if os.path.isfile("/etc/sys.sh"):
        os.remove("/etc/sys.sh")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )

    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")
    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()
    genir_ping()
    sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash


ip_address="66.200.1.1"


max_pings=5


interval=2


while true
do

    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Geneve Configuration Completed!\033[0m")


def genf5_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93mGeneve +  \033[96mIPV4 \033[93m+\033[92m Gre6 \033[93mMenu\033[0m"
    )
    print('\033[92m "-"\033[93m═══════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen5_ipger()
            break
        elif server_type == "2":
            gen5_ipgeri()
            break
        elif server_type == "3":
            clear()
            genf_ip()
            break
        else:
            print("Invalid choice.")


def gen5_ipger():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharej1_gen_menu()
            break
        elif server_type == "2":
            geneve_gerk6_version2()
            break
        else:
            print("Invalid choice.")


def geneve_gerk6_version2():
    kharej_gree6_menu()
    ufw("2002:831a::1")
    ufw("2002:831a::2")
    ufw("2002:831b::1")
    ufw("2002:831b::2")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gen5_ipgeri():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            iran1_gen_menu()
            break
        elif server_type == "2":
            geneve_geri5_version2()
            break
        else:
            print("Invalid choice.")


def geneve_geri5_version2():
    iran_gree6_menu()
    ufw("2002:831a::1")
    ufw("2002:831a::2")
    ufw("2002:831b::1")
    ufw("2002:831b::2")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


## test n gre
def gree6_kharej1_tunnel():
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mKharej\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufw(remote_ip)
    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::1/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


def gree6_kharej1():
    gree6_kharej1_tunnel()
    ip_address = "2002:831a::2"  # iranip
    max_pings = 3
    interval = 2
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    create_ping_script(ip_address, max_pings, interval)
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    ping_gre6_service()
    gre6_cronjob()


def gree6_iran1_tunnel():
    file_path = "/etc/gre6.sh"

    if os.path.exists(file_path):
        os.remove(file_path)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    remote_ip = input(
        "\033[93mEnter \033[92mKharej\033[93m IPV6 address [\033[92mNative\033[93m or\033[96m Tunnelbroker\033[93m]: \033[0m"
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")
    ufw(remote_ip)
    command = f"echo '/sbin/modprobe ip6_gre' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 tunnel add azumig6 mode ip6gre remote {remote_ip} local {local_ip} ttl 255' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 addr add 2002:831a::2/64 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip link set azumig6 up' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"echo 'ip -6 route add 2002::/16 dev azumig6' >> {file_path}"
    subprocess.run(command, shell=True, check=True)

    command = f"chmod +x {file_path}"
    subprocess.run(command, shell=True, check=True)
    subprocess.run(f"bash {file_path}", shell=True, check=True)

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [GRE6]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )
    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumig6 mtu {mtu_value}\n"
        with open("/etc/gre6.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    sleep(1)


def gree6_iran1():
    gree6_iran1_tunnel()
    ip_address = "2002:831a::1"  # kharejip
    max_pings = 3
    interval = 2
    iran_ping_script(ip_address, max_pings, interval)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    ping_result = subprocess.run(
        ["ping6", "-c", "2", ip_address], capture_output=True, text=True
    ).stdout.strip()
    print(ping_result)
    iran_gre6_service()
    gre6_cronjob()


def gen_ipger():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_gerk_version1()
            break
        elif server_type == "2":
            geneve_gerk_version2()
            break
        else:
            print("Invalid choice.")


def check_gre6():
    with open("/etc/gre6.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre61():
    with open("/etc/gre61.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre62():
    with open("/etc/gre62.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre63():
    with open("/etc/gre63.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre64():
    with open("/etc/gre64.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre65():
    with open("/etc/gre65.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre66():
    with open("/etc/gre66.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre67():
    with open("/etc/gre67.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre68():
    with open("/etc/gre68.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre69():
    with open("/etc/gre69.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def check_gre610():
    with open("/etc/gre610.sh", "r") as file:
        lines = file.readlines()
        for line in lines:
            if "azumig6" in line and "ip6gretap" in line:
                return "gre6tap"
            elif "azumig6" in line and "ip6gre" in line:
                return "gre6"
    return "unknown"


def remote_extraction(file_path):
    with open(file_path, "r") as file:
        content = file.read()
        match = re.search(r"remote\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", content)
        if match:
            return match.group(1)
    return None


def interface_ex(interface):
    output = subprocess.run(
        ["ip", "a", "show", interface], capture_output=True, text=True
    )
    return output.returncode == 0


def interface_check(interface):
    output = subprocess.run(
        ["ip", "a", "show", interface], capture_output=True, text=True
    )
    if output.returncode == 0:
        if re.search(r"state (UP|UNKNOWN)", output.stdout):
            return "online"
    return "offline"


def ipsec_secret():
    try:
        with open("/etc/ipsec.secrets", "r") as file:
            lines = file.readlines()
            for line in lines:
                if "PSK" in line:
                    secret_key = line.split('"')[1]
                    return secret_key.strip()
    except FileNotFoundError:
        pass

    return "Not found"


def checktype(file_path):
    with open(file_path, "r") as file:
        contents = file.read()
        if "::2/64" in contents:
            return "Kharej"
        elif "::1/64" in contents:
            return "IRAN"


def checktype3(file_path):
    with open(file_path, "r") as file:
        contents = file.read()
        if "::2/64" in contents:
            return "IRAN"
        elif "::1/64" in contents:
            return "KHAREJ"


def checktypegen2(file_path):
    with open(file_path, "r") as file:
        contents = file.read()
        if "::2/16" in contents:
            return "IRAN"
        elif "::1/16" in contents:
            return "KHAREJ"


def checktypegen(file_path):
    with open(file_path, "r") as file:
        contents = file.read()
        if "::2/16" in contents:
            return "Kharej"
        elif "::1/16" in contents:
            return "IRAN"

        elif (
            "sudo ip addr add 66.200.2.1/32" in contents
            or "sudo ip addr add 80.200.1.2/32" in contents
        ):
            return "Kharej"
        elif "sudo ip addr add 66.200.1.1/32" in contents:
            return "IRAN"
    return None


def checktype2(path):
    with open(path, "r") as file:
        contents = file.read()
        if "::2/16" in contents:
            return "Kharej"
        elif "::1/16" in contents:
            return "IRAN"
    return None


def multi_status():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mMulti Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭─────────────────────────────────────────────────╮\033[0m")
    print("\033[93mYou are viewing the status of your current tunnels:\033[0m")

    interfaces = [
        "azumi1",
        "azumi2",
        "azumi3",
        "azumi4",
        "azumi5",
        "azumi6",
        "azumi7",
        "azumi8",
        "azumi9",
        "azumip1",
        "azumip2",
        "azumip3",
        "azumip4",
        "azumip5",
        "azumip6",
        "azumip7",
        "azumip8",
        "azumip9",
        "azumip10",
        "azumig61",
        "azumig62",
        "azumig63",
        "azumig64",
        "azumig65",
        "azumig66",
        "azumig67",
        "azumig68",
        "azumig69",
        "azumig610",
        "azumigen1",
        "azumigen2",
        "azumigen3",
        "azumigen4",
        "azumigen5",
        "azumi10",
    ]

    active_int = []
    for interface in interfaces:
        if interface_ex(interface):
            status = interface_check(interface)
            if status == "online":
                active_int.append(interface)

    if not active_int:
        print(" No Interfaces available.")
    elif "azumigen5" in active_int and "azumig65" in active_int:
        with open("/etc/private5.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                print(
                    "\033[93m─────────────────────────────────────────────────\033[0m"
                )
                print(f" \033[97mIRAN SERVER \033[0m")
            else:
                print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumig65, azumigen5\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGRE6 Geneve\033[0m")
        with open("/etc/private5.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                if "azumi5" in active_int and "azumi4" in active_int:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m5 \033[92mOnline\033[0m"
                    )
            else:
                if "azumi5" in active_int and "azumi4" in active_int:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 5 \033[92mOnline\033[0m"
                    )
        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 6):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    with open("/etc/private5.sh", "r") as file:
                        contents = file.read()

                    match = re.search(r"::2/64", contents)
                    if match:
                        if match.start() < contents.index("::1/64"):
                            print(
                                f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )
                        else:
                            print(
                                f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )

    elif "azumigen4" in active_int and "azumig64" in active_int:
        with open("/etc/private4.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                print(f" \033[97mIRAN SERVER \033[0m")
            else:
                print(f" \033[97mKHAREJ SERVER \033[0m")
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumig64, azumigen4\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGRE6 Geneve\033[0m")
        with open("/etc/private4.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                if "azumi4" in active_int and "azumi3" in active_int:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m4 \033[92mOnline\033[0m"
                    )
            else:
                if "azumi4" in active_int and "azumi3" in active_int:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 4 \033[92mOnline\033[0m"
                    )
        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 5):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    with open("/etc/private4.sh", "r") as file:
                        contents = file.read()

                    match = re.search(r"::2/64", contents)
                    if match:
                        if match.start() < contents.index("::1/64"):
                            print(
                                f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )
                        else:
                            print(
                                f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )

    elif "azumigen3" in active_int and "azumig63" in active_int:
        with open("/etc/private3.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                print(f" \033[97mIRAN SERVER \033[0m")
            else:
                print(f" \033[97mKHAREJ SERVER \033[0m")
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumig63, azumigen3\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGRE6 Geneve\033[0m")
        with open("/etc/private3.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                if "azumi3" in active_int and "azumi2" in active_int:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m3 \033[92mOnline\033[0m"
                    )
            else:
                if "azumi3" in active_int and "azumi2" in active_int:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 3 \033[92mOnline\033[0m"
                    )
        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 4):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    with open("/etc/private3.sh", "r") as file:
                        contents = file.read()

                    match = re.search(r"::2/64", contents)
                    if match:
                        if match.start() < contents.index("::1/64"):
                            print(
                                f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )
                        else:
                            print(
                                f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )

    elif "azumigen2" in active_int and "azumig62" in active_int:
        with open("/etc/private2.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                print(f" \033[97mIRAN SERVER \033[0m")
            else:
                print(f" \033[97mKHAREJ SERVER \033[0m")
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumig62, azumigen2\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGRE6 Geneve\033[0m")
        with open("/etc/private2.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                if "azumi2" in active_int and "azumi1" in active_int:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m2 \033[92mOnline\033[0m"
                    )
            else:
                if "azumi2" in active_int and "azumi1" in active_int:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                    )
                else:
                    print(
                        " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 2 \033[92mOnline\033[0m"
                    )
        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 3):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    with open("/etc/private2.sh", "r") as file:
                        contents = file.read()

                    match = re.search(r"::2/64", contents)
                    if match:
                        if match.start() < contents.index("::1/64"):
                            print(
                                f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )
                        else:
                            print(
                                f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )

    elif "azumigen1" in active_int and "azumig61" in active_int:
        with open("/etc/private1.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                print(f" \033[97mIRAN SERVER \033[0m")
            else:
                print(f" \033[97mKHAREJ SERVER \033[0m")
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumig61, azumigen1\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGRE6 Geneve\033[0m")
        with open("/etc/private1.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):

                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel \033[92mOnline\033[0m"
                )
            else:

                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 1 \033[92mOnline\033[0m"
                )
        print("\033[93m─────────────────────────────────────────────────\033[0m")
        private_files = ["/etc/private1.sh"]
        for private_file in private_files:
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    with open("/etc/private1.sh", "r") as file:
                        contents = file.read()

                    match = re.search(r"::2/64", contents)
                    if match:
                        if match.start() < contents.index("::1/64"):
                            print(
                                f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )
                        else:
                            print(
                                f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )

    elif "azumig610" in active_int and "azumi10" in active_int:
        gre6_method10 = check_gre610()
        if gre6_method10 == "gre6tap":
            with open("/etc/private10.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi10, azumig610\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private10.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi10" in active_int and "azumi9" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m10 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi10" in active_int and "azumi9" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 10 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 11):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private10.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method10 == "gre6":
            with open("/etc/private10.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi10, azumig610\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private10.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi10" in active_int and "azumi9" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m10 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi10" in active_int and "azumi9" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 10 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 11):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private10.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig69" in active_int and "azumi9" in active_int:
        gre6_method9 = check_gre69()
        if gre6_method9 == "gre6tap":
            with open("/etc/private9.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi9, azumig69\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private9.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi9" in active_int and "azumi8" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m9 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi9" in active_int and "azumi8" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 9 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 10):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private9.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method9 == "gre6":
            with open("/etc/private9.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi9, azumig69\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private9.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi9" in active_int and "azumi8" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m9 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi9" in active_int and "azumi8" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 9 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 10):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private9.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig68" in active_int and "azumi8" in active_int:
        gre6_method8 = check_gre68()
        if gre6_method8 == "gre6tap":
            with open("/etc/private8.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi8, azumig68\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private8.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi8" in active_int and "azumi7" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m8 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi8" in active_int and "azumi7" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 8 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 9):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private8.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method8 == "gre6":
            with open("/etc/private8.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi8, azumig68\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private8.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi8" in active_int and "azumi7" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m8 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi8" in active_int and "azumi7" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 8 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 9):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private8.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig67" in active_int and "azumi7" in active_int:
        gre6_method7 = check_gre67()
        if gre6_method7 == "gre6tap":
            with open("/etc/private7.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi7, azumig67\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private7.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi7" in active_int and "azumi6" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m7 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi7" in active_int and "azumi6" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 7 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 8):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private7.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method7 == "gre6":
            with open("/etc/private7.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi7, azumig67\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private7.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi7" in active_int and "azumi6" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m7 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi7" in active_int and "azumi6" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 7 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 8):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private7.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig66" in active_int and "azumi6" in active_int:
        gre6_method6 = check_gre66()
        if gre6_method6 == "gre6tap":
            with open("/etc/private6.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi6, azumig66\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private6.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi6" in active_int and "azumi5" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m6 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi6" in active_int and "azumi5" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 6 \033[92mOnline\033[0m"
                        )

            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 7):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private6.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method6 == "gre6":
            with open("/etc/private6.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi6, azumig66\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private6.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi6" in active_int and "azumi5" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m6 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi6" in active_int and "azumi5" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 6 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 7):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private6.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig65" in active_int and "azumi5" in active_int:
        gre6_method5 = check_gre65()
        if gre6_method5 == "gre6tap":
            with open("/etc/private5.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi5, azumig65\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private5.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi5" in active_int and "azumi4" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m5 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi5" in active_int and "azumi4" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 5 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 6):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private5.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method5 == "gre6":
            with open("/etc/private5.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi5, azumig65\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private5.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi5" in active_int and "azumi4" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m5 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi5" in active_int and "azumi4" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 5 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 6):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private5.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig64" in active_int and "azumi4" in active_int:
        gre6_method4 = check_gre64()
        if gre6_method4 == "gre6tap":
            with open("/etc/private4.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi4, azumig64\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private4.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi4" in active_int and "azumi3" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m4 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi4" in active_int and "azumi3" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 4 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 5):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private4.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method4 == "gre6":
            with open("/etc/private4.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi4, azumig64\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private4.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi4" in active_int and "azumi3" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m4 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi4" in active_int and "azumi3" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 4 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 5):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private4.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig63" in active_int and "azumi3" in active_int:
        gre6_method3 = check_gre63()
        if gre6_method3 == "gre6tap":
            with open("/etc/private3.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi3, azumig63\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private3.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi3" in active_int and "azumi2" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m3 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi3" in active_int and "azumi2" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 3 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 4):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private3.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method3 == "gre6":
            with open("/etc/private3.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi3, azumig63\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private3.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi3" in active_int and "azumi2" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m3 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi3" in active_int and "azumi2" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 3 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 4):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private3.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                        else:
                            print(
                                f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )

    elif "azumig62" in active_int and "azumi2" in active_int:
        gre6_method2 = check_gre62()
        if gre6_method2 == "gre6tap":
            with open("/etc/private2.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi2, azumig62\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private2.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi2" in active_int and "azumi1" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m2 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi2" in active_int and "azumi1" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 2 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 3):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private2.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method2 == "gre6":
            with open("/etc/private2.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi2, azumig62\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private2.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi2" in active_int and "azumi1" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m2 \033[92mOnline\033[0m"
                        )
                else:
                    if "azumi2" in active_int and "azumi1" in active_int:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 2 \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 3):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private2.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumig61" in active_int and "azumi1" in active_int:
        gre6_method1 = check_gre61()
        if gre6_method1 == "gre6tap":
            with open("/etc/private1.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi1, azumig61\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            with open("/etc/private1.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi1" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m1 \033[97local Tunnel \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 2):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private1.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

        elif gre6_method1 == "gre6":
            with open("/etc/private1.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    print(f" \033[97mIRAN SERVER \033[0m")
                else:
                    print(f" \033[97mKHAREJ SERVER \033[0m")
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumi1, azumig61\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            with open("/etc/private1.sh", "r") as file:
                contents = file.read()

            match = re.search(r"::2/64", contents)
            if match:
                if match.start() < contents.index("::1/64"):
                    if "azumi1" in active_int:
                        print(
                            " \033[92mIRAN \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel \033[92mOnline\033[0m"
                        )
                    else:
                        print(
                            " \033[92mKharej \033[97mStatus  : \033[96m1 \033[97local Tunnel \033[92mOnline\033[0m"
                        )
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            for i in range(1, 2):
                private_file = f"/etc/private{i}.sh"
                if os.path.exists(private_file):
                    remote_ip = remote_extraction(private_file)
                    if remote_ip:
                        with open("/etc/private1.sh", "r") as file:
                            contents = file.read()

                        match = re.search(r"::2/64", contents)
                        if match:
                            if match.start() < contents.index("::1/64"):
                                print(
                                    f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )
                            else:
                                print(
                                    f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                                )

    elif "azumip10" in active_int and "azumi10" in active_int:
        with open("/etc/private10.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip10, azumi10\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip10" in active_int and "azumip9" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m10 \033[92mOnline\033[0m"
                )
        else:
            if "azumip10" in active_int and "azumip9" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 10 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 11):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip9" in active_int and "azumi9" in active_int:
        with open("/etc/private9.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip9, azumi9\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip9" in active_int and "azumip8" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m9 \033[92mOnline\033[0m"
                )
        else:
            if "azumip9" in active_int and "azumip8" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 9 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 10):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip8" in active_int and "azumi8" in active_int:
        with open("/etc/private8.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip8, azumi8\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip8" in active_int and "azumip7" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m8 \033[92mOnline\033[0m"
                )
        else:
            if "azumip8" in active_int and "azumip7" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 8 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 9):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip7" in active_int and "azumi7" in active_int:
        with open("/etc/private7.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip7, azumi7\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip7" in active_int and "azumip6" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m7 \033[92mOnline\033[0m"
                )
        else:
            if "azumip7" in active_int and "azumip6" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 7 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 8):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip6" in active_int and "azumi6" in active_int:
        with open("/etc/private6.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip6, azumi6\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip6" in active_int and "azumip5" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m6 \033[92mOnline\033[0m"
                )
        else:
            if "azumip6" in active_int and "azumip5" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 6 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 7):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip5" in active_int and "azumi5" in active_int:
        with open("/etc/private5.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip5, azumi5\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip5" in active_int and "azumip4" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m5 \033[92mOnline\033[0m"
                )
        else:
            if "azumip5" in active_int and "azumip4" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 5 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 6):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip4" in active_int and "azumi4" in active_int:
        with open("/etc/private4.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip4, azumi4\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip4" in active_int and "azumip3" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m4 \033[92mOnline\033[0m"
                )
        else:
            if "azumip4" in active_int and "azumip3" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 4 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 5):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip3" in active_int and "azumi3" in active_int:
        with open("/etc/private3.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip3, azumi3\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip3" in active_int and "azumip2" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m3 \033[92mOnline\033[0m"
                )
        else:
            if "azumip3" in active_int and "azumip2" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 3 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 4):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip2" in active_int and "azumi2" in active_int:
        with open("/etc/private2.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip2, azumi2\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip2" in active_int and "azumip1" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m2 \033[92mOnline\033[0m"
                )
        else:
            if "azumip2" in active_int and "azumip1" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 2 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 3):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumip1" in active_int and "azumi1" in active_int:
        with open("/etc/private1.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print("\033[93m─────────────────────────────────────────────────\033[0m")
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names examples:\033[96m azumip2, azumi2\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")

        if iran_server:
            if "azumip1" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel\033[96m \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 2):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif os.path.exists("/etc/6to4.sh") and "azumi6" in active_int:
        with open("/etc/6to4.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/16", contents)
        if match:
            if match.start() < contents.index("::1/16"):
                print(f" \033[97mIRAN SERVER \033[0m")
            else:
                print(f" \033[97mKHAREJ SERVER \033[0m")
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi6\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6to4 Sit\033[0m")

    elif "azumi10" in active_int:
        with open("/etc/private10.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi10\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi10" in active_int and "azumi9" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m10 \033[92mOnline\033[0m"
                )
        else:
            if "azumi10" in active_int and "azumi9" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m10 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 10 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 11):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi9" in active_int:
        with open("/etc/private9.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi9\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi9" in active_int and "azumi8" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m9 \033[92mOnline\033[0m"
                )
        else:
            if "azumi9" in active_int and "azumi8" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m9 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 9 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 10):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi8" in active_int:
        with open("/etc/private8.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi8\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi8" in active_int and "azumi7" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m8 \033[92mOnline\033[0m"
                )
        else:
            if "azumi8" in active_int and "azumi7" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m8 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 8 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 9):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi7" in active_int:
        with open("/etc/private7.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi7\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi7" in active_int and "azumi6" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m7 \033[92mOnline\033[0m"
                )
        else:
            if "azumi7" in active_int and "azumi6" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m7 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 7 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 8):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi6" in active_int:
        with open("/etc/private6.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi6\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi6" in active_int and "azumi5" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m6 \033[92mOnline\033[0m"
                )
        else:
            if "azumi6" in active_int and "azumi5" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m6 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 6 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 7):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi5" in active_int:
        with open("/etc/private5.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi5\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi5" in active_int and "azumi4" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m5 \033[92mOnline\033[0m"
                )
        else:
            if "azumi5" in active_int and "azumi4" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 5 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 6):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi4" in active_int:
        with open("/etc/private4.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi4\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi4" in active_int and "azumi3" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m4 \033[92mOnline\033[0m"
                )
        else:
            if "azumi4" in active_int and "azumi3" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 4 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 5):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi3" in active_int:
        with open("/etc/private3.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi3\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi3" in active_int and "azumi2" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m3 \033[92mOnline\033[0m"
                )
        else:
            if "azumi3" in active_int and "azumi2" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 3 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 4):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi2" in active_int:
        with open("/etc/private2.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi2\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi2" in active_int and "azumi1" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m2 \033[92mOnline\033[0m"
                )
        else:
            if "azumi2" in active_int and "azumi1" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 2 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 3):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumi1" in active_int:
        with open("/etc/private1.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi5\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6TO4 Sit\033[0m")

        if iran_server:
            if "azumi1" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel \033[92mOnline\033[0m"
                )
        else:
            if "azumi1" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel\033[96m \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 2):
            private_file = f"/etc/private{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumigen5" in active_int:
        with open("/etc/sys5.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumigen5\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGeneve UDP\033[0m")

        if iran_server:
            if "azumigen5" in active_int and "azumigen4" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m5 \033[92mOnline\033[0m"
                )
        else:
            if "azumigen5" in active_int and "azumigen4" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m5 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 5 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 5):
            private_file = f"/etc/sys{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumigen4" in active_int:
        with open("/etc/sys4.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumigen4\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGeneve UDP\033[0m")

        if iran_server:
            if "azumigen4" in active_int and "azumigen3" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m4 \033[92mOnline\033[0m"
                )
        else:
            if "azumigen4" in active_int and "azumigen3" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m4 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 4 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 5):
            private_file = f"/etc/sys{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumigen3" in active_int:
        with open("/etc/sys3.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumigen3\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGeneve UDP\033[0m")

        if iran_server:
            if "azumigen3" in active_int and "azumigen2" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m3 \033[92mOnline\033[0m"
                )
        else:
            if "azumigen3" in active_int and "azumigen2" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m3 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 3 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 4):
            private_file = f"/etc/sys{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumigen2" in active_int:
        with open("/etc/sys2.sh", "r") as file:
            contents = file.read()

        ipv6_2 = "::2/64" in contents
        ipv6_1 = "::1/64" in contents

        if ipv6_2 and ipv6_1:
            index_2 = contents.index("::2/64")
            index_1 = contents.index("::1/64")
            iran_server = index_2 < index_1
        else:
            iran_server = ipv6_2

        if iran_server:
            print(f" \033[97mIRAN SERVER \033[0m")
        else:
            print(f" \033[97mKHAREJ SERVER \033[0m")

        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumigen2\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGeneve UDP\033[0m")

        if iran_server:
            if "azumigen2" in active_int and "azumigen1" in active_int:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[97mlocal Tunnel \033[96m2 \033[92mOnline\033[0m"
                )
        else:
            if "azumigen2" in active_int and "azumigen1" in active_int:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m2 \033[97mlocal Tunnels\033[96m \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[97mlocal Tunnel\033[96m 2 \033[92mOnline\033[0m"
                )

        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 3):
            private_file = f"/etc/sys{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    if iran_server:
                        print(
                            f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )
                    else:
                        print(
                            f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                        )

    elif "azumigen1" in active_int:
        with open("/etc/sys1.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                print(f" \033[97mIRAN SERVER \033[0m")
            else:
                print(f" \033[97mKHAREJ SERVER \033[0m")
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumigen1\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGeneve UDP\033[0m")
        with open("/etc/sys1.sh", "r") as file:
            contents = file.read()

        match = re.search(r"::2/64", contents)
        if match:
            if match.start() < contents.index("::1/64"):
                print(
                    " \033[92mIRAN \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel \033[92mOnline\033[0m"
                )
            else:
                print(
                    " \033[92mKharej \033[97mStatus  : \033[96m1 \033[97mlocal Tunnel \033[92mOnline\033[0m"
                )
        print("\033[93m─────────────────────────────────────────────────\033[0m")
        for i in range(1, 2):
            private_file = f"/etc/sys{i}.sh"
            if os.path.exists(private_file):
                remote_ip = remote_extraction(private_file)
                if remote_ip:
                    with open("/etc/sys1.sh", "r") as file:
                        contents = file.read()

                    match = re.search(r"::2/64", contents)
                    if match:
                        if match.start() < contents.index("::1/64"):
                            print(
                                f" \033[92mKHAREJ\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )
                        else:
                            print(
                                f" \033[92mIRAN\033[93m IP for \033[96mlocal tunnel \033[92m{i}\033[93m: \033[97m{remote_ip}\033[0m"
                            )

    print("\033[93m─────────────────────────────────────────────────\033[0m")
    secret_key = ipsec_secret()
    if secret_key != "Not found":
        print(" \033[93mIPsec Secret Key:\033[96m", secret_key, "\033[0m")
    else:
        print(" \033[93mIPSEC is not available\033[0m")
    print("\033[93m─────────────────────────────────────────────────\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰─────────────────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "0":
            os.system("clear")
            status_mnu()
            break
        else:
            print("Invalid choice.")


def single_status():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mSingle Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mYou are viewing the status of your current tunnels:\033[0m")

    interfaces = {
        "azumi": "azumi",
        "azumi6": "azumi6",
        "azumip": "azumip",
        "azumig": "azumig",
        "azumig6": "azumig6",
        "azumigen": "azumigen",
        "vxlan": "vxlan",
    }

    active_int = []
    for interface, label in interfaces.items():
        status = interface_check(interface)
        if status == "online":
            active_int.append(interface)

    if not active_int:
        print(" No Interfaces available.")
    elif "azumigen" in active_int and "azumig6" in active_int:
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names:\033[96m azumig6, azumigen\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGRE6 Geneve\033[0m")
        private_sh = "/etc/private.sh"
        if os.path.exists(private_sh):
            server_type = checktype(private_sh)
            remote_ip = remote_extraction(private_sh)
            if remote_ip:
                print(
                    f" \033[92m{server_type}\033[93m Remote IP: \033[97m{remote_ip}\033[0m"
                )
    elif "azumi" in active_int and "azumig6" in active_int:
        gre6_method = check_gre6()
        if gre6_method == "gre6tap":
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names:\033[96m azumi, azumig6\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6tap\033[0m")
            private_sh = "/etc/private.sh"
            if os.path.exists(private_sh):
                server_type = checktype(private_sh)
                remote_ip = remote_extraction(private_sh)
                if remote_ip:
                    print(
                        f" \033[92m{server_type}\033[93m Remote IP: \033[97m{remote_ip}\033[0m"
                    )
        elif gre6_method == "gre6":
            print(
                " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names:\033[96m azumi, azumig6\033[0m"
            )
            print(" \033[93mTunnel Method: \033[97mGRE6\033[0m")
            private_sh = "/etc/private.sh"
            if os.path.exists(private_sh):
                server_type = checktype(private_sh)
                remote_ip = remote_extraction(private_sh)
                if remote_ip:
                    print(
                        f" \033[92m{server_type}\033[93m Remote IP: \033[97m{remote_ip}\033[0m"
                    )
    elif "azumip" in active_int:
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface names:\033[96m azumi, azumip\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mIP6IP6\033[0m")
        private_sh = "/etc/private.sh"
        if os.path.exists(private_sh):
            server_type = checktype(private_sh)
            remote_ip = remote_extraction(private_sh)
            if remote_ip:
                print(
                    f" \033[92m{server_type}\033[93m Remote IP: \033[97m{remote_ip}\033[0m"
                )
    elif os.path.exists("/etc/6to4.sh") and "azumi6" in active_int:
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi6\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97m6to4 Sit\033[0m")
        private_sh = "/etc/6to4.sh"
        if os.path.exists(private_sh):
            server_type = checktype(private_sh)
            remote_ip = remote_extraction(private_sh)
            if remote_ip:
                print(
                    f" \033[92m{server_type} \033[93mRemote IP: \033[97m{remote_ip}\033[0m"
                )
    elif os.path.exists("/etc/private.sh") and "azumi" in active_int:
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumi\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mPrivate Sit\033[0m")
        private_sh = "/etc/private.sh"
        if os.path.exists(private_sh):
            server_type = checktype(private_sh)
            remote_ip = remote_extraction(private_sh)
            if remote_ip:
                print(
                    f" \033[92m{server_type}\033[93m Remote IP: \033[97m{remote_ip}\033[0m"
                )
    elif "vxlan" in active_int:
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m vxlan\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mVxlan\033[0m")
    elif "azumig" in active_int:
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumig\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGRE\033[0m")
        private_sh = "/etc/gre.sh"
        if os.path.exists(private_sh):
            server_type = checktype2(private_sh)
            remote_ip = remote_extraction(private_sh)
            if remote_ip:
                print(
                    f" \033[92m{server_type}\033[93m Remote IP: \033[97m{remote_ip}\033[0m"
                )
    elif "azumigen" in active_int:
        print(
            " \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m azumigen\033[0m"
        )
        print(" \033[93mTunnel Method: \033[97mGeneve UDP\033[0m")
        private_sh = "/etc/sys.sh"
        if os.path.exists(private_sh):
            server_type = checktypegen(private_sh)
            remote_ip = remote_extraction(private_sh)
            if remote_ip:
                print(
                    f" \033[92m{server_type}\033[93m Remote IP: \033[97m{remote_ip}\033[0m"
                )
    secret_key = ipsec_secret()
    if secret_key != "Not found":
        print(" \033[93mIPsec Secret Key:\033[96m", secret_key, "\033[0m")

    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if choice == "0":
            os.system("clear")
            status_mnu()
            break
        else:
            print("Invalid choice.")


def geneve_gerk_version1():
    gree6_kharej1()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def geneve_gerk_version2():
    gree6_kharej1()

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::2",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::2\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gen_ipgeri():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_geri_version1()
            break
        elif server_type == "2":
            geneve_geri_version2()
            break
        else:
            print("Invalid choice.")


def geneve_geri_version1():
    gree6_iran1()
    ufw("66.200.1.1")
    ufw("66.200.2.1")
    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def geneve_geri_version2():
    gree6_iran1()

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw("2002:831a::1")
    ufw("2002:831a::2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            "2002:831a::1",
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote 2002:831a::1\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


##azumi native
def gen2_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve + Native  Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKHAREJ \033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_na_k()
            break
        elif server_type == "2":
            gen_na_i()
            break
        elif server_type == "3":
            clear()
            genz_ip()
            break
        else:
            print("Invalid choice.")


def gen_na_k():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_nk_version1()
            break
        elif server_type == "2":
            geneve_nk_version2()
            break
        else:
            print("Invalid choice.")


def geneve_nk_version1():
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[96mNative \033[93m| \033[92mTunnelbroker\033[93m]: \033[0m"
    )
    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("80.200.1.2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/30", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/30 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="80.200.1.2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def geneve_nk_version2():
    remote_ip = input(
        "\033[93mEnter \033[92mIRAN\033[93m IPV6 address [\033[96mNative \033[93m| \033[92mTunnelbroker\033[93m]: \033[0m"
    )

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw(remote_ip)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def gen_na_i():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_ni_version1()
            break
        elif server_type == "2":
            geneve_ni_version2()
            break
        else:
            print("Invalid choice.")


def geneve_ni_version1():
    remote_ip = input(
        "\033[93mEnter \033[92mKHAREJ\033[93m IPV6 address [\033[96mNative \033[93m| \033[92mTunnelbroker\033[93m]: \033[0m"
    )

    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("80.200.1.2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "80.200.1.2/30", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 80.200.1.2/30 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        80.200.1.2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def geneve_ni_version2():
    remote_ip = input(
        "\033[93mEnter \033[92mKHAREJ\033[93m IPV6 address [\033[96mNative \033[93m| \033[92mTunnelbroker\033[93m]: \033[0m"
    )

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw(remote_ip)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


##### saki no


def gen_ip():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve  Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mMethod 1[PointIP] \033[0m")
    print("2. \033[93mMethod 2[Route]\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            gen_ipm1()
            break
        elif server_type == "2":
            gen_ipm2()
            break
        elif server_type == "3":
            clear()
            genz_ip()
            break
        else:
            print("Invalid choice.")


def gen_ipm2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mMethod 2\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejm2_gen_menu()
            break
        elif server_type == "2":
            iranm2_gen_menu()
            break
        elif server_type == "3":
            clear()
            gen_ip()
            break
        else:
            print("Invalid choice.")


def gen_ipm1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mMethod 1\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mKharej\033[0m")
    print("2. \033[93mIRAN\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            kharejm1_gen_menu()
            break
        elif server_type == "2":
            iranm1_gen_menu()
            break
        elif server_type == "3":
            clear()
            gen_ip()
            break
        else:
            print("Invalid choice.")


def genkhm1_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "66.200.2.1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def genkhm2_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "80.200.1.2"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def genirm1_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "66.200.1.1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def genirm2_ping():
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    try:
        print("\033[96mPlease Wait, Azumi is pinging...")
        subprocess.run(
            ["ping", "-c", "2", "66.200.1.1"], check=True, stdout=subprocess.DEVNULL
        )
    except subprocess.CalledProcessError as e:
        print(Fore.LIGHTRED_EX + "Pinging failed:", e, Style.RESET_ALL)


def ping_kh_service():
    service_content = """[Unit]
Description=keepalive
After=network.target

[Service]
ExecStart=/bin/bash /etc/ping_sys.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    service_file_path = "/etc/systemd/system/ping_gen.service"
    with open(service_file_path, "w") as service_file:
        service_file.write(service_content)

    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", "ping_gen.service"])
    sleep(1)
    subprocess.run(["systemctl", "restart", "ping_gen.service"])


def gen_job():
    file_path = "/etc/sys.sh"

    try:

        subprocess.run(
            f"(crontab -l | grep -v '{file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        subprocess.run(
            f"(crontab -l ; echo '@reboot /bin/bash {file_path}') | crontab -",
            shell=True,
            capture_output=True,
            text=True,
        )

        display_checkmark("\033[92mCronjob added successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("\033[91mFailed to add cronjob:\033[0m", e)


def ufw(ip_address):
    subprocess.run(["sudo", "ufw", "allow", "from", ip_address])


def delufw(ip_address):
    subprocess.run(["sudo", "ufw", "delete", "allow", "from", ip_address])


def ipv4_address():
    result = subprocess.run(
        ["curl", "-s", "https://ipinfo.io/ip"], capture_output=True, text=True
    )
    return result.stdout.strip()


def gen_ipvers():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_ipk_version1()
            break
        elif server_type == "2":
            geneve_ipk_version2()
            break
        else:
            print("Invalid choice.")


def geneve_ipk_version1():
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("66.200.2.1")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.2.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.2.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def geneve_ipk_version2():
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw(remote_ip)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def kharejm1_gen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server \033[92mMethod 1\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/sys.sh"):
        os.remove("/etc/sys.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gen_ipvers()


## model 2
def gen_ipvers2():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_ipk1_version1()
            break
        elif server_type == "2":
            geneve_ipk1_version2()
            break
        else:
            print("Invalid choice.")


def geneve_ipk1_version1():
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("80.200.1.2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.1.1/30", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.1.1/30 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.1.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="80.200.1.2"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def geneve_ipk1_version2():
    remote_ip = input("\033[93mEnter \033[92mIRAN\033[93m IPV4 address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw(remote_ip)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genkhm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (Kharej):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mIRAN IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mKharej Server Configuration Completed!\033[0m")


def kharejm2_gen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mKharej server\033[92m Method 2\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring Kharej server...\033[0m")

    if os.path.isfile("/etc/sys.sh"):
        os.remove("/etc/sys.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gen_ipvers2()


def gen_ipver():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_ip_version1()
            break
        elif server_type == "2":
            geneve_ip_version2()
            break
        else:
            print("Invalid choice.")


def geneve_ip_version1():
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("66.200.2.1")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "66.200.2.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "route", "add", "66.200.1.1/32", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 66.200.2.1/32 dev azumigen\n")
        f.write("sudo ip route add 66.200.1.1/32 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        66.200.2.1\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def geneve_ip_version2():
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw(remote_ip)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def iranm1_gen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIran server\033[92m Method 1\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring for Iran server...\033[0m")

    if os.path.isfile("/etc/sys.sh"):
        os.remove("/etc/sys.sh")

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    gen_ipver()


def gen1_ipver():
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose Geneve IP Version:\033[0m")
    print("1. \033[92mIPV4\033[0m")
    print("2. \033[93mIPV6\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            geneve_ipi_version1()
            break
        elif server_type == "2":
            geneve_ipi_version2()
            break
        else:
            print("Invalid choice.")


def geneve_ipi_version1():
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")
    ufw(remote_ip)
    ufw("66.200.1.1")
    ufw("80.200.1.2")

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", "80.200.1.2/30", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write("sudo ip addr add 80.200.1.2/30 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    genirm1_ping()
    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "        80.200.1.2\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    script_content = """#!/bin/bash
ip_address="66.200.1.1"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{print $2}" | awk -F " " "{print $1}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def geneve_ipi_version2():
    remote_ip = input("\033[93mEnter \033[92mKharej\033[93m IPV4 address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ufw(remote_ip)

    subprocess.run(
        [
            "sudo",
            "ip",
            "link",
            "add",
            "name",
            "azumigen",
            "type",
            "geneve",
            "id",
            "1000",
            "remote",
            remote_ip,
        ],
        stdout=subprocess.DEVNULL,
    )
    subprocess.run(
        ["sudo", "ip", "link", "set", "azumigen", "up"], stdout=subprocess.DEVNULL
    )
    subprocess.run(
        ["sudo", "ip", "addr", "add", prefix + "/16", "dev", "azumigen"],
        stdout=subprocess.DEVNULL,
    )

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_notification("\033[93mAdding commands...\033[0m")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")

    with open("/etc/sys.sh", "w") as f:
        f.write(
            f"sudo ip link add name azumigen type geneve id 1000 remote {remote_ip}\n"
        )
        f.write("sudo ip link set azumigen up\n")
        f.write(f"sudo ip addr add {prefix}/16 dev azumigen\n")

    set_mtu = input(
        "\033[93mDo you want to set the \033[92mMTU\033[96m [Geneve]\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    )

    if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
        mtu_value = input(
            "\033[93mEnter the desired\033[92m MTU value\033[93m: \033[0m"
        )
        mtu_command = f"ip link set dev azumigen mtu {mtu_value}\n"
        with open("/etc/sys.sh", "a") as f:
            f.write(mtu_command)
        subprocess.run(mtu_command, shell=True, check=True)

    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    display_checkmark("\033[92mConfiguration is done!\033[0m")

    gen_job()

    time.sleep(1)
    display_checkmark("\033[92mkeepalive service Configured!\033[0m")

    time.sleep(1)
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    print("\033[93mCreated IP Addresses (IRAN):\033[0m")
    print("\033[92m" + "+---------------------------+" + "\033[0m")
    print("\033[92m" + "     {}\033[0m".format(prefix))
    print("\033[92m" + "+---------------------------+" + "\033[0m")

    remote_ipv4 = input(
        "\033[93mEnter \033[92mKharej IPv4\033[93m address [Ping Service]: \033[0m"
    )

    remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
        *map(int, remote_ipv4.split("."))
    )
    ufw(remote_prefix)

    script_content = """#!/bin/bash
ip_address="{remote_prefix}"
max_pings=5
interval=2
while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done
    echo "Waiting for $interval seconds..."
    sleep $interval
done
""".format(
        remote_prefix=remote_prefix
    )

    with open("/etc/ping_sys.sh", "w") as script_file:
        script_file.write(script_content)

    os.chmod("/etc/ping_sys.sh", 0o755)
    ping_kh_service()

    print("\033[92mIRAN Server Configuration Completed!\033[0m")


def iranm2_gen_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mIran server\033[92m Method 2\033[0m")
    print('\033[92m "-"\033[93m═══════════════════════════\033[0m')
    display_notification("\033[93mConfiguring for Iran server...\033[0m")

    if os.path.isfile("/etc/sys.sh"):
        os.remove("/etc/sys.sh")

    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    gen1_ipver()


def i6to41_any_iran():
    clear_screen()
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print(
        "\033[92m(   ) \033[93m6to4 \033[92mIRAN\033[93m  Menu\033[92m[Anycast]\033[0m"
    )
    print('\033[92m "-"\033[93m════════════════════════════\033[0m')

    if (
        subprocess.run(["test", "-f", "/etc/6to4.sh"], capture_output=True).returncode
        == 0
    ):
        subprocess.run(["rm", "/etc/6to4.sh"])

    display_notification("\033[93mConfiguring...\033[0m")
    local_ipv4 = server_ipv4()
    if local_ipv4 is None:
        return
    sleep(1)
    print("\033[93m╭─────────────────────────────────────────────────────────╮\033[0m")
    local_ip = input("\033[93mEnter \033[92mIran IPv4\033[93m address: \033[0m")

    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()

    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))

    ipv6_address = f'ipv4="{local_ipv4}"; printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`'
    ipv6_process = subprocess.run(
        ipv6_address, shell=True, capture_output=True, text=True
    )
    if ipv6_process.returncode != 0:
        print("Error generating IPv6 address.")
        return

    ipv6 = ipv6_process.stdout.strip()
    print(
        "\033[93m│\033[0m \033[92mGenerated IPv6 address:\033[0m",
        ipv6,
        "\033[93m│\033[0m",
    )

    with open("/etc/6to4.sh", "w") as f:
        f.write("#!/bin/bash\n")
        f.write("/sbin/modprobe sit\n")
        f.write(
            "/sbin/ip tunnel add azumi6 mode sit remote any local {} ttl 255\n".format(
                local_ip
            )
        )
        set_mtu = input(
            "\033[93mDo you want to set \033[92m MTU?\033[93m (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
        )
        if set_mtu.lower() == "yes" or set_mtu.lower() == "y":
            mtu_value = input(
                "\033[93mEnter the desired \033[92mMTU value\033[93m: \033[0m"
            )
            f.write("/sbin/ip -6 link set dev azumi6 mtu {}\n".format(mtu_value))
        else:
            f.write("/sbin/ip -6 link set dev azumi6 mtu 1480\n")
        f.write("/sbin/ip link set dev azumi6 up\n")
        f.write("/sbin/ip -6 addr add {}/16 dev azumi6\n".format(prefix))
        f.write(
            "/sbin/ip -6 route add 2000::/3 via ::192.88.99.1 dev azumi6 metric 1\n"
        )
        answer = input(
            "\033[93mDo you want to change the \033[92mdefault route\033[93m? (\033[92my\033[93m/\033[91mn\033[93m)\033[0m "
        )
        if answer.lower() in ["yes", "y"]:
            interface = ipv6_int()
            if interface is None:
                print("Error: No network interface with IPv6 address.")
            else:
                print("Interface:", interface)
                f.write(
                    "ip -6 route replace default via fe80::1 dev {} src {}\n".format(
                        interface, prefix
                    )
                )
        else:
            print("Skipping changing the default route.")
    print("\033[93m─────────────────────────────────────────────────────────\033[0m")
    num_ips = int(
        input("\033[93mHow many \033[92madditional IPs\033[93m do you need? \033[0m")
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    start_index = 3

    with open("/etc/6to4.sh", "a") as f:
        for i in range(start_index, start_index + num_ips):
            ip_addr = "2002:{:02x}{:02x}:{:02x}{:02x}::{:02x}/16".format(
                *map(int, ipv4.split(".")), i
            )
            f.write("ip -6 addr add {} dev azumi6\n".format(ip_addr))

    display_notification("\033[93mAdding cronjob!\033[0m")

    config_file_path = "/etc/6to4.sh"

    subprocess.run(
        f"(crontab -l | grep -v -F '{config_file_path}') | crontab -",
        shell=True,
        check=True,
    )

    cronjob_command = (
        f"(crontab -l 2>/dev/null; echo '@reboot sh {config_file_path}') | crontab -"
    )
    subprocess.run(cronjob_command, shell=True, check=True)

    display_notification("\033[93mStarting 6to4...\033[0m")
    subprocess.run(["/bin/bash", "/etc/6to4.sh"])

    num_servers = int(
        input(
            "\033[93mEnter the \033[92mnumber\033[93m of \033[96mServers\033[93m[Ping Service]? \033[0m"
        )
    )
    print("\033[93m╰─────────────────────────────────────────────────────────╯\033[0m")

    for i in range(num_servers):
        remote_ipv4 = input(
            f"\033[93mEnter \033[96mIPv4 address\033[93m of server \033[92m{i+1} [Ping Service]: \033[0m"
        )

        remote_prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(
            *map(int, remote_ipv4.split("."))
        )
        sleep(1)
        print("\033[92m(\033[96mPlease wait,Azumi is pinging...\033[0m")
        ping_result = subprocess.run(
            ["ping6", "-c", "2", remote_prefix], capture_output=True, text=True
        ).stdout.strip()
        print(ping_result)

        script_content = """#!/bin/bash

ip_address="{}"

max_pings=5

interval=2

while true
do
    for ((i = 1; i <= max_pings; i++))
    do
        ping_result=$(ping -c 1 $ip_address | grep "time=" | awk -F "time=" "{{print $2}}" | awk -F " " "{{print $1}}" | cut -d "." -f1)
       
        if [ -n "$ping_result" ]; then
            echo "Ping successful! Response time: $ping_result ms"
        else
            echo "Ping failed!"
        fi
    done

    echo "Waiting for $interval seconds..."
    sleep $interval
done
"""

        script_filename = f"/etc/ping_v6{i+1}.sh"
        with open(script_filename, "w") as f:
            f.write(script_content)

        subprocess.run(["chmod", "+x", script_filename])

        service_filename = f"/etc/systemd/system/ping_v6{i+1}.service"
        with open(service_filename, "w") as f:
            f.write("[Unit]\n")
            f.write(f"Description=Ping Service {i+1}\n")
            f.write("After=network.target\n")
            f.write("\n")
            f.write("[Service]\n")
            f.write(f"ExecStart=/bin/bash {script_filename}\n")
            f.write("Restart=always\n")
            f.write("\n")
            f.write("[Install]\n")
            f.write("WantedBy=multi-user.target\n")

        subprocess.run(["systemctl", "daemon-reload"])
        subprocess.run(["systemctl", "enable", f"ping_v6{i+1}.service"])
        subprocess.run(["systemctl", "start", f"ping_v6{i+1}.service"])
        sleep(1)
        subprocess.run(["systemctl", "restart", f"ping_v6{i+1}.service"])

        print(
            f"\033[92mPing service for server {i+1} has been added successfully!\033[0m"
        )

    display_checkmark("\033[92m6to4 Service has been added successfully!\033[0m")


def remove_6to4():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92m6TO4\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/6to4.sh", shell=True) == 0:
            subprocess.run("rm /etc/6to4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot sh /etc/6to4.sh" | crontab -', shell=True
        )

        subprocess.run("sudo rm /etc/ping_v6.sh", shell=True)
        time.sleep(1)

        subprocess.run("systemctl disable ping_v6.service > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop ping_v6.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v6.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi6 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_6to41():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92m6TO4\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/6to4.sh", shell=True) == 0:
            subprocess.run("rm /etc/6to4.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot sh /etc/6to4.sh" | crontab -', shell=True
        )

        subprocess.run("sudo rm /etc/ping_v6.sh", shell=True)
        time.sleep(1)

        subprocess.run("systemctl disable ping_v6.service > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop ping_v6.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v6.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v61.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v61.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v62.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v62.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v63.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v63.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v64.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v64.service > /dev/null 2>&1", shell=True
        )
        subprocess.run(
            "systemctl disable ping_v65.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_v65.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_v65.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumi6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumi6 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot sh /etc/gre.sh" | crontab -', shell=True
        )

        subprocess.run("sudo rm /etc/ping_ip.sh", shell=True)
        time.sleep(1)

        subprocess.run("systemctl disable ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)

        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumig down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre6():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if (
            subprocess.call(
                "test -f /etc/gre6.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/gre6.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        if (
            subprocess.call(
                "test -f /etc/private.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/private.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre6.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping_v6.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        time.sleep(1)
        subprocess.run(
            "sudo rm /etc/ping_ip.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping_v6.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping_v6.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping_v6.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_ip.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping_ip.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping_ip.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        time.sleep(1)
        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "ip link set dev azumi down > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "ip tunnel del azumi > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        time.sleep(1)
        subprocess.run(
            "ip link set dev azumig6 down > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "ip tunnel del azumig6 > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre621():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre6.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre6.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre6.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ping_ip.sh", shell=True)
        subprocess.run("systemctl disable ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumig6 down > /dev/null", shell=True)
        subprocess.run("ip tunnel del azumig6 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_gre6tap21():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving \033[92mGRE6\033[93m Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if subprocess.call("test -f /etc/gre6.sh", shell=True) == 0:
            subprocess.run("rm /etc/gre6.sh", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/gre6.sh" | crontab -',
            shell=True,
        )
        subprocess.run("sudo rm /etc/ping_ip.sh", shell=True)
        subprocess.run("systemctl disable ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run("systemctl stop ping_ip.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_ip.service > /dev/null 2>&1", shell=True
        )
        time.sleep(1)
        subprocess.run("systemctl daemon-reload", shell=True)

        subprocess.run("ip link set dev azumig6 down > /dev/null", shell=True)
        subprocess.run("ip link delete azumig6 > /dev/null", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remove_privatesec():
    remove_private()
    ipsecs_uninstall_private()


def remove_private():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving private IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        if (
            subprocess.call(
                "test -f /etc/private.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/private.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/private.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping_v6.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        time.sleep(1)
        subprocess.run(
            "systemctl disable ping_v6.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping_v6.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping_v6.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        time.sleep(1)

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "ip link set dev azumi down > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "ip tunnel del azumi > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def prefix_ip_gen():
    gen_path = "/etc/ping_sys.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as ping_gen_sh:
        for line in ping_gen_sh:
            if "ip_address" in line:
                ip_address = line.split("=")[-1].strip().strip('"')
                return ip_address

    return None


def remote_ip_gen():
    gen_path = "/etc/sys.sh"

    if not os.path.isfile(gen_path):
        return None

    with open(gen_path, "r") as gen_sh:
        for line in gen_sh:
            if "remote" in line:
                remote_ip = line.split()[-1].strip('"')
                return remote_ip

    return None


def genz_uninstall():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"],
        stdout=subprocess.PIPE,
        stderr=subprocess.DEVNULL,
        text=True,
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))
    delufw(prefix)
    remote_ip = remote_ip_gen()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)

    remote2_ip = prefix_ip_gen()

    if remote2_ip is None:
        print("Unable to retrieve prefix")
    else:
        delufw(remote2_ip)

    delufw("66.200.1.1")
    delufw("80.200.1.2")
    delufw("66.200.2.1")
    delufw("2001:db8::1")
    delufw("2001:db8::2")
    try:
        if (
            subprocess.call(
                "test -f /etc/sys.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )
            == 0
        ):
            subprocess.run(
                "rm /etc/sys.sh",
                shell=True,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys.sh" | crontab -',
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo rm /etc/ping_sys.sh",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl disable ping_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "systemctl stop ping_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        subprocess.run(
            "rm /etc/systemd/system/ping_gen.service > /dev/null 2>&1",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "systemctl daemon-reload",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        subprocess.run(
            "sudo ip link delete azumigen > /dev/null",
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def remove_test():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mGeneve \033[92mIPsec\033[93m Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1. \033[92mGeneve + IPsec\033[0m")
    print("2. \033[93mGeneve + GRE6 + IPsec\033[0m")
    print("3. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "1":
            remove_testz1()
            break
        elif server_type == "2":
            remove_testz2()
            break
        elif server_type == "3":
            clear()
            genx_ip()
            break
        else:
            print("Invalid choice.")


def remove_testz1():
    genz_uninstall()
    ipsecs_uninstall_gen()


def remove_testz2():
    genz_uninstall()
    gen6_uninstall()
    ipsecs_uninstall_gen()


def gen4_uninstall():
    remove_private()
    remove_gre621()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Geneve + \033[92mGRE6 + IP6tnl \033[93m+ \033[96mTunnel\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")
    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))
    delufw(prefix)
    remote_ip = remote_ip_gen()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)

    remote2_ip = prefix_ip_gen()

    if remote2_ip is None:
        print("Unable to retrieve prefix")
    else:
        delufw(remote2_ip)

    delufw("66.200.1.1")
    delufw("66.200.2.1")
    delufw("2002:831a::1")
    delufw("2002:831a::2")
    delufw("2002:831b::2")
    delufw("2002:831b::1")
    delufw("2001:db8::1")
    delufw("2001:db8::2")

    try:
        if subprocess.call("test -f /etc/sys.sh", shell=True) == 0:
            subprocess.run("rm /etc/sys.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys.sh" | crontab - > /dev/null 2>&1',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_sys.sh > /dev/null 2>&1", shell=True)

        subprocess.run(
            "systemctl disable ping_gen.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_gen.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_gen.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload > /dev/null 2>&1", shell=True)

        subprocess.run("sudo ip link delete azumigen > /dev/null 2>&1", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def gen2_uninstall():
    remove_gre621()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Geneve + \033[92mGRE6 \033[93m+ \033[96mNATIVE Tunnel\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")
    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))
    delufw(prefix)
    remote_ip = remote_ip_gen()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
        prefix = prefix_ip_gen()

        if prefix is None:
            print("Unable to retrieve prefix")
        else:
            delufw(prefix)
            delufw("66.200.1.1")
            delufw("66.200.2.1")
            delufw("2002:831a::1")
            delufw("2002:831a::2")

    try:
        if subprocess.call("test -f /etc/sys.sh", shell=True) == 0:
            subprocess.run("rm /etc/sys.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys.sh" | crontab - > /dev/null 2>&1',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_sys.sh > /dev/null 2>&1", shell=True)

        subprocess.run(
            "systemctl disable ping_gen.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_gen.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_gen.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload > /dev/null 2>&1", shell=True)

        subprocess.run("sudo ip link delete azumigen > /dev/null 2>&1", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def gen6_uninstall():
    remove_private()
    remove_gre6()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Geneve + \033[92mGRE6 \033[93m+ \033[96mIPV4\033[93m Tunnel\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")
    delufw("66.200.1.1")
    delufw("66.200.2.1")
    delufw("2002:831a::1")
    delufw("2002:831a::2")
    delufw("2002:831b::1")
    delufw("2002:831b::2")
    delufw("2001:db8::1")
    delufw("2001:db8::2")
    ipv4 = subprocess.run(
        ["curl", "-s", "https://api.ipify.org"], capture_output=True, text=True
    ).stdout.strip()
    prefix = "2002:{:02x}{:02x}:{:02x}{:02x}::1".format(*map(int, ipv4.split(".")))
    delufw(prefix)
    remote_ip = remote_ip_gen()

    if remote_ip is None:
        print("Unable to retrieve remote IP")
    else:
        delufw(remote_ip)
        prefix = prefix_ip_gen()

        if prefix is None:
            print("Unable to retrieve prefix")
        else:
            delufw(prefix)

    try:
        if subprocess.call("test -f /etc/sys.sh", shell=True) == 0:
            subprocess.run("rm /etc/sys.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys.sh" | crontab - > /dev/null 2>&1',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_sys.sh > /dev/null 2>&1", shell=True)

        subprocess.run(
            "systemctl disable ping_gen.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_gen.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_gen.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload > /dev/null 2>&1", shell=True)

        subprocess.run("sudo ip link delete azumigen > /dev/null 2>&1", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())
    except Exception as e:
        print("Error:", str(e))


def gen3_uninstall():
    remove_gre6()
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification(
        "\033[93mRemoving Geneve + \033[92mGRE6 \033[93m+ \033[96mNative\033[93m Tunnel\033[0m"
    )
    print("\033[93m───────────────────────────────────────\033[0m")
    delufw("66.200.1.1")
    delufw("66.200.2.1")
    delufw("2002:831a::1")
    delufw("2002:831a::2")

    try:
        if subprocess.call("test -f /etc/sys.sh", shell=True) == 0:
            subprocess.run("rm /etc/sys.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys.sh" | crontab - > /dev/null 2>&1',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_sys.sh > /dev/null 2>&1", shell=True)

        subprocess.run(
            "systemctl disable ping_gen.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_gen.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_gen.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload > /dev/null 2>&1", shell=True)

        subprocess.run("sudo ip link delete azumigen > /dev/null 2>&1", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def gen_icmp():
    os.system("clear > /dev/null 2>&1")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Geneve + ICMP Tunnel...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    remove_icmp()

    subprocess.run(
        'crontab -l | grep -v "@reboot /bin/bash /etc/icmp.sh" | crontab - > /dev/null 2>&1',
        shell=True,
    )

    remote2_ip = prefix_ip_gen()

    if remote2_ip is None:
        print("Unable to retrieve prefix")
        return
    delufw(remote2_ip)
    delufw("66.200.1.1")
    delufw("66.200.2.1")
    delufw("70.0.0.1")
    delufw("70.0.0.2")

    try:
        if subprocess.call("test -f /etc/sys.sh", shell=True) == 0:
            subprocess.run("rm /etc/sys.sh > /dev/null 2>&1", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/sys.sh" | crontab - > /dev/null 2>&1',
            shell=True,
        )

        subprocess.run("sudo rm /etc/ping_sys.sh > /dev/null 2>&1", shell=True)

        subprocess.run(
            "systemctl disable ping_gen.service > /dev/null 2>&1", shell=True
        )
        subprocess.run("systemctl stop ping_gen.service > /dev/null 2>&1", shell=True)
        subprocess.run(
            "rm /etc/systemd/system/ping_gen.service > /dev/null 2>&1", shell=True
        )

        subprocess.run("systemctl daemon-reload > /dev/null 2>&1", shell=True)

        subprocess.run("sudo ip link delete azumigen > /dev/null 2>&1", shell=True)

        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 1
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mUninstall completed!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())



def extra_uninstall():
    os.system("clear")
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mRemoving Extra IP addresses...\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")

    try:
        interface = (
            subprocess.check_output(
                "ip route | awk '/default/ {print $5; exit}'", shell=True
            )
            .decode()
            .strip()
        )
        addresses = (
            subprocess.check_output(
                f"ip addr show dev {interface} | awk '/inet6 .* global/ {{print $2}}'",
                shell=True,
            )
            .decode()
            .splitlines()
        )

        for address in addresses:
            subprocess.run(f"ip addr del {address} dev {interface}", shell=True)

        display_notification("\033[93mRemoving cronjob...\033[0m")
        subprocess.run(
            'crontab -l | grep -v "@reboot /bin/bash /etc/ipv6.sh" | crontab -',
            shell=True,
        )

        sleep(1)
        subprocess.run("sudo rm /etc/ipv6.sh", shell=True)

        display_notification(
            "\033[93mRemoving Extra ip, Working in the background..\033[0m"
        )
        print("Progress: ", end="")

        frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
        delay = 0.1
        duration = 3
        end_time = time.time() + duration

        while time.time() < end_time:
            for frame in frames:
                print("\r[%s] Loading...  " % frame, end="")
                time.sleep(delay)
                print("\r[%s]             " % frame, end="")
                time.sleep(delay)

        display_checkmark("\033[92mExtra IP addresses removed successfully!\033[0m")
    except subprocess.CalledProcessError as e:
        print("Error:", e.output.decode().strip())


def remote_extraction(file_path):
    with open(file_path, "r") as file:
        content = file.read()
        match_ipv4 = re.search(
            r"remote\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", content
        )
        match_ipv6 = re.search(r"remote\s+([0-9a-fA-F:]+)", content)
        if match_ipv4:
            return match_ipv4.group(1)
        elif match_ipv6:
            return match_ipv6.group(1)
    return None


def remote_extraction_sit(file_path):
    with open(file_path, "r") as file:
        content = file.read()
        match = re.search(r"remote\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", content)
        if match:
            return match.group(1)
    return None


def remote_endpoint(file_path):
    with open(file_path, "r") as file:
        content = file.read()
        match = re.search(r"\[Peer\][\s\S]*?Endpoint\s*=\s*([\d\.]+)", content)
        if match:
            return match.group(1)
    return None


def parse_wireguard_config(file_path):
    with open(file_path, "r") as file:
        content = file.read()
    endpoint = re.search(r"Endpoint\s*=\s*(\S+)", content)
    mtu = re.search(r"MTU\s*=\s*(\d+)", content)
    port = re.search(r"ListenPort\s*=\s*(\d+)", content)
    return {
        "endpoint": endpoint.group(1) if endpoint else None,
        "mtu": mtu.group(1) if mtu else None,
        "port": port.group(1) if port else None,
    }


def interface_ex(interface):
    output = subprocess.run(
        ["ip", "a", "show", interface], capture_output=True, text=True
    )
    return output.returncode == 0


def interface_check(interface):
    output = subprocess.run(
        ["ip", "a", "show", interface], capture_output=True, text=True
    )
    if output.returncode == 0:
        if re.search(r"state (UP|UNKNOWN)", output.stdout):
            return "online"
    return "offline"

def wireguard_status():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mWireguard Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭─────────────────────────────────────────────────╮\033[0m")
    print("\033[93mYou are viewing the status of your current tunnels:\033[0m")

    interfaces = [
        "wireserver5",
        "azumig65",
        "wireserver4",
        "azumig64",
        "wireserver3",
        "azumig63",
        "wireserver2",
        "azumig62",
        "wireserver1",
        "azumig61",
        "wireclient",
        "azumi5",
        "azumi4",
        "azumi3",
        "azumi2",
        "azumi1",
    ]

    active_int = {}
    for interface in interfaces:
        if interface_ex(interface):
            status = interface_check(interface)
            if status == "online":
                active_int[interface] = True

    if not active_int:
        print(" No Interfaces available.")
        return

    config_pairs = [
        (
            "wireserver5",
            "azumig65",
            "/etc/gre65.sh",
            "/etc/wireguard/wireserver5.conf",
            "Server Config [5]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireserver4",
            "azumig64",
            "/etc/gre64.sh",
            "/etc/wireguard/wireserver4.conf",
            "Server Config [4]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireserver3",
            "azumig63",
            "/etc/gre63.sh",
            "/etc/wireguard/wireserver3.conf",
            "Server Config [3]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireserver2",
            "azumig62",
            "/etc/gre62.sh",
            "/etc/wireguard/wireserver2.conf",
            "Server Config [2]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireserver1",
            "azumig61",
            "/etc/gre61.sh",
            "/etc/wireguard/wireserver1.conf",
            "Server Config [1]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireclient",
            "azumig65",
            "/etc/gre65.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [5]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireclient",
            "azumig64",
            "/etc/gre64.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [4]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireclient",
            "azumig63",
            "/etc/gre63.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [3]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireclient",
            "azumig62",
            "/etc/gre62.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [2]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireclient",
            "azumig61",
            "/etc/gre61.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [1]",
            "Native GRE6TAP + WireGuard",
            "WireGuard + GRE6TAP",
        ),
        (
            "wireserver5",
            "azumi5",
            "/etc/private5.sh",
            "/etc/wireguard/wireserver5.conf",
            "Server Config [5]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireserver4",
            "azumi4",
            "/etc/private4.sh",
            "/etc/wireguard/wireserver4.conf",
            "Server Config [4]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireserver3",
            "azumi3",
            "/etc/private3.sh",
            "/etc/wireguard/wireserver3.conf",
            "Server Config [3]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireserver2",
            "azumi2",
            "/etc/private2.sh",
            "/etc/wireguard/wireserver2.conf",
            "Server Config [2]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireserver1",
            "azumi1",
            "/etc/private1.sh",
            "/etc/wireguard/wireserver1.conf",
            "Server Config [1]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireclient",
            "azumi5",
            "/etc/private5.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [5]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireclient",
            "azumi4",
            "/etc/private4.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [4]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireclient",
            "azumi3",
            "/etc/private3.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [3]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireclient",
            "azumi2",
            "/etc/private2.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [2]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
        (
            "wireclient",
            "azumi1",
            "/etc/private1.sh",
            "/etc/wireguard/wireclient.conf",
            "Client [1]",
            "Sit + Wireguard",
            "Sit + Wireguard",
        ),
    ]

    displayed_servers = set()

    for (
        int_a,
        int_b,
        gre_file,
        wg_file,
        config_label,
        tunnel_type_ipv6,
        tunnel_type_ipv4,
    ) in config_pairs:
        if active_int.get(int_a) and active_int.get(int_b):
            remote_ip = (
                remote_extraction(gre_file)
                if "private" not in gre_file
                else remote_extraction_sit(gre_file)
            )
            wg_config = parse_wireguard_config(wg_file)

            if remote_ip:
                if config_label not in displayed_servers:
                    if ":" in remote_ip:  # IPv6
                        print(
                            "\033[93m─────────────────────────────────────────────────\033[0m"
                        )
                        print(f" \033[93mThis is \033[92m{config_label}\033[0m")
                        print(
                            f" \033[97mTunnel Type: \033[92m{tunnel_type_ipv6}\033[0m"
                        )
                        print(
                            f" \033[93mRemote \033[92m[Client]\033[93m IP Address : \033[97m{remote_ip}\033[0m"
                        )
                    else:  # IPv4
                        print(
                            "\033[93m─────────────────────────────────────────────────\033[0m"
                        )
                        print(f" \033[93mThis is \033[92m{config_label}\033[0m")
                        print(
                            f" \033[97mTunnel Type: \033[92m{tunnel_type_ipv4}\033[0m"
                        )
                        if wg_config["endpoint"]:
                            print(
                                f" \033[93mRemote \033[92m[Client]\033[93m IP Address : \033[97m{wg_config['endpoint'].split(':')[0]}\033[0m"
                            )

                    print(f" \033[93mPort: \033[97m{wg_config['port']}\033[0m")
                    print(f" \033[93mMTU: \033[97m{wg_config['mtu']}\033[0m")

                    displayed_servers.add(config_label)

    additional_servers = [
        (
            "wireserver5",
            "Server Config [5]",
            "/etc/wireguard/wireserver5.conf",
        ),
        (
            "wireserver4",
            "Server Config [4]",
            "/etc/wireguard/wireserver4.conf",
        ),
        (
            "wireserver3",
            "Server Config [3]",
            "/etc/wireguard/wireserver3.conf",
        ),
        (
            "wireserver2",
            "Server Config [2]",
            "/etc/wireguard/wireserver2.conf",
        ),
        (
            "wireserver1",
            "Server Config [1]",
            "/etc/wireguard/wireserver1.conf",
        ),
        ("wireclient", "Client", "/etc/wireguard/wireclient.conf"),
    ]

    for interface, label, config_path in additional_servers:
        if active_int.get(interface) and label not in displayed_servers:
            remote_ip = remote_endpoint(config_path)
            wg_config = parse_wireguard_config(config_path)

            if remote_ip:
                print(
                    "\033[93m─────────────────────────────────────────────────\033[0m"
                )
                print(f" \033[93mThis is \033[92m{label}\033[0m")
                print(f" \033[97mTunnel Type: \033[92mWireGuard UDP\033[0m")
                print(
                    f" \033[93mRemote \033[92mClient\033[93m IP Address  \033[96m[{interface[-1]}]: \033[97m{remote_ip}\033[0m"
                )
                print(f" \033[93mPort: \033[97m{wg_config['port']}\033[0m")
                print(f" \033[93mMTU: \033[97m{wg_config['mtu']}\033[0m")
                print(
                    "\033[93m─────────────────────────────────────────────────\033[0m"
                )
    print("\033[93m─────────────────────────────────────────────────\033[0m")
    print("0.\033[97mback to the main script\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    while True:
        server_type = input("\033[38;5;205mEnter your choice Please: \033[0m")
        if server_type == "0":
            os.system("clear")
            os._exit(0)
            break
        else:
            print("Invalid choice.")

main_menu()
