Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if the computer has a wifi adapter?

Which way can I decide the computer has a wifi adapter?
When I test my code it works, but I am uncertain, will it always work?

private bool hasWifi()
{
    try
    {
        WlanClient wlanclient = new WlanClient();
    }
    catch (System.ComponentModel.Win32Exception except)
    {
        return false;
    }

    return true;
}
like image 417
Döme Avatar asked May 12 '16 13:05

Döme


1 Answers

You can use the NetworkInterface.GetAllNetworkInterfaces to look at what is installed.

private bool hasWifi()
{
    return NetworkInterface.GetAllNetworkInterfaces()
        .Any(nic => nic.NetworkInterfaceType == NetworkInterfaceType.Wireless80211);
}
like image 133
Richard Avatar answered Oct 27 '22 07:10

Richard