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

Posted on

Question :

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

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
     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 🙂

Answer #1:

import subprocess

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

Answer #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.

Answered By: flamenco

Answer #3:

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')
Answered By: Tejesh Teju

Leave a Reply

Your email address will not be published. Required fields are marked *