[improvement] internet availability checking code

This commit is contained in:
Vinícius Moreira
2020-04-20 10:29:23 -03:00
parent 3e73797090
commit efd4179b7e
2 changed files with 10 additions and 8 deletions

View File

@@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [0.9.1] ## [0.9.1] 2020
### Improvements
- Internet availability checking code
### Fixes ### Fixes
- Arch - Arch
- wrong dialog titles - wrong dialog titles

View File

@@ -1,13 +1,12 @@
import subprocess import http.client as http_client
import traceback
from subprocess import Popen
def is_available() -> bool: def is_available() -> bool:
conn = http_client.HTTPConnection("www.google.com", timeout=5)
try: try:
res = Popen(['ping', '-q', '-w1', '-c1', 'google.com'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) conn.request("HEAD", "/")
res.wait() conn.close()
return res.returncode == 0 return True
except: except:
traceback.print_exc() conn.close()
return False return False