![使用busctl和dbus读取systemd-networkd租赁信息](https://linux22.com/image/223619/%E4%BD%BF%E7%94%A8busctl%E5%92%8Cdbus%E8%AF%BB%E5%8F%96systemd-networkd%E7%A7%9F%E8%B5%81%E4%BF%A1%E6%81%AF.png)
我想使用busctl 读取Linux 中特定链接的systemd netowrkd 租用信息。
在busctl tree
我的系统上,我可以看到网络接口:
Service org.freedesktop.resolve1:
└─/org
└─/org/freedesktop
├─/org/freedesktop/LogControl1
└─/org/freedesktop/resolve1
├─/org/freedesktop/resolve1/dnssd
└─/org/freedesktop/resolve1/link
├─/org/freedesktop/resolve1/link/_31
├─/org/freedesktop/resolve1/link/_32
├─/org/freedesktop/resolve1/link/_33
├─/org/freedesktop/resolve1/link/_34
├─/org/freedesktop/resolve1/link/_35
├─/org/freedesktop/resolve1/link/_36
├─/org/freedesktop/resolve1/link/_37
├─/org/freedesktop/resolve1/link/_38
└─/org/freedesktop/resolve1/link/_39
当我检查链接接口时,我看到了我想要读取的 DHCP 服务器名称:
busctl introspect org.freedesktop.network1 /org/freedesktop/network1/link/_35
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
org.freedesktop.network1.DHCPServer interface - - -
.Leases property a(uayayayayt) 2 2 7 1 174 229 169 184 21 41 4 10 10 1… emits-change
org.freedesktop.network1.Link interface - - -
.Describe method - s -
.ForceRenew method - - -
.Reconfigure method - - -
.Renew method - - -
.RevertDNS method - - -
.RevertNTP method - - -
.SetDNS method a(iay) - -
.SetDNSEx method a(iayqs) - -
.SetDNSOverTLS method s - -
.SetDNSSEC method s - -
.SetDNSSECNegativeTrustAnchors method as - -
.SetDefaultRoute method b - -
.SetDomains method a(sb) - -
.SetLLMNR method s - -
.SetMulticastDNS method s - -
.SetNTP method as - -
.AddressState property s "routable" emits-change
.AdministrativeState property s "configured" emits-change
.BitRates property (tt) 18446744073709551615 184467440737095516… -
.CarrierState property s "carrier" emits-change
.IPv4AddressState property s "routable" emits-change
.IPv6AddressState property s "degraded" emits-change
.OnlineState property s "online" emits-change
.OperationalState property s "routable" emits-change
我似乎无法调用 Leases 方法:
busctl call org.freedesktop.network1 /org/freedesktop/network1/link/_35 org.freedesktop.network1.DHCPServer Leases
Call failed: Unknown method Leases or interface org.freedesktop.network1.DHCPServer.
我在这里做错了什么以及如何阅读租赁信息?谢谢。
答案1
正如表所示,Leases
它不是一种方法,而是一种方法财产。用来busctl get-property
阅读它。
busctl get-property org.freedesktop.network1 \
/org/freedesktop/network1/link/_35 \
org.freedesktop.network1.DHCPServer \
Leases
通过调用接口下的方法来访问属性org.freedesktop.DBus.Properties
;例如,“get-property”调用Get(interface, property)
,而“introspect”可能使用GetAll(interface)
.
busctl call org.freedesktop.network1 \
/org/freedesktop/network1/link/_35 \
org.freedesktop.DBus.Properties \
Get \
ss \
org.freedesktop.network1.DHCPServer \
Leases
(请记住,该房产包含已发出的租约经过网络充当 DHCP 服务器。 Networkd 不提供 D-Bus 访问它作为客户端收到的租约;您需要使用从 /run 读取文件的 C API。)