Next Generation Emulation banner

1 - 2 of 2 Posts

·
Memories are all I have..
Joined
·
423 Posts
Discussion Starter #1
hey guys, i have this piece of code:
Code:
ManagementClass mc = new ManagementClass("root\\WMI","MSNdis_80211_ServiceSetIdentifier", null);
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
	string wlanCard = (string)mo["InstanceName"];
	bool active = (bool)mo["Active"];
	byte[] ssid = (byte[])mo["Ndis80211SsId"];
	string ssidString = Encoding.ASCII.GetString(ssid);

	label1.Text = string.Format("{0}\r\n{1}\r\n{2}", wlanCard, active, ssidString);
	Console.WriteLine("{0}\r\n{1}\r\n{2}", wlanCard, active, ssidString);
	Console.WriteLine();
}
Basically what it does is that it detects your wireless network and outputs it. Now problem is that when i view the output in console mode, i can see everything clearly. The ssid mainly.
However, if i output it to the label1.Text ... all i get is a giant dot in the label. Im guessing the encoding is wrong, but after trying every single encoding avaliable, im kinda lost.

Any ideas?
 

·
I'm in despair!
Joined
·
3,420 Posts
Weird, I had already posted a response to this question. :p

Anyway, when I ran your code here I noticed that the first 4 bytes of the ssid bytearray were 0x0A, 0x00, 0x00 and 0x00, and only int the 5th byte the actual name of the ssid started.

I changed the code to cut those first 4 bytes, and it seemed to work alright:

Code:
ManagementClass mc = new ManagementClass("root\\WMI","MSNdis_80211_ServiceSetIdentifier", null);
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
	string wlanCard = (string)mo["InstanceName"];
	bool active = (bool)mo["Active"];
	byte[] buffer = (byte[])mo["Ndis80211SsId"];
	byte[] ssid = new Byte[buffer.Length-4];

	for(int i=4;i<buffer.Length;i++)
	{
		ssid[i-4] = buffer[i];
	}

	string ssidString = Encoding.ASCII.GetString(ssid);

	MessageBox.Show(ssidString);
}
[]s Badaro
 
1 - 2 of 2 Posts
Top