Posted By

jakswa on 02/18/09


Tagged

python os popen sys iwevent iwconfig


Versions (?)

Detect SSID Change Python


 / Published in: Python
 

Me trying to not be a noob in python.

Yes, I know my noob is probably showing.

  1. #! /usr/bin/env python
  2.  
  3. from subprocess import Popen,PIPE
  4. import re, dbus, gtk, glib, sys, os
  5.  
  6. def checkCurrentSsid():
  7. ssidpat = re.compile('ESSID:"([^"]*)"')
  8. iwconf = Popen(['iwconfig'], stdout=PIPE).communicate()[0]
  9. if ssidpat.search(iwconf):
  10. ssid = ssidpat.search(iwconf).groups()[0]
  11. print "ssid ....... " +ssid
  12.  
  13. iwpipe = os.popen('iwevent','r')
  14.  
  15. while 1:
  16. iwoutput = iwpipe.readline()
  17. if (iwoutput.find("New Access") != -1 and iwoutput.find('Not-Associated') == -1):
  18. print "iwoutput ... " +iwoutput
  19. checkCurrentSsid()

Report this snippet  

You need to login to post a comment.