mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Update ohcapi.py
A more elegant code to test the internet connection Signed-off-by: Frédéric <fmatray@users.noreply.github.com>
This commit is contained in:
@ -75,20 +75,16 @@ class ohcapi(plugins.Plugin):
|
||||
return
|
||||
|
||||
# Check if the internet is still available by pinging Google
|
||||
self.internet_active = False
|
||||
try:
|
||||
response = requests.get('https://www.google.com', timeout=5)
|
||||
if response.status_code == 200:
|
||||
self.internet_active = True
|
||||
except requests.ConnectionError:
|
||||
self.internet_active = False
|
||||
return
|
||||
|
||||
if response.status_code == 200:
|
||||
self.internet_active = True
|
||||
else:
|
||||
self.internet_active = False
|
||||
return
|
||||
|
||||
current_time = time.time()
|
||||
if current_time - self.last_run >= self.options['sleep']:
|
||||
if self.internet_active and current_time - self.last_run >= self.options['sleep']:
|
||||
self._run_tasks(agent)
|
||||
self.last_run = current_time
|
||||
|
||||
|
Reference in New Issue
Block a user