【C#】Winform工具-閃訊下快速分享Wifi(源碼)

來源:互聯網
上載者:User

標籤:

 A.工具簡介

       最近忙著改論文,但迫於手機沒有流量,反覆共用電腦wifi的操作已經讓我忍無可忍,而“獵豹wifi”“360wifi分享”等工具曾導致電腦多次睡死(可能是台式機的USB網卡相容性問題)。因此抽空寫了個便利工具,完全利用windows內建功能實現,主要合并了“命令提示字元”的若干指令:

  1. 設定windows內建wifi熱點;
  2. 開啟、關閉wifi;
  3. 自動關機與取消;(主要是本人喜歡睡前趴床上再玩會手機,又懶得起身關電腦)

        以及部分.NET對系統進行管理:

  1. 關閉閃訊進程(避免閃訊鎖定共用功能);
  2. 利用windows內建的庫實現自動共用,避免手動設定。(很多人可能卡在這步上)

        經測試,本工具不影響閃訊心跳驗證,上網穩定,不會像手動共用那樣在幾分鐘後就會斷網。

        當然,如果不是浙江一帶的校園網使用者可能不需要閃訊這類進行撥號,直接開啟熱點進行分享即可。

   

        Github來源程式(專案檔): https://github.com/Blz-Galaxy/Tools-Wifi-Sharing

 

 B.指令與執行

相關命令提示字元(也可以用BAT指令碼方式調用)

  • 設定系統內建的虛擬網卡Microsoft Virtual WiFi Miniport Adapter,從而建立熱點(只需在首次使用前配置):
    netsh wlan set hostednetwork mode=allow ssid=Blz_Galaxy key=1234567890

      此處熱點標識為Blz_Galaxy,密碼為1234567890,請自行修改。

  • 開啟分享的Wifi熱點:
    netsh wlan start hostednetwork
  • 關閉Wifi熱點:
    netsh wlan stop hostednetwork
  • 定時關機(3600秒後關機):
    shutdown -s -t 3600
  • 設定關機後也可以取消關機計劃:
    shutdown -a

 

  • C#調用控制台指令方式:
    System.Diagnostics.Process _pCmd;_pCmd = new System.Diagnostics.Process();_pCmd.StartInfo.FileName = "cmd.exe";_pCmd.StartInfo.UseShellExecute = false;_pCmd.StartInfo.RedirectStandardOutput = true;_pCmd.StartInfo.RedirectStandardInput = true;_pCmd.StartInfo.CreateNoWindow = true;_pCmd.Start();//執行目標指令_pCmd.StandardInput.WriteLine("shutdown -a");

      再一例:

  • Regex reg = new Regex(@"[\u4e00-\u9fa5]");//Regexif (reg.IsMatch(textBox1.Text) || reg.IsMatch(textBox2.Text)){    MessageBox.Show("不能含有漢字");    return;}if (textBox2.Text.Length < 8){    MessageBox.Show("密碼8位以上");    return;}_strWrite = String.Format("netsh wlan set hostednetwork mode=allow ssid={0} key={1}", this.textBox1.Text, this.textBox2.Text);_pCmd.StandardInput.WriteLine(_strWrite);
 C.通過C# (.NET) 進行系統管理
  • 自動關閉指定進程(如閃訊的“singleNet”進程)

     取代了人工在工作管理員中尋找進程,解救密集恐懼症患者~

  • Process[] processes = Process.GetProcessesByName(ProcessName);foreach (Process instance in processes){    try    {        if (instance.ProcessName == ProcessName)            instance.Kill();;    }    catch { }

     

    具體可以參看:  【C#】指定進程關閉&閃訊下的Wifi共用

 

  • 調用\Windows\system32\hnetcfg.dll,即能使用“NETCONLib”實現自動共用 (關鍵)
    try{    string connectionToShare = this.textBox3.Text; // 被共用的網路連接    string sharedForConnection = this.textBox4.Text; // 需要共用的網路連接    NetSharingManager manager = new NetSharingManager();    var connections = manager.EnumEveryConnection;    foreach (INetConnection c in connections)    {        var props = manager.NetConnectionProps[c];        var sharingCfg = manager.INetSharingConfigurationForINetConnection[c];        if (props.Name == connectionToShare)        {            sharingCfg.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC);        }        else if (props.Name == sharedForConnection)        {            sharingCfg.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE);        }    }}catch{    MessageBox.Show("請開啟網路和共用中心·查看是不是已經串連Internet!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}

      取代手動進入“網際網路共用中心->更改適配器設定->singleNetPPPoE屬性->共用->勾選允許分享internet->選擇分享目標”這一連串操作,懶人福音~

      

【C#】Winform工具-閃訊下快速分享Wifi(源碼)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.