2011-05-12 linux python network manager internet
Скрипт каждые 30 сек. проверяет наличие интернета, если пинг отсутствует, то вызывает команду включения/переподключения соединения из network manager.
Посмотреть uuid нужного соединения можно командой:
nmcli con list
#!/usr/bin/python
# coding: utf8
# list connections: nmcli con list
import os
import subprocess
import time
host = 'ya.ru'
uuid = '27534a5a-bbc3-4a35-8d73-f6a254b76051'
while True:
try:
print 'ping'
PIPE = subprocess.PIPE
p = subprocess.Popen(['ping',host,'-c','3'], stdout=PIPE)
s = p.stdout.read()
print s
if not 'time=' in s: os.system('nmcli con up uuid "%s"' % uuid)
except Exception as e:
print e
time.sleep(30)