Last active
September 13, 2018 20:30
-
-
Save meeuw/5765413 to your computer and use it in GitHub Desktop.
Python script to create, using dbus, an adhoc wifi connection
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
import dbus | |
bus = dbus.SystemBus() | |
wpas_obj = bus.get_object("fi.w1.wpa_supplicant1", | |
"/fi/w1/wpa_supplicant1") | |
wpas = dbus.Interface(wpas_obj, "fi.w1.wpa_supplicant1") | |
path = wpas.CreateInterface({'Ifname':"wlan0"}) | |
if_obj = bus.get_object("fi.w1.wpa_supplicant1", path) | |
path = if_obj.AddNetwork({ | |
'ssid':"adhocname", | |
'mode':1, | |
'frequency':2412, | |
'proto':"WPA", | |
'key_mgmt':"NONE", | |
'pairwise':"NONE", | |
'group':'TKIP', | |
'psk':"verysecret123", | |
}, dbus_interface="fi.w1.wpa_supplicant1.Interface") | |
network = bus.get_object("fi.w1.wpa_supplicant1", path) | |
network.Set("fi.w1.wpa_supplicant1.Network", "Enabled", True, dbus_interface=dbus.PROPERTIES_IFACE) | |
print(network.GetAll("fi.w1.wpa_supplicant1.Network", dbus_interface=dbus.PROPERTIES_IFACE)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm running Ubuntu 16.04. I'll try what you said, thanks.