How do I get Python to know what Wifi the user is connected to?
Solution 1:
import subprocess
if "SchoolWifiName" in subprocess.check_output("netsh wlan show interfaces"):
print "I am on school wifi!"
Solution 2:
here some code that actually works, the other answers did not work for me on Windows...
import subprocess
wifi = subprocess.check_output(['netsh', 'WLAN', 'show', 'interfaces'])
data = wifi.decode('utf-8')
if "school_wifi_name" in data:
print("connected to speccific wifi")
else:
print("not connected")
Solution 3:
For Mac OS query the airport using os
module.
"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I"
Then, look the name assigned to SSID
by your school.
It should be something similar for the other operating systems.
Solution 4:
This will help you out to get the network name.
import subprocess
subprocess_result = subprocess.Popen('iwgetid',shell=True,stdout=subprocess.PIPE)
subprocess_output = subprocess_result.communicate()[0],subprocess_result.returncode
network_name = subprocess_output[0].decode('utf-8')