Last active
February 4, 2019 22:05
-
-
Save spookyahell/b11585ba814b05f27d6aba4f662a57b7 to your computer and use it in GitHub Desktop.
Check the internet connection reliably... firefox is faster due to transferring less data and as we know is also more safe... Google is maybe even more reliable (never seen detectportal down though either)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def CheckNet(source = 'F'): | |
sources = {'G':'https://www.google.com','F':'http://detectportal.firefox.com/success.txt'} | |
find_in_text = {'G':'maxlength="2048" name="q"','F':'success'} | |
if source in sources: | |
src = sources[source] | |
else: | |
raise NotImplementedError('Source unavailable') | |
try: | |
r = requests.get(src, timeout = 10) | |
if find_in_text[source] in r.text: | |
return True | |
else: | |
return False | |
except: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment