假设我想以编程方式获取以太网卡的接口名称。这似乎有效:
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
返回:
method return sender=:1.5 -> dest=:1.135 reply_serial=2
variant string "eth0"
有什么方法可以去掉中间人org.freedesktop.DBus.Properties.Get
,更直接地检索财产吗?唉,将其作为方法调用是行不通的:
dbus-send --print-reply \
--type=method_call \
--system \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager/Devices/0 \
org.freedesktop.NetworkManager.Device.Interface
回报:
Error org.freedesktop.DBus.Error.UnknownMethod:
Method "Interface" with signature "" on interface
"org.freedesktop.NetworkManager.Device" doesn't exist
我问是因为必须调用 org.freedesktop.DBus.Properties.Get
看起来必须调用 aobject.getProp("someproperty")
而不是object.getSomeProperty()
在 Python/Java/等中。