Commit d63f8192 authored by root's avatar root

working...

parent 042c992b
#!/usr/bin/env python3
import iwlist
import iw_parse
from pprint import pprint
import psutil
import sys
from shell_cmd import sh
try:
from setproctitle import setproctitle
setproctitle("fuswim")
except:
pass
boot=False
auto=False
def kill_proc(name, ops=False):
for process in psutil.process_iter():
if process.name() == name:
if ops:
if ops in process.cmdline():
process.kill()
else:
process.kill()
def start_wpa(interface):
kill_proc("dhclient", interface)
kill_proc("wpa_supplicant", interface)
sh("/sbin/wpa_supplicant -s -B -P /run/wpa_supplicant."+interface+".pid -i wlan0 -D nl80211,wext -C /run/wpa_supplicant")
if len(sys.argv) > 1 and sys.argv[1] == 'boot':
print(' * fuswim starts... ')
boot=True
auto=True
if len(sys.argv) > 1 and sys.argv[1] == 'auto':
auto=True
interface = "wlan0"
if sys.argv[-1] not in ['auto','boot',sys.argv[0]]:
interface = sys.argv[-1]
if not interface in psutil.net_if_stats().keys():
print("Interface "+interface+" doesn't exists. Exiting...")
sys.exit(1)
# check for wpa_supplicant
wpas = False
for process in psutil.process_iter():
if process.name() == 'wpa_supplicant':
if interface in process.cmdline():
wpas = True
if not wpas:
if auto not boot:
print("wpa_supplicant for "+interface+" not running, launch it... ")
start_wpa(interface)
else:
print("wpa_supplicant for "+interface+" not running, exiting... ")
sys.exit(1)
else:
if psutil.net_if_stats()[interface].isup:
if boot:
print("wpa_supplicant for "+interface+" already configured, exiting... ")
sys.exit(0)
else:
print("wpa_supplicant for "+interface+" already configured, reconfiguring it")
start_wpa(interface)
else:
print("wpa_supplicant for "+interface+" already configured, reconfiguring it")
start_wpa(interface)
from pprint import pprint
netw = iw_parse.get_interfaces(interface="wlan0")
pprint(netw)
# detect all networks...
#netw = iw_parse.get_interfaces(interface="wlan0")
#pprint(netw)
#networks = iwlist.parse(iwlist.scan('wlan0'))
#pprint(networks)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment