blob: dba82261c09dacff037ff935d9bc7f6a0c333166 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#!/bin/sh
# vim: ft=sh ts=2 sts=2 sw=2 et ai
# -*- Mode: sh; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2011 - 2012 Red Hat, Inc.
#
#
# This example lists basic information about network interfaces known to NM.
# It finds the devices via GetDevices() D-Bus call and then gets properties of
# each device.
#
NM_SERVICE_NAME="org.freedesktop.NetworkManager"
NM_OBJECT_PATH="/org/freedesktop/NetworkManager"
DEVICE_IFACE="org.freedesktop.NetworkManager.Device"
NM_GET_DEVICES="org.freedesktop.NetworkManager.GetDevices"
DBUS_PROPERTIES_GET="org.freedesktop.DBus.Properties.Get"
# For the types see include/NetworkManager.h
devtype_to_name()
{
case $1 in
1) echo "Ethernet" ;;
2) echo "Wi-Fi" ;;
5) echo "Bluetooth" ;;
6) echo "OLPC" ;;
7) echo "WiMAX" ;;
8) echo "Modem" ;;
9) echo "InfiniBand" ;;
10) echo "Bond" ;;
11) echo "VLAN" ;;
12) echo "ADSL" ;;
13) echo "Bridge" ;;
14) echo "Generic" ;;
15) echo "Team" ;;
*) echo "Unknown" ;;
esac
}
state_to_name()
{
case $1 in
10) echo "Unmanaged" ;;
20) echo "Unavailable" ;;
30) echo "Disconnected" ;;
40) echo "Prepare" ;;
50) echo "Config" ;;
60) echo "Need Auth" ;;
70) echo "IP Config" ;;
80) echo "IP Check" ;;
90) echo "Secondaries" ;;
100) echo "Activated" ;;
110) echo "Deactivating" ;;
120) echo "Failed" ;;
*) echo "Unknown" ;;
esac
}
get_devices()
{
dbus-send --system --print-reply --dest=$NM_SERVICE_NAME $NM_OBJECT_PATH $NM_GET_DEVICES | \
grep "object path" | cut -d '"' -f2
}
get_device_property()
{
# first arg: device object path
# second arg: property name
# returns: property value
dbus-send --system --print-reply --dest=$NM_SERVICE_NAME "$1" $DBUS_PROPERTIES_GET string:$DEVICE_IFACE string:"$2" | \
grep "variant" | awk '{print $3}' | sed 's/"//g'
}
list_devices_details()
{
for device in `get_devices`
do
DEV_INTERFACE=`get_device_property "$device" "Interface"`
DEV_TYPE=`get_device_property "$device" "DeviceType"`
DEV_DRIVER=`get_device_property "$device" "Driver"`
DEV_STATE=`get_device_property "$device" "State"`
echo "============================"
echo "Interface: $DEV_INTERFACE"
echo "Type: `devtype_to_name $DEV_TYPE`"
echo "Driver: $DEV_DRIVER"
echo "State: `state_to_name $DEV_STATE`"
done
}
# print devices details
list_devices_details
|