I have some devices that send a standard beacon and then a user data(38 bytes). So to get it I set a socket. I'm programming in C#.
private void buttonStart_Click(object sender, EventArgs e)
{
if (comboBoxInterfaces.SelectedIndex == -1)
{
MessageBox.Show("Select an Interface to capture the packets.", "WIFI Sniffer",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
if (!continue_capturing)
{
buttonStart.Text = "&Stop";
continue_capturing = true;
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(comboBoxInterfaces.SelectedItem.ToString()), 0));
mainSocket.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded,
true);
byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
byte[] byOut = new byte[4] { 1, 0, 0, 0 };
mainSocket.IOControl(IOControlCode.ReceiveAll,
byTrue,
byOut);
mainSocket.BeginReceive(byte_data, 0, byte_data.Length, SocketFlags.None,
new AsyncCallback(OnReceive), null);
}
else
{
buttonStart.Text = "&Start";
continue_capturing = false;
mainSocket.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "WIFI Sniffer", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
When I parse received packets I see only TCP, UDP packets also socket type - SocketType.Raw. How can I get beacons? May be I should configure it differently?