From b4f58ec1b4e3cf15c439a9a06ee16d72b64852b0 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Mon, 17 Apr 2023 04:09:07 +0530 Subject: Using detectportal.firefox.com used by firefox to detect captive portal through requests --- auto-login.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/auto-login.py b/auto-login.py index 36b7fa0..01bb5b0 100644 --- a/auto-login.py +++ b/auto-login.py @@ -1,11 +1,21 @@ import time import subprocess +import requests w_user=subprocess.run(["pass","wifi-user"], capture_output=True).stdout.decode().strip() w_pass=subprocess.run(["pass","wifi-pass"], capture_output=True).stdout.decode().strip() cmd = "netstat -nr | grep -w 'UG'| awk '{print $2}'" -pipedps=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) -gateway=pipedps.communicate()[0].decode().strip() + +#Better implementation to get the captive portal url +url = 'http://detectportal.firefox.com/canonical.html' +expected_response = b'I am not a portal' + +response = requests.get(url) + +if response.content == expected_response: + print('Not behind a captive portal') +else: + print('Behind a captive portal') from selenium import webdriver from selenium.webdriver.common.by import By -- cgit v1.2.3