mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[improvement] internet availability checking code
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user