commit 0a84c9025790971f354743886dacf5ff4fea5a09 Author: Vincent Hanewinkel Date: Wed May 21 16:47:43 2025 +0200 first commit diff --git a/Internet.py b/Internet.py new file mode 100644 index 0000000..ce5145d --- /dev/null +++ b/Internet.py @@ -0,0 +1,49 @@ +import paramiko +import requests +import time + +ssh_host = "139.18.143.253" +ssh_username = "" +ssh_password = "" + +def sshVerbindung(): + + client = paramiko.SSHClient() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + + try: + client.connect(ssh_host, username=ssh_username, password=ssh_password) + + channel = client.invoke_shell() + + while True: + time.sleep(60) + if not checkGoogle(): + break + + except Exception as e: + print(f"Fehler: {e}") + + finally: + client.close() + +def checkGoogle(): + try: + response = requests.get("https://www.google.com", timeout=5) + if response.status_code == 200: + return True + else: + return False + except requests.ConnectionError: + return False + except requests.Timeout: + return False + except Exception as e: + return False + +while True: + sshVerbindung() + time.sleep(10) + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..fa72071 --- /dev/null +++ b/readme.md @@ -0,0 +1,9 @@ +#SSH Internet Skript + +## Verzeichnis Aufbau + +´ +- Root +|- etc/init.d/sshinternet +|- etc/openwrt_scripts/internet.py +´ \ No newline at end of file diff --git a/sshinternet b/sshinternet new file mode 100644 index 0000000..33953eb --- /dev/null +++ b/sshinternet @@ -0,0 +1,39 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +START=99 +STOP=01 +NAME=sshinternet +DEPENDS="network" + +start_service() { + procd_open_instance + procd_set_param command /usr/bin/python3 /etc/openwrt_scripts/internet.py + procd_set_param respawn + procd_set_param env HOME=/root + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param user root + procd_set_param pidfile /var/run/${NAME}.pid + procd_close_instance +} + +stop_service() { + pid=$(cat /var/run/${NAME}.pid 2>/dev/null) + [ -n "$pid" ] && { + logger -t "$NAME" "Stopping PID $pid" + kill $pid + timeout=10 + while kill -0 $pid 2>/dev/null && [ $timeout -gt 0 ]; do + sleep 1 + timeout=$((timeout-1)) + done + [ $timeout -eq 0 ] && kill -9 $pid 2>/dev/null + } + rm -f /var/run/${NAME}.pid +} + +reload_service() { + stop + start +} \ No newline at end of file