当前位置:首页 > Windows程序 > 正文

闪讯下快速分享Wifi(源码)

2021-05-24 Windows程序

标签:

  A.工具简介

最近忙着改论文,但迫于手机没有流量,反复共享电脑wifi的操作已经让我忍无可忍,而“猎豹wifi”“360wifi分享”等工具曾导致电脑多次睡死(可能是台式机的USB网卡兼容性问题)。因此抽空写了个便利工具,完全利用windows自带功能实现,主要合并了“命令提示符”的若干指令:

设置windows自带wifi热点;

开启、关闭wifi;

自动关机与取消;(主要是本人喜欢睡前趴床上再玩会手机,,又懒得起身关电脑)

以及部分.NET对系统进行管理:

关闭闪讯进程(避免闪讯锁定共享功能);

利用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]");//正则表达式 if (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); }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70475.html