disabled server.py check internet

This commit is contained in:
Justin 2022-03-02 19:25:42 +08:00 committed by GitHub
parent 15e839f6e3
commit 8afe025d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -412,23 +412,23 @@ def set_wifi():
os.system('wpa_cli -i wlan0 reconfigure') os.system('wpa_cli -i wlan0 reconfigure')
return index() return index()
def check_internet_connection(host='http://google.com'): #def check_internet_connection(host='http://google.com'):
try: #try:
urllib.request.urlopen(host) #Python 3.x #urllib.request.urlopen(host) #Python 3.x
return True #return True
except: #except:
return False #return False
def check_network_connection(): #def check_network_connection():
ps = subprocess.Popen(['iwconfig'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) #ps = subprocess.Popen(['iwconfig'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
try: #try:
output = subprocess.check_output(('grep', 'ESSID'), stdin=ps.stdout) #output = subprocess.check_output(('grep', 'ESSID'), stdin=ps.stdout)
return True #return True
except subprocess.CalledProcessError: #except subprocess.CalledProcessError:
# grep did not match any lines # grep did not match any lines
print("No wireless networks connected") #print("No wireless networks connected")
return False #return False
def edit_hosts(hostname): def edit_hosts(hostname):
current_hosts = open('/etc/hosts') current_hosts = open('/etc/hosts')