Skip to content

Instantly share code, notes, and snippets.

@meeuw
Last active September 13, 2018 20:30
Show Gist options
  • Save meeuw/5765413 to your computer and use it in GitHub Desktop.
Save meeuw/5765413 to your computer and use it in GitHub Desktop.
Python script to create, using dbus, an adhoc wifi connection
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))
@laneschmidt
Copy link

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