def get_active_connection_info(self, ac_path):
bus = dbus.SystemBus()
wifi = bus.get_object('org.freedesktop.NetworkManager', ac_path)
iface = dbus.Interface(wifi, dbus_interface='org.freedesktop.DBus.Properties')
# creating proxy 'Get' method
m = iface.get_dbus_method("Get", dbus_interface=None)
# getting Id of active connection
Id = m("org.freedesktop.NetworkManager.Connection.Active", "Id")
# getting Type of active connection
Type = m("org.freedesktop.NetworkManager.Connection.Active", "Type")
# getting Uuid of active connection
Uuid = m("org.freedesktop.NetworkManager.Connection.Active", "Uuid")
# getting State of active connection
State = m("org.freedesktop.NetworkManager.Connection.Active", "State")
# NOTE:
# this function only returns properties like Id, Type, Uuid, State of an active connection
# However, other properties like Dhcp4Config, Dhcp6Config, Ip4Config, Ip6Config etc. can also be obtained
return (str(Id), str(Type), str(Uuid), int(State))
评论列表
文章目录