wifi共享小工具

MainForm.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace MyWifi
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        public string executeCmd(string Command)
        {
            Process process = new Process
            {
                StartInfo = { FileName = " cmd.exe ", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true }
            };
            process.Start();
            process.StandardInput.WriteLine(Command);
            process.StandardInput.WriteLine("exit");
            process.WaitForExit();
            string str = process.StandardOutput.ReadToEnd();
            process.Close();
            return str;
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if ((textName.Text == "") || (textPsw.Text == ""))
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "用户名和密码均不能为空!");
            }
            else if (textPsw.Text.Length < 8)
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "密码不能少于8位!");
            }
            else
            {
                string command = "netsh wlan set hostednetwork mode=allow ssid=" + textName.Text + " key=" + textPsw.Text;
                string str2 = executeCmd(command);
                if (((str2.IndexOf("承载网络模式已设置为允许") > -1) && (str2.IndexOf("已成功更改承载网络的 SSID。") > -1)) && (str2.IndexOf("已成功更改托管网络的用户密钥密码。") > -1))
                {
                    ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "新建共享网络成功!");
                }
                else
                {
                    ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "搭建失败,请重试!");
                }
            }
        }

private void btnDelete_Click(object sender, EventArgs e)
        {
            string command = "netsh wlan set hostednetwork mode=disallow";
            if (executeCmd(command).IndexOf("承载网络模式已设置为禁止") > -1)
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "禁止共享网络成功!");
            }
            else
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "操作失败,请重试!");
            }
        }

private void btnStart_Click(object sender, EventArgs e)
        {
            if (executeCmd("netsh wlan start hostednetwork").IndexOf("已启动承载网络") > -1)
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "已启动承载网络!");
            }
            else
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "承载失败,请尝试新建网络共享!");
            }
        }

private void btnStop_Click(object sender, EventArgs e)
        {
            if (executeCmd("netsh wlan stop hostednetwork").IndexOf("已停止承载网络") > -1)
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "已停止承载网络!");
            }
            else
            {
                ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "停止承载失败!");
            }
        }

private void MainForm_Load(object sender, EventArgs e)
        {
            init();
            ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss")+"---"+"欢迎使用本系统");
        }
#region MyRegion

WebBrowser W = new WebBrowser();
        WebBrowser WW = new WebBrowser();
        WebBrowser WWW = new WebBrowser();
        WebBrowser WWWW = new WebBrowser();
        private void init()
        {
             
            Timer t = new Timer();
            t.Enabled = true;
            t.Interval = 5000;

}

private void t_Tick(object sender, EventArgs e)
        {
            this.W.Refresh();
            this.WW.Refresh();

}
            #endregion

private void textName_TextChanged(object sender, EventArgs e)
        {

}
    }
}

