summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2015-08-24 11:01:09 +0200
committerJiří Klimeš <jklimes@redhat.com>2015-08-24 12:33:04 +0200
commitcb64067b7affab5656dc16a0d095c87fbff8c4ac (patch)
tree4844284a3bad1d21eb01c0c1ae47e90d76d1b377 /examples
parentd46a2c1af396a5d5b9cd95865f36544a8282076c (diff)
downloadNetworkManager-cb64067b7affab5656dc16a0d095c87fbff8c4ac.tar.gz
examples: add flags and mode parsing to show-wifi-networks.[lua|py]
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/lua/lgi/show-wifi-networks.lua43
-rwxr-xr-xexamples/python/gi/show-wifi-networks.py64
2 files changed, 107 insertions, 0 deletions
diff --git a/examples/lua/lgi/show-wifi-networks.lua b/examples/lua/lgi/show-wifi-networks.lua
index 69a065c67b..954fee701d 100755
--- a/examples/lua/lgi/show-wifi-networks.lua
+++ b/examples/lua/lgi/show-wifi-networks.lua
@@ -29,6 +29,11 @@
local lgi = require 'lgi'
local NM = lgi.NM
+function is_empty(t)
+ local next = next
+ if next(t) then return false else return true end
+end
+
function ssid_to_utf8(ap)
local ssid = ap:get_ssid()
if not ssid then return "" end
@@ -44,13 +49,51 @@ function print_device_info(device)
print(string.rep("=", info:len()))
end
+function flags_to_string(flags)
+ local str = ""
+ for flag, _ in pairs(flags) do
+ str = str .. " " .. flag
+ end
+ if str == "" then str = "NONE" end
+ return (str:gsub( "^%s", ""))
+end
+
+function flags_to_security(flags, wpa_flags, rsn_flags)
+ local str = ""
+ if flags["PRIVACY"] and is_empty(wpa_flags) and is_empty(rsn_flags) then
+ str = str .. " WEP"
+ end
+ if not is_empty(wpa_flags) then
+ str = str .. " WPA1"
+ end
+ if not is_empty(rsn_flags) then
+ str = str .. " WPA2"
+ end
+ if wpa_flags["KEY_MGMT_802_1X"] or rsn_flags["KEY_MGMT_802_1X"] then
+ str = str .. " 802.1X"
+ end
+ return (str:gsub( "^%s", ""))
+end
+
function print_ap_info(ap)
local strength = ap:get_strength()
local frequency = ap:get_frequency()
+ local flags = ap:get_flags()
+ local wpa_flags = ap:get_wpa_flags()
+ local rsn_flags = ap:get_rsn_flags()
+ -- remove extra NONE from the flags tables
+ flags["NONE"] = nil
+ wpa_flags["NONE"] = nil
+ rsn_flags["NONE"] = nil
print("SSID: ", ssid_to_utf8(ap))
print("BSSID: ", ap:get_bssid())
print("Frequency: ", frequency)
print("Channel: ", NM.utils_wifi_freq_to_channel(frequency))
+ print("Mode: ", ap:get_mode())
+ print("Flags: ", flags_to_string(flags))
+ print("WPA flags: ", flags_to_string(wpa_flags))
+ print("RSN flags: ", flags_to_string(rsn_flags))
+ print("Security: ", flags_to_security(flags, wpa_flags, rsn_flags))
print(string.format("Strength: %s %s%%", NM.utils_wifi_strength_bars(strength), strength))
print("")
end
diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py
index 7f3bd2dbb0..e35738ea5c 100755
--- a/examples/python/gi/show-wifi-networks.py
+++ b/examples/python/gi/show-wifi-networks.py
@@ -50,13 +50,77 @@ def print_device_info(device):
print info
print '=' * len(info)
+def mode_to_string(mode):
+ if mode == getattr(NM, '80211Mode').INFRA:
+ return "INFRA"
+ if mode == getattr(NM, '80211Mode').ADHOC:
+ return "ADHOC"
+ if mode == getattr(NM, '80211Mode').AP:
+ return "AP"
+ return "UNKNOWN"
+
+def flags_to_string(flags):
+ if flags & getattr(NM, '80211ApFlags').PRIVACY:
+ return "PRIVACY"
+ return "NONE"
+
+def security_flags_to_string(flags):
+ NM_AP_FLAGS = getattr(NM, '80211ApSecurityFlags')
+ str = ""
+ if flags & NM_AP_FLAGS.PAIR_WEP40:
+ str = str + " PAIR_WEP40"
+ if flags & NM_AP_FLAGS.PAIR_WEP104:
+ str = str + " PAIR_WEP104"
+ if flags & NM_AP_FLAGS.PAIR_TKIP:
+ str = str + " PAIR_TKIP"
+ if flags & NM_AP_FLAGS.PAIR_CCMP:
+ str = str + " PAIR_CCMP"
+ if flags & NM_AP_FLAGS.GROUP_WEP40:
+ str = str + " GROUP_WEP40"
+ if flags & NM_AP_FLAGS.GROUP_WEP104:
+ str = str + " GROUP_WEP104"
+ if flags & NM_AP_FLAGS.GROUP_TKIP:
+ str = str + " GROUP_TKIP"
+ if flags & NM_AP_FLAGS.GROUP_CCMP:
+ str = str + " GROUP_CCMP"
+ if flags & NM_AP_FLAGS.KEY_MGMT_PSK:
+ str = str + " KEY_MGMT_PSK"
+ if flags & NM_AP_FLAGS.KEY_MGMT_802_1X:
+ str = str + " KEY_MGMT_802_1X"
+ if str:
+ return str.lstrip()
+ else:
+ return "NONE"
+
+def flags_to_security(flags, wpa_flags, rsn_flags):
+ str = ""
+ if ((flags & getattr(NM, '80211ApFlags').PRIVACY) and
+ (wpa_flags == 0) and (rsn_flags == 0)):
+ str = str + " WEP"
+ if wpa_flags != 0:
+ str = str + " WPA1"
+ if rsn_flags != 0:
+ str = str + " WPA2"
+ if ((wpa_flags & getattr(NM, '80211ApSecurityFlags').KEY_MGMT_802_1X) or
+ (rsn_flags & getattr(NM, '80211ApSecurityFlags').KEY_MGMT_802_1X)):
+ str = str + " 802.1X"
+ return str.lstrip()
+
def print_ap_info(ap):
strength = ap.get_strength()
frequency = ap.get_frequency()
+ flags = ap.get_flags()
+ wpa_flags = ap.get_wpa_flags()
+ rsn_flags = ap.get_rsn_flags()
print "SSID: %s" % (ssid_to_utf8(ap))
print "BSSID: %s" % (ap.get_bssid())
print "Frequency: %s" % (frequency)
print "Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency))
+ print "Mode: %s" % (mode_to_string(ap.get_mode()))
+ print "Flags: %s" % (flags_to_string(flags))
+ print "WPA flags: %s" % (security_flags_to_string(wpa_flags))
+ print "RSN flags: %s" % (security_flags_to_string(rsn_flags))
+ print "Security: %s" % (flags_to_security(flags, wpa_flags, rsn_flags))
print "Strength: %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength)
print