from sshtunnel import SSHTunnelForwarder
import os

filename = os.path.basename(__file__)

def ping(host):
    # Führe den Ping-Befehl aus und erfasse die Ausgabe
    result = os.system("ping -c 1 " + host)
    if result == 0:
        hostname = "172.17.1.21", 22
    else:
        hostname = "forward.stines.de", 2223
    return hostname

server = SSHTunnelForwarder(
        (ping("forward.stines.de")),
        ssh_username="root",
        ssh_password="adm.3dfx12",
        remote_bind_address=('127.0.0.1', 3306)
)

def server_start():
    server.start()
    return print(f"{filename}-Server started")

def server_stop():
    server.stop()
    return print(f"{filename}-Server stoped")

def server_port():
    return server.local_bind_port


