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)) |
I've made some minor changes; it works for me on Fedora 28. You should run this script as root, edit the interface (wlan0) and if it fails somewhere, restart wpa_supplicant and rerun the script. You might also want to make the interface unmanaged for NetworkManager by adding:
[keyfile]
unmanaged-devices=mac:00:11:22:33:44:55
to /etc/NetworkManager/NetworkManager.conf
I'm running Ubuntu 16.04. I'll try what you said, thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Little old but I get error:
org.freedesktop.DBus.Error.UnknownMethod
when trying to calldbus.Interface()