using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics; namespace wifiGX
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int wifikg = 0;
private void Form1_Load(object sender, EventArgs e)
{ }
//cmd调用
private string InvokeCmd(string cmdArgs)
{
string Tstr = "";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start(); p.StandardInput.WriteLine(cmdArgs);
p.StandardInput.WriteLine("exit");
Tstr = p.StandardOutput.ReadToEnd();
p.Close();
return Tstr;
} private void button1_Click(object sender, EventArgs e)
{
if (okmima == 1 && okmingzi == 1)
{
try
{
string mingling = "netsh wlan set hostednetwork mode=allow ssid=" + mingzi.Text + " key=" + mima.Text;
string str = InvokeCmd(mingling);
richTextBox1.Text = str;
int cg = 0;
for (int i = 0; i < str.Length - 2; i++)
if (str.Substring(i, 2) == "成功")
cg++;
if (cg == 2)
{
richTextBox1.Text = "承载网络模式已设置为允许。\n已成功更改承载网络的 SSID。\n已成功更改托管网络的用户密钥密码。\n";
}
else
{
richTextBox1.Text = " 系统函数调用错误,可能原因是账号密码不规则(密码尽量只用数字和字母)";
} }
catch
{
richTextBox1 .Text =" 系统函数调用错误,可能原因是账号密码不规则(密码尽量只用数字和字母)";
}
}
else
{
MessageBox.Show("wifi名字或者密码长度不符合要求");
}
} private void button2_Click(object sender, EventArgs e)
{
try
{
string mingling = "netsh wlan start hostednetwork";
string str = InvokeCmd(mingling);
int mk = 0;
for(int i = 0;i < str.Length - 7;i ++)
{
if (str.Substring(i, 7) == "已启动承载网络")
{
mk = 1;
richTextBox1.Text = "已启动承载网络";
wifikg = 1;
}
}
if (mk == 0) richTextBox1.Text = "启动失败!";
else
{
if (wifikg == 0)
{
richTextBox2.Text = "wifi未开启,暂无设置信息!";
richTextBox3.Text = "wifi未开启,暂无状态信息!";
}
else
try
{
mingling = "netsh wlan show hostednetwork";
str = InvokeCmd(mingling);
int s1 = 0, s2 = 0, s = 0, s3 = 0;
for (int i = 0; i < str.Length - 6; i++)
{
if (str.Substring(i, 6) == "承载网络设置")
s1 = i;
if (str.Substring(i, 6) == "承载网络状态")
s2 = i;
if (s2 != 0 && str.Substring(i, 1) == "\n") s++;
if (s == 7 && s3 == 0) s3 = i;
}
richTextBox2.Text = str.Substring(s1, s2 - s1);
richTextBox3.Text = str.Substring(s2, s3 - s2);
}
catch
{
richTextBox2.Text = "信息更新失败!";
richTextBox3.Text = "信息更新失败!";
}
}
}
catch
{
richTextBox1.Text = "启动失败!";
} } private void button3_Click(object sender, EventArgs e)
{
//已停止承载网络
try
{
string mingling = "netsh wlan stop hostednetwork";
string str = InvokeCmd(mingling);
int mk = 0;
for (int i = 0; i < str.Length - 7; i++)
{
if (str.Substring(i, 7) == "已停止承载网络")
{
mk = 1;
richTextBox1.Text = "已停止承载网络";
wifikg = 0;
}
}
if (mk == 0) richTextBox1.Text = "停止失败!";
}
catch
{
richTextBox1.Text = "停止失败!";
}
}
int okmingzi = 0;
int okmima = 0;
private void mima_TextChanged(object sender, EventArgs e)
{
if (mima.Text.Length >= 8 && mima.Text.Length <= 12)
{
label1.Text = "Yes";
label1.ForeColor = Color.Green;
okmima = 1;
}
else
{
label1.Text = "No";
label1.ForeColor = Color.Red ;
okmima = 0;
}
} private void mingzi_TextChanged(object sender, EventArgs e)
{
if (mingzi.Text.Length >= 1 && mingzi.Text.Length <= 10)
{
okmingzi = 1;
label2.Text = "Yes";
label2.ForeColor = Color.Green;
}
else
{
okmingzi = 0;
label2.Text = "No";
label2.ForeColor = Color.Red;
}
} private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if(wifikg == 1)
try
{
string mingling = "netsh wlan stop hostednetwork";
string str = InvokeCmd(mingling);
int mk = 0;
for (int i = 0; i < str.Length - 7; i++)
{
if (str.Substring(i, 7) == "已停止承载网络")
{
mk = 1;
richTextBox1.Text = "已停止承载网络";
}
}
if (mk == 0) richTextBox1.Text = "停止失败!";
}
catch
{
richTextBox1.Text = "停止失败!";
}
} private void timer1_Tick(object sender, EventArgs e)
{
if (wifikg == 0)
{
richTextBox2.Text = "wifi未开启,暂无设置信息!";
richTextBox3.Text = "wifi未开启,暂无状态信息!";
}
else
try
{
string mingling = "netsh wlan show hostednetwork";
string str = InvokeCmd(mingling);
int s1 = 0, s2 = 0, s = 0, s3 = 0;
for (int i = 0; i < str.Length - 6; i++)
{
if (str.Substring(i, 6) == "承载网络设置")
s1 = i;
if (str.Substring(i, 6) == "承载网络状态")
s2 = i;
if (s2 != 0 && str.Substring(i, 1) == "\n") s++;
if (s == 7 && s3 == 0) s3 = i;
}
richTextBox2.Text = str.Substring(s1, s2 - s1);
richTextBox3.Text = str.Substring(s2, s3 - s2);
}
catch
{
richTextBox2.Text = "信息更新失败!";
richTextBox3.Text = "信息更新失败!";
}
} private void button4_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.Show();
}
}
}

