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. HDU_3949 XOR 【线性基】

    一.题目 XOR 二.分析 给定$N$个数,问它的任意子集异或产生的数进行排列,求第K小的数. 构造出线性基$B$后,如果$|B| < N$,那么代表N个数中有一个数是可以由线性基中的其他数异或 ...

  2. 2019 GDUT Rating Contest III : Problem E. Family Tree

    题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...

  3. 基于autofac的属性注入

    基于autofac的属性注入 什么是属性注入 在了解属性注入之前,要先了解一下DI(Dependency Injection),即依赖注入.在ASP.NET Core里自带了一个IOC容器,而且程序支 ...

  4. IPFS挖矿必须要托管吗?

    IPFS 本质上只是一个人人使用的协议,而 Filecoin 是 IPFS 的激励层,大家平时说的 IPFS 挖矿,其实就是挖 Filecoin.而提到IPFS 就不得不说到矿机托管的问题. 点击了解 ...

  5. 攻防世界 reverse BabyXor

    BabyXor     2019_UNCTF 查壳 脱壳 dump 脱壳后 IDA静态分析 int main_0() { void *v0; // eax int v1; // ST5C_4 char ...

  6. 【Java】流、IO(初步)

    (这部分比较抽象且写的不是很好,可能还要再编辑) [概述] 流:流是一系列数据,包括输入流和输出流.你可以想象成黑客帝国的"代码雨",只要我们输入指令,这些数据就像水一样流进流出了 ...

  7. Elasticsearch核心技术与实战,性能是真牛

    Elasticsearch 是一款非常强大的开源搜索及分析引擎.结合 Kibana.Logstash和Beats,Elasticsearch 还被广泛运用在大数据近实时分析,包括日志分析.指标监控.信 ...

  8. 女娲造人引发思考之Java设计模式:工厂模式

    目录 工厂模式的几种形态 简单工厂模式 示例 结构 优缺点 女娲抟土造人 工厂方法模式 结构 女娲举绳造人 抽象工厂模式 结构 女娲造万物 工厂模式的几种形态 工厂模式专门负责将大量有共同接口的类实例 ...

  9. Spring Cloud Alibaba(2)---RestTemplate微服务项目

    RestTemplate微服务项目 前言 因为要运用 Spring Cloud Alibaba 开源组件到分布式项目中,所以这里先搭建一个不通过 Spring Cloud只通过 RestTemplat ...

  10. Digit Counting UVA - 1225

    ​ Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequ ...