基本信息
源码名称:C# 启动、停止 wifiap例子源码
源码大小:0.04M
文件格式:.zip
开发语言:C#
更新时间:2015-08-04
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Diagnostics; using System.Security.Principal; using System.Windows.Forms; namespace WiFiAP { static class Program { /// <summary> /// Punto de entrada principal para la aplicación. /// </summary> // Added global string to refer the name of this application. public static string ApplicationName = "WiFiAP"; [STAThread] static void Main() { // Before start, checks if program has been run as admin if (!checkAdmin()) { MessageBox.Show(ApplicationName " has not been run with admin privileges", "Admin check failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Application.Exit(); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); WifiController wc = new WifiController(); Application.Run(new MainPanel()); } } static bool checkAdmin() { var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); return principal.IsInRole(WindowsBuiltInRole.Administrator); } } public class WifiController { public WifiController() { } /// <summary> /// This function calls "netsh wlan" args through cmd /// </summary> /// <param name="args">arguments</param> /// <returns></returns> public String controller(string args) { string res = "FAIL"; var pProcess = new System.Diagnostics.Process { StartInfo = { FileName = "cmd.exe", Arguments = "/C netsh wlan " args, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, WorkingDirectory = "C:\\" } }; pProcess.Start(); res = pProcess.StandardOutput.ReadToEnd(); pProcess.Close(); return res; } /// <summary> /// Starts WiFi AP by using "start hostednetwork" /// </summary> public String StartAP() { string res = "FAIL"; res = controller("start hostednetwork"); Console.WriteLine(res); return res; } public String StopAP() { string res = "FAIL"; res = controller("stop hostednetwork"); Console.WriteLine(res); return res; } /// <summary> /// Returns Status using "show hostednetwork" /// </summary> public String getStatus() { string res = "UNKNOWN"; res = controller("show hostednetwork"); string status = "Estado : "; int aux = res.IndexOf(status) status.Length; res = res.Substring(aux, res.IndexOf("\n",aux) - aux); return res; } public String getSSID() { string res = "UNKNOWN"; res = controller("show hostednetwork"); string status = "Nombre de SSID : "; int aux = res.IndexOf(status) status.Length 1; res = res.Substring(aux, res.IndexOf("\n", aux) - aux-2); return res; } } }