C#-WiFi共享的更多相关文章

  1. PC使用网线上网的条件下,通过PC的Wifi共享提供手机上网教程

    场景和目标 你有一个笔记本(或装有无线网卡的PC),可以通过网线上网,但是没有无线路由器.现在想要通过笔记本的无线网,让手机也能共享wifi上网. 环境 Win7 操作系统.带有无线网卡的PC或笔记本 ...

  2. Window 8.1 开启Wifi共享

    p{padding-left:20px;} Hosted network supported:Yes  支持Wifi共享 命令:netsh wlan set hostednetwork mode=al ...

  3. win7笔记本电脑实现wifi共享

    前提条件:win 7系统,有wifi 同dos命令就可实现wifi共享 第一步: netsh wlan start hostednetwork pause 第二步: netsh wlan set ho ...

  4. python版本wifi共享工具

    原先不知道win7系统也可以当作无线路由器,既然知道了这个东西那么就搞搞了 使用python写的一个wifi共享工具,还不够完善,有些功能还没做(说明:internet共享连接需要手动设置)..... ...

  5. win8开wifi共享无法使用的问题解决办法

    相信现在不少人都安装了windows8操作系统,因为windows8这个全新的操作系统用起来 确实挺强大,包括漂亮的开始屏,但是不得不说这个系统的兼容性还是有待提高,所以win8我的 装了又卸,卸了又 ...

  6. WiFi共享精灵与路由器

    路由器是大家都知晓的.WiFi共享精灵如今也是非常多人在用的. 那么非常多人就有疑问了,都有路由器了,还要WiFi共享精灵干嘛? 我们来比較一下两者的差别. 首先两个都是能够实现共享上网的. 就是两个 ...

  7. Windows 8.1设置WIFI共享以及无法启动承载链接解决方案.

    1.设置WIFI共享方法 2.无法启动承载链接解决方案 1.设置WIFI共享方法 Windows8 windows8.1笔记本wifi热点 wifi共享.快速将笔记本或者台式机的网络共享给手机,平板等 ...

  8. wifi共享精灵2014.04.25.001已经更新,wifi热点中文名走起!

    五一回来后,有个惊喜,wifi共享精灵有了最新动向.不晓得wifi共享精灵是啥的朋友,我来解释下,它就相当于一个无线路由器.说起来,Wifi共享精灵正式版2014.04.25.001(http://w ...

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

    早在2007年推出iPhone时,乔布斯就提出这种如果:商业区与居民区的wifi路由器全民开放,实现与路人共享网络之便.能够想象,那算是一个wifi共享的乌托邦. 数年过去了,乔布斯的梦想依然没能全然 ...

  10. 简单两行,实现无线WiFi共享上网,手机抓包再也不用愁了

    你是否为WiFi共享而发愁,各个无线共享软件,某某共享精灵,某某免费WiFi,某某共享大师,某某随身WiFi,一个比一个难用,一个比一个私货多,一个比一个广告多,如果装上了它们,你的电脑就基本沦陷了, ...

随机推荐

  1. ubantu16与windows下——redis的安装与使用

      (1) 打开ubantu16,使用如下命令下载安装包 wget http://download.redis.io/releases/redis-2.8.3.tar.gz (2)解压缩命令: tar ...

  2. 关于个Base64,MD5,16进制的转换

    1,待签名数据以UTF-8的格式转字节流,对字节流进行MD5算法得到的签名字节流,再转换为16进制字符串,即生成了数字签名. byte[] targetData = md5.ComputeHash(S ...

  3. Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置

    之后随笔将更多笔墨着重于NNIE开发系列,下文是关于Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置,目前项目需要对 ...

  4. 07-Spring ConfigurationClassPostProcessor

    ConfigurationClassPostProcessor 功能 此类是一个后置处理器类,主要功能是参与 BeanFactory 中 BeanDefinition 的操作和 BeanDefinit ...

  5. C# yield return 原理探究

    天需要些一个小工具,需要使用到多线程读写程序集,接口方法返回值类型需要为"IEnumerable<string>"这里用到了"yield return&quo ...

  6. 前端学习 node 快速入门 系列 —— 报名系统 - [express]

    其他章节请看: 前端学习 node 快速入门 系列 报名系统 - [express] 最简单的报名系统: 只有两个页面 人员信息列表页:展示已报名的人员信息列表.里面有一个报名按钮,点击按钮则会跳转到 ...

  7. 【SqlServer】管理全文索引(FULL TEXT INDEX)

    Sql Server中的全文索引(下面统一使用FULLTEXT INDEX来表示全文索引),是一种特定语言搜索索引功能.它和LIKE的不一样,LIKE主要是根据搜索模板搜索数据,它的效率比FULLTE ...

  8. [SIGIR2020] Sequential Recommendation with Self-Attentive Multi-Adversarial Network

    这篇论文主要提出了一个网络,成为Multi-Factor Generative Adversarial Network,直接翻译过来的话就是多因子生成对抗网络.主要是期望能够探究影响推荐的其他因子(因 ...

  9. Two point

    利用问题的本身与序列的特新,使用两个下标i, j对序列进行扫描(可以同向扫描,也可以反向扫描),以较低的时间复杂度解决问题,一般是O(n) 例1:给定一个递增的正整数序列和一个正整数M,求序列中的两个 ...

  10. Java后端进阶-JVM参数调优

    package com.study.performance; import org.springframework.boot.SpringApplication; import org.springf ...