I am running the command netsh wlan show interfaces
from Python using subprocess.check_output
and collecting it in a variable.
a = subprocess.check_output(["netsh","wlan","show","interfaces"])
And it is giving me output as:
>>> print a
>>> \r\nThere is 1 interface on the system: \r\n\r\n Name : Wireless Network Connection\r\n Description : Ralink RT3290 802.11bgn Wi-Fi Adapter\r\n GUID : 77cbe2d6-1a1e-41e7-be0a-3f18689c9ceb\r\n Physical address : c0:38:96:92:b7:1d\r\n State : connected\r\n SSID : PenguinWiFi\r\n BSSID : 6c:72:20:d2:f9:21\r\n Network type : Infrastructure\r\n Radio type : 802.11n\r\n Authentication : WPA2-Personal\r\n Cipher : CCMP\r\n Connection mode : Auto Connect\r\n Channel : 11\r\n Receive rate (Mbps) : 72\r\n Transmit rate (Mbps) : 72\r\n Signal : 100% \r\n Profile : PenguinWiFi \r\n\r\n Hosted network status : Not available\r\n\r\n'
I want to get the status of wlan from this output as "connected"
or "not connected"
.
For that I want to convert the above string into dictionary and want to use "state"
as a key so that I can get the value from a key and decide whether wlan
is connected or not connected.
But when I am converting it to a dictionary its giving error something like this:
>>> a_dict = dict(a)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a_dict = dict(a)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
I am not getting what is the real problem, its with the string or something else?