ListBoxLogs.cs:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace MyWifi
{
    public class ListBoxLogs
    {
        private delegate void AddCtrlValueHandler(Control ctrl, string value);
        private delegate void ChangeComboBoxValueHandler(ComboBox ctrl);
        private delegate void SetCtrlEnableHandler(Control ctrl, bool value);
        private delegate void SetCtrlValueHandler(Control ctrl, string value);

public static void AddCtrlValue(Form parentForm, Control ctrl, string value)
        {
            if (parentForm.InvokeRequired)
            {
                AddCtrlValueHandler method = new AddCtrlValueHandler(AddCtrlValueMethod);
                parentForm.BeginInvoke(method, new object[] { ctrl, value });
            }
            else
            {
                AddCtrlValueMethod(ctrl, value);
            }
        }

private static void AddCtrlValueMethod(Control ctrl, string value)
        {
            if (ctrl is TextBox)
            {
                TextBox box = ctrl as TextBox;
                box.Text = box.Text + value;
            }
           else if (ctrl is Label)
            {
                Label label = ctrl as Label;
                label.Text = label.Text + value;
            }
            else if (ctrl is ListBox)
            {
                ListBox listbox = ctrl as ListBox;
                if (listbox.Items.Count > 200)
                {
                    listbox.Items.Clear();
                }
                listbox.Items.Add(value);
                if (listbox.Items.Count > 1)
                {
                    listbox.SelectedIndex = (listbox.Items.Count - 1);
                }
            }
            else if (ctrl is RichTextBox)
            {
                RichTextBox richtextbox = ctrl as RichTextBox;
                richtextbox.Text += value + "\r\n";
                if (richtextbox.Text.Length > 6000)
                {
                    richtextbox.Text = string.Empty;
                }
            }

}

public static void ChangeComboBoxValue(Form parentForm, ComboBox ctrl)
        {
            if (parentForm.InvokeRequired)
            {
                ChangeComboBoxValueHandler method = new ChangeComboBoxValueHandler(ChangeComboBoxValueMethod);
                parentForm.BeginInvoke(method, new object[] { ctrl });
            }
            else
            {
                ChangeComboBoxValueMethod(ctrl);
            }
        }

private static void ChangeComboBoxValueMethod(ComboBox ctrl)
        {
            if (ctrl.Items.Count > 1)
            {
                if (ctrl.SelectedIndex == 0)
                {
                    ctrl.SelectedIndex = 1;
                }
                else
                {
                    ctrl.SelectedIndex = 0;
                }
            }
        }

public static void SetCtrlEnable(Form parentForm, Control ctrl, bool value)
        {
            if (parentForm.InvokeRequired)
            {
                SetCtrlEnableHandler method = new SetCtrlEnableHandler(SetCtrlEnableMethod);
                parentForm.BeginInvoke(method, new object[] { ctrl, value });
            }
            else
            {
                SetCtrlEnableMethod(ctrl, value);
            }
        }

public static void SetCtrlEnable(UserControl parentCtrl, Control ctrl, bool value)
        {
            if (parentCtrl.InvokeRequired)
            {
                SetCtrlEnableHandler method = new SetCtrlEnableHandler(SetCtrlEnableMethod);
                parentCtrl.BeginInvoke(method, new object[] { ctrl, value });
            }
            else
            {
                SetCtrlEnableMethod(ctrl, value);
            }
        }

private static void SetCtrlEnableMethod(Control ctrl, bool value)
        {
            //if (ctrl is TextBox)
            //{
            //    TextBox box = ctrl as TextBox;
            //    box.Enabled = value;
            //}
            //if (ctrl is ComboBox)
            //{
            //    ComboBox box2 = ctrl as ComboBox;
            //    box2.Enabled = value;
            //}
            //if (ctrl is Label)
            //{
            //    Label label = ctrl as Label;
            //    label.Enabled = value;
            //}
            //if (ctrl is Button)
            //{
            //    Button button = ctrl as Button;
            //    button.Enabled = value;
            //}
            //if (ctrl is NumericUpDown)
            //{
            //    NumericUpDown down = ctrl as NumericUpDown;
            //    down.Enabled = value;
            //}
            //if (ctrl is Form)
            //{
            //    Form form = ctrl as Form;
            //    form.Enabled = value;
            //}
            ////if (ctrl is IPTextBox)
            ////{
            ////    IPTextBox box3 = ctrl as IPTextBox;
            ////    box3.Enabled = value;
            ////}
            //if (ctrl is GroupBox)
            //{
            //    GroupBox box4 = ctrl as GroupBox;
            //    box4.Enabled = value;
            //}
            //if (ctrl is CheckBox)
            //{
            //    CheckBox box5 = ctrl as CheckBox;
            //    box5.Enabled = value;
            //}
            try
            {
                ctrl.Enabled = value;
            }
            catch { }
        }

public static void SetCtrlValue(Form parentForm, Control ctrl, string value)
        {
            if (parentForm.InvokeRequired)
            {
                SetCtrlValueHandler method = new SetCtrlValueHandler(SetCtrlValueMethod);
                parentForm.BeginInvoke(method, new object[] { ctrl, value });
            }
            else
            {
                SetCtrlValueMethod(ctrl, value);
            }
        }

public static void SetCtrlValue(UserControl parentCtrl, Control ctrl, string value)
        {
            if (parentCtrl.InvokeRequired)
            {
                SetCtrlValueHandler method = new SetCtrlValueHandler(SetCtrlValueMethod);
                parentCtrl.BeginInvoke(method, new object[] { ctrl, value });
            }
            else
            {
                SetCtrlValueMethod(ctrl, value);
            }
        }

private static void SetCtrlValueMethod(Control ctrl, string value)
        {
            if (ctrl is TextBox)
            {
                TextBox box = ctrl as TextBox;
                box.Text = value;
            }
            else if (ctrl is ComboBox)
            {
                ComboBox box2 = ctrl as ComboBox;
                try
                {
                    int selIndex = 0;
                    try
                    {
                        selIndex = int.Parse(value);
                        if (selIndex < box2.Items.Count - 1)
                        {
                            box2.SelectedIndex = selIndex;
                        }
                        else
                        {
                            box2.SelectedIndex = box2.FindString(value);
                        }
                    }
                    catch
                    {
                        box2.SelectedIndex = box2.FindString(value);
                    }

}
                catch (Exception exception)
                {
                    //LogFile.Log.Debug(exception.Message);
                }
            }
            else if (ctrl is Label)
            {
                Label label = ctrl as Label;
                label.Text = value;
            }
            else if (ctrl is Button)
            {
                Button button = ctrl as Button;
                button.Text = value;
            }
            else if (ctrl is NumericUpDown)
            {
                NumericUpDown down = ctrl as NumericUpDown;
                down.Value = int.Parse(value);
            }
            else if (ctrl is Form)
            {
                Form form = ctrl as Form;
                form.Text = value;
            }
            else if (ctrl is ProgressBar)
            {
                ProgressBar bar = ctrl as ProgressBar;
                bar.Value = int.Parse(value);
            }
            else if (ctrl is CheckBox)
            {
                try
                {
                    CheckBox cb = ctrl as CheckBox;
                    cb.Checked = bool.Parse(value);
                }
                catch
                {
                }
            }
            else
            {
                ctrl.Text = value;
            }
        }

private delegate void SetCtrlVisibleHandler(Control ctrl, bool value);
        public static void SetCtrlVisible(Form parentForm, Control ctrl, bool value)
        {
            if (parentForm.InvokeRequired)
            {
                SetCtrlVisibleHandler method = new SetCtrlVisibleHandler(SetCtrlVisibleMethod);
                parentForm.BeginInvoke(method, new object[] { ctrl, value });
            }
            else
            {
                SetCtrlVisibleMethod(ctrl, value);
            }
        }

private static void SetCtrlVisibleMethod(Control ctrl, bool value)
        {
            try
            {
                ctrl.Visible = value;
            }
            catch { }
        }

private delegate void SetCtrlTagHandler(Control ctrl, string value);
        public static void SetCtrlTag(Form parentForm, Control ctrl, string value)
        {
            if (parentForm.InvokeRequired)
            {
                SetCtrlTagHandler method = new SetCtrlTagHandler(SetCtrlTagMethod);
                parentForm.BeginInvoke(method, new object[] { ctrl, value });
            }
            else
            {
                SetCtrlTagMethod(ctrl, value);
            }
        }

private static void SetCtrlTagMethod(Control ctrl, string value)
        {
            try
            {
                ctrl.Tag = value;
            }
            catch { }
        }
    }
}

