using regular expression to retrieve the BSSID of the networks
i run t开发者_如何学运维he following command in to retrieved the list of BSSIDs:
netsh wlan show networks mode=Bssid | findstr "SSID"
and i got this:
SSID 1 : John
BSSID 1 : b0:e7:54:f2:97:f9
SSID 2 : 2WIRE519
BSSID 1 : 00:1e:c7:fb:f5:89
SSID 3 : Home SCW
BSSID 1 : 00:1e:c7:fb:40:11
SSID 4 : CBV704W-AFE5
BSSID 1 : 00:1a:2b:57:2e:75
SSID 5 : neboi
BSSID 1 : 34:ef:44:76:e2:90
And now i want to store the individual BSSID by using regular expression and i try this:
"^[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]$
...but is not working. Can anyone help me with this? Here's some sample code:
string sPattern = "^[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]:[a-z0-9][a-z0-9]$";
if (Regex.IsMatch(result, sPattern))
Console.WriteLine("Pattern Found");
else
Console.WriteLine("Pattern Not Found");
Give this a try:
(?:[A-Fa-f0-9]{2}[:-]){5}(?:[A-Fa-f0-9]{2})
static Regex MyRegex = new Regex(
"([a-f0-9]{2}:){5}[a-f0-9]{2}",
RegexOptions.Compiled);
static bool isBSSID(string line)
{
return MyRegex.IsMatch(line);
}
void Main()
{
string lines =
"SSID 1 : John\n"+
"BSSID 1 : b0:e7:54:f2:97:f9\n"+
"SSID 2 : 2WIRE519\n"+
"BSSID 1 : 00:1e:c7:fb:f5:89\n"+
"SSID 3 : Home SCW\n"+
"BSSID 1 : 00:1e:c7:fb:40:11\n"+
"SSID 4 : CBV704W-AFE5\n"+
"BSSID 1 : 00:1a:2b:57:2e:75\n"+
"SSID 5 : neboi\n"+
"BSSID 1 : 34:ef:44:76:e2:90";
Console.WriteLine(isBSSID(lines)+"\n-----");
foreach (string line in lines.Split('\n'))
{
Console.WriteLine(isBSSID(line));
}
//result:
//True
//-----
//False
//True
//False
//True
//False
//True
//False
//True
//False
//True
}
精彩评论