first commit
This commit is contained in:
+49
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#SSH Internet Skript
|
||||||
|
|
||||||
|
## Verzeichnis Aufbau
|
||||||
|
|
||||||
|
´
|
||||||
|
- Root
|
||||||
|
|- etc/init.d/sshinternet
|
||||||
|
|- etc/openwrt_scripts/internet.py
|
||||||
|
´
|
||||||
+39
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user