use requests for offline test

This commit is contained in:
Roy Olav Purser 2021-11-03 08:51:41 +01:00
parent f76b3807b9
commit 82e8db22f6
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -1,13 +1,17 @@
#!/usr/bin/env python3
import configparser
import subprocess
import requests
import re
import io
def offline():
expr = re.compile("ips:[^()]+handshake")
proc = subprocess.run(["wg", "show", "vpn"], capture_output=True, encoding="utf-8")
return len(expr.findall(proc.stdout)) == 0
try:
requests.head("https://1.1.1.1", timeout=1)
except Exception:
return True
else:
return False
def rotate_conf():
iface = None