Skip to content

Instantly share code, notes, and snippets.

@edsoncelio
Last active July 25, 2018 13:32
Show Gist options
  • Save edsoncelio/d138e5f318bee04b3cdfc8b6a7ce8ec6 to your computer and use it in GitHub Desktop.
Save edsoncelio/d138e5f318bee04b3cdfc8b6a7ce8ec6 to your computer and use it in GitHub Desktop.
Função para recuperar endereço MAC da interface Wlan0 em c#
public void ShowNetworkInterfaces(Label label_mac)
{
var end_mac="";
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
//nics[1] eh a interface wlan0, sendo : nics[1] = eth0, nics[2] = wlan0
PhysicalAddress address = nics[2].GetPhysicalAddress();
byte[] bytes = address.GetAddressBytes();
for (int i = 0; i < bytes.Length; i++)
{
end_mac += bytes[i].ToString("X2").ToString();
}
//adicionar em uma label
label_mac.Text = "MAC: " + end_mac;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment