Created
April 10, 2015 20:28
-
-
Save hG3n/418b3c15c6ad90ee8812 to your computer and use it in GitHub Desktop.
OSX Wifi Terminal Tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import subprocess | |
import urwid | |
def filterNames(string): | |
temp = string.lstrip().split(' ') | |
return temp[0] | |
def getAvailableNetworks(): | |
#command used to get the available wifi networks | |
command = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport' | |
#get the command output and parse it to variable | |
p = subprocess.Popen([command,'scan'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output = [] | |
for line in p.stdout: | |
output.append(line) | |
output.pop(0) | |
networklist = [] | |
# get rid of the leading spaces, split by ' ' and pass the names into a list | |
for i in range(0, len(output)): | |
networklist.append(filterNames(output[i])) | |
return networklist | |
def connectToNetwork(network): | |
return true | |
def menu(title, choices): | |
body = [urwid.Text(title), urwid.Divider()] | |
for c in choices: | |
button = urwid.Button(c) | |
urwid.connect_signal(button, 'click', exit_program, c) | |
body.append(urwid.AttrMap(button, None, focus_map='reversed')) | |
return urwid.ListBox(urwid.SimpleFocusListWalker(body)) | |
def item_chosen(button, choice): | |
response = urwid.Text([u'You chose ', choice, u'\n']) | |
done = urwid.Button(u'Ok') | |
urwid.connect_signal(done, 'click', exit_program) | |
main.original_widget = urwid.Filler(urwid.Pile([response, | |
urwid.AttrMap(done, None, focus_map='reversed')])) | |
def exit_program(key): | |
if key in ('q', 'Q'): | |
raise urwid.ExitMainLoop() | |
# main function | |
def main(): | |
networklist = getAvailableNetworks() | |
main = urwid.Padding(menu(u'Networks', networklist), left=2, right=2) | |
top = urwid.Overlay(main, urwid.SolidFill(u' '), | |
align='center', width=('relative', 60), | |
valign='middle', height=('relative', 60), | |
min_width=20, min_height=9) | |
urwid.MainLoop(top, palette=[('reversed', 'standout', '')], | |
unhandled_input=exit_program).run() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment