WlanHelper.cs

(开头部分) 9KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

// Created by Leestar54
// E-Mail:178078114@qq.com
using NativeWifi;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Wifi连接器
{
    /// <summary>
    /// Wlan小助手
    /// </summary>
    public static class WlanHelper
    {
        //是否联网dll
        [System.Runtime.InteropServices.DllImport("winInet.dll")]
        private static extern bool InternetGetConnectedState(ref int dwFlag, int dwReserved);


        /// <summary>
        /// 设置自动连接,有些系统通过xml设置无效,只能用cmd了
        /// </summary>
        /// <param name="profile"></param>
        public static void SetAutoConnect(string profile)
        {
            using (var p = new Process())
            {
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;    //输出信息重定向
                p.StartInfo.CreateNoWindow = true;
                //可能接受来自调用程序的输入信息  
                p.StartInfo.RedirectStandardInput = true;
                //由调用程序获取输出信息  
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();                    //启动线程
                p.StandardInput.WriteLine("netsh wlan set profileparameter name=\"" + profile + "\" connectionmode=auto");
                p.StandardInput.WriteLine("exit");
                p.WaitForExit();            //等待进程结束
            }
        }

        /// <summary>
        /// 一键连接wifi网络
        /// </summary>
        /// <param name="network">加密网络</param>
        /// <param name="password">密码</param>
        public static void ConnetWifi(WlanClient.WlanInterface wlanIface, Wlan.WlanAvailableNetwork network, string password)
        {
            string profile = GetStringForSSID(network.dot11Ssid);
            if (password != null)
            {
                string hex = StringToHex(profile);
                string authentication = GetAuthentication(network.dot11DefaultAuthAlgorithm);
                string authEncryption = GetEncryption(network.dot11DefaultCipherAlgorithm);
                string keytype = GetKeyType(authEncryption);
                string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>{2}</authentication><encryption>{3}</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>{4}</keyType><protected>false</protected><keyMaterial>{5}</keyMaterial></sharedKey></security></MSM></WLANProfile>", profile, hex, authentication, authEncryption, keytype, password);
                wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
                wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profile);
后面还有 196 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。