Say I want to programmatically get the interface name of my ethernet card. This seems to work:
dbus-send --print-reply \
--type=method_call \
--system \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager/Devices/0 \
org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.NetworkManager.Device \
string:Interface
Which returns:
method return sender=:1.5 -> dest=:1.135 reply_serial=2
variant string "eth0"
Is there some way of cutting out the middleman org.freedesktop.DBus.Properties.Get
and retrieve the property more directly? Alas, calling it as a method does not work:
dbus-send --print-reply \
--type=method_call \
--system \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager/Devices/0 \
org.freedesktop.NetworkManager.Device.Interface
Returns:
Error org.freedesktop.DBus.Error.UnknownMethod:
Method "Interface" with signature "" on interface
"org.freedesktop.NetworkManager.Device" doesn't exist
I ask because having to call org.freedesktop.DBus.Properties.Get
looks like having to call a object.getProp("someproperty")
instead of object.getSomeProperty()
in Python/Java/etc.
The dbus-send command is used to send a message to a D-Bus message bus. See https://www.freedesktop.org/wiki/Software/dbus/ for more information about the big picture.
Dbus is an Inter-Process Communication protocol (IPC). It allows multiple processes to exchange information in a standardized way. This is typically used to separate the back end system control from the user-facing interface.
Yep, you can do that if you use qdbus. I don't have NetworkManager with me, but a command like that should work:
qdbus --system \
org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager/Devices/0 \
org.freedesktop.NetworkManager.Device.Interface
There are various command-line clients for talking to D-Bus, some are more convenient than others. Here's the list of the ones I know.
dbus-send
(provided with D-Bus itself)gdbus
(provided by GLib)qdbus
(provided by Qt)busctl
(provided by systemd)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With