Skip to content

Commit

Permalink
implement wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfleischer committed May 24, 2022
1 parent 7dbae09 commit b73e323
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cloudmesh/burn/command/burn.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def execute(label, function):
if manager:
if not ssid:
ssid = get_ssid()
if ssid is None:
if ssid == "" or ssid is None:
Console.info('Wireless connection not detected. The user can specify the SSID when running '
'this command with --ssid=SSID. Skipping SSID')
else:
Expand Down
59 changes: 43 additions & 16 deletions cloudmesh/burn/wifi/ssid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,55 @@
from cloudmesh.common.systeminfo import os_is_mac
from cloudmesh.common.systeminfo import os_is_pi
from cloudmesh.common.systeminfo import os_is_windows
from cloudmesh.common.Printer import Printer
from cloudmesh.common.util import yn_choice
from cloudmesh.common.util import Console
import subprocess


def get_ssid():
ssid = ""
try:
if os_is_mac():
command = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I"
r = Shell.run(command).replace("\t", "").splitlines()
ssid = Shell.cm_grep(r, " SSID:")[0].split(":")[1].strip()
elif os_is_linux():
command = "iwgetid -r"
ssid = Shell.run(command).strip()
elif os_is_pi():
command = "iwgetid -r"
ssid = Shell.run(command).strip()
elif os_is_windows():
r = ""
if os_is_mac():
command = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I"
r = Shell.run(command).replace("\t", "").splitlines()
ssid = Shell.cm_grep(r, " SSID:")[0].split(":")[1].strip()
elif os_is_linux():
command = "iwgetid -r"
ssid = Shell.run(command).strip()
elif os_is_pi():
command = "iwgetid -r"
ssid = Shell.run(command).strip()
elif os_is_windows():
try:
try:
r = Shell.run('netsh wlan show interfaces').strip().splitlines()
ssid = Shell.cm_grep(r, ' SSID')[0].split(':')[1].strip()
except:
ssid = None
except: # noqa
pass
except subprocess.CalledProcessError as e:
if "The Wireless AutoConfig Service (wlansvc) is not running" in str(e.output):
print("Machine is not configured for wifi")
except:
command = "netsh wlan show profiles"
r = Shell.run(command) # .splitlines()
r = Shell.cm_grep(r, "User Profile")
r = [line.split(":")[1].strip() for line in r]
from cloudmesh.common.prettytable import PrettyTable
x = PrettyTable(["SSIDs"])
for item in r:
x.add_row([item])
x.align = "l"
x.align["SSID"] = "l"
looping = True
while looping:
print(x)
ssid = input('Enter ssid from list:\n')
if ssid not in r:
if not yn_choice(f'The entered SSID is not in the list. Are you sure you want to '
f'use {ssid}? (type Y and press Enter to use {ssid}) '):
Console.ok('Showing the list of SSIDs again...\n')
else:
looping = False
else:
looping = False

return ssid

0 comments on commit b73e323

Please sign in to comment.