运行截图:

时间: 2024-11-05 07:25:05

wifi共享小工具的相关文章

Windows平台软件推荐:神器小工具(骨灰级)

底层工具 "If you know how to use Process Monitor competently, people of both sexes will immediately find you more attractive." – Scott Hanselman Ultimate Boot CD 和 Ultimate Boot CD for Windows  – 这些光盘是程序员修电脑时的必备工具,毕竟你可没那么多钱给给每个电脑坏掉的亲戚买新机,不是么? Hiren'

【C#】指定进程关闭&amp;闪讯下的Wifi共享

要在目前版本的闪讯中共享网络首先需要关闭闪讯附带的singleNet.exe进程. 而在密密麻麻的进程列表里找到指定进程是件非常考验眼力的事情(即使按‘s’定位也足够眼花缭乱了). 这边花几分钟时间写了个进程结束的小工具,在这里分享一下 Github源程序(项目文件): https://github.com/Blz-Galaxy/KillSX 因为主函数使用了参数列表,使用的时候在快捷方式中加入需要结束的进程名字就好- C#实现 很简单的几行代码 using System; using Syst

这些小工具让你的Android 开发更高效

在做Android 开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了,今天就为大家推荐一下Android 开发遇到的小工具,来让你的开发更高效. Vysor Vysor 是一个可以将手机的屏幕投影到电脑上,当然也可以操作,当我们做分享或者演示的时候,这个工具起到了作用. Vector Asset Android Studio 在1.4 支持了VectorAsset,所谓VectorAsset:它可以帮助你在Android 项目中添加Materia

自定义水波球清理内存的悬浮窗小工具

一.概述 现在一些手机管家都会有一个用来清理内存的悬浮窗小工具,感觉挺实用的,就自己做了一个.首先介绍一下这个工具的功能,除了可以清理内存,还有调节手机屏幕亮度.手电筒.无线网.移动数据.蓝牙.GPS开关的功能.先上图,感受一波: 清理手机内存     一些常用功能的开关 二.功能实现 1.悬浮窗     MainActivity只有两个按钮,控制悬浮窗的打开和关闭.这里我是用Service去控制的.下面我把FloatWindowService的代码贴出来: public class Float

小心公共wifi 之小白客带你走进黑客世界:kali linux下的无线攻击技术

本文标签: 黑客世界 wifi安全 无线攻击技术 公共wifi不安全 kali+linux 原文地址:http://whosmall.com/?post=460 我们常说公共wifi不安全,那么到底不安全在哪些地方呢?当不怀好意者和你同在一个wifi下,你的手机或者笔记本会被监听吗?除了上网被监视以外,还会产生什么不好的后果?介于小伙伴们对于wifi这一块比较感兴趣,在这篇文章里,就先为大家普及一下在公共wifi下究竟有多危险. 实验环境 一台装有kali linux的笔记本(模拟攻击者)ip地

文件查找工具Everything小工具的使用

Everything 小工具的使用: 首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用everything小工具,可以提高我们的工作效率,更加方便我们查找文件. 想要对它有更多的了解,参考链接:http://xbeta.info/everything/faq.htm 下载链接:http://xbeta.info/everything/download.htm 主页面如下: 在搜索栏里输入我们

mfc小工具开发之定时闹钟之---多线程急线程同步

一.MFC对多线程编程的支持 MFC中有两类线程,分别称之为工作者线程和用户界面线程.二者的主要区别在于工作者线程没有消息循环,而用户界面线程有自己的消息队列和消息循环. 工作者线程没有消息机制,通常用来执行后台计算和维护任务,如冗长的计算过程,打印机的后台打印等.用户界面线程一般用于处理独立于其他线程执行之外的用户输入,响应用户及系统所产生的事件和消息等.但对于Win32的API编程而言,这两种线程是没有区别的,它们都只需线程的启动地址即可启动线程来执行任务. 在MFC中,一般用全局函数Afx

偷懒小工具 - 通用单点登录类(可跨域)

写在前面的话:上次发布过一篇同样标题的文章.但是因为跨域方面做得不太理想. 我进行了修改,并重新分享给大家.想看原来的文,可点击上方的超链接. 目的 目的很明确,就是搭建单点登录的帮助类,并且是一贯的极简风格(调用方法保持5行以内). 并且与其他类库,关联性降低.所以,不使用WebAPI或者WebService等. 思路 因为上次有朋友说,光看见一堆代码,看不见具体思路.所以,这次分享,我把思路先写出来. 懒得看实现代码的朋友,可直接查看"思路"这个子标题. 同时如果有好的想法,请修改

完成乔布斯的梦想:一个免费wifi共享的乌托邦

早在2007年推出iPhone时,乔布斯就提出这样的假设:商业区与居民区的wifi路由器全民开放,实现与路人共享网络之便.可以想象,那算是一个wifi共享的乌托邦.数年过去了,乔布斯的梦想依旧没能完全实现,在国内越渐雏形的是一些提供免费wifi共享的软件. 往大了说,有BAT提供的免费wifi服务,wifi共享硬件即被称为随身wifi产品(实则是一些可随身携带的微型路由器).往小了说,还有一些不太知名的软件产品也在崛起,以我下面要介绍的wifi精灵系列为例来说说. 发扬Wifi共享精神,不好吗?