How do I get Python to know what Wifi the user is connected to?

假装没事ソ 提交于 2020-01-01 09:17:04

问题


I'm 14, pardon my Python knowlege. I'm trying to make this program that will only run while I'm at school (on the school's Wifi) using an if/else statement like this:

if ontheschoolwifi:
     Keep running the program
else:
     close the program because im not at school and wont need it

I'd like to know how to let python know how to get what wifi it is connected to. Thank you, in advance, for your help :)


回答1:


import subprocess

if "SchoolWifiName" in subprocess.check_output("netsh wlan show interfaces"):
    print "I am on school wifi!"



回答2:


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.



来源:https://stackoverflow.com/questions/33227160/how-do-i-get-python-to-know-what-wifi-the-user-is-connected-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!