C# 读取网卡、设置网上、自动连接Wifi

项目需求:

  1. 扫描所有可用wifi
  2. 连接指定wifi,根据 ssid和 pwd连接
  3. 设置网卡获取IP的方式:静态IP、DHCP

有了以上需求,分别对应写了三个方法

扫描wifi

public void ScanSSID()
        {
            WlanClient client = new WlanClient();
            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {
                // Lists all networks with WEP security
                Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                {
                    WIFISSID targetSSID = new WIFISSID();

                    targetSSID.wlanInterface = wlanIface;
                    targetSSID.wlanSignalQuality = (int)network.wlanSignalQuality;
                    targetSSID.SSID = GetStringForSSID(network.dot11Ssid);
                    //targetSSID.SSID = Encoding.Default.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength);

你可能感兴趣的:(.net,学习,工具包)