【问题标题】:Windows 7 Virtual WiFi using C#?使用 C# 的 Windows 7 虚拟 WiFi?
【发布时间】:2009-12-29 20:21:46
【问题描述】:

Windows 7 引入了虚拟 WiFi,可让您创建热点。但是我找不到任何关于在 C# 中执行此操作的教程。我找到了 Virtual Router(它是开源的,用 C# 编写),但我似乎无法弄清楚它是如何工作的,因为它有很多不相关的代码,因为它是作为服务实现的。

谁能解释我如何创建热点并为客户端分配 IP 地址?我不需要像 ICS 这样的功能,但我希望能够广播网关和 DNS 信息。

还有一个名为 Connectify 的封闭源代码替代方案。我确实设法获得了它的来源,但它并没有太大帮助。它使用了一个开源库,但我不知道如何用它创建热点。

【问题讨论】:

  • 为什么不直接安装虚拟路由器(MSI)?
  • 因为我需要修改它的几个方面 + 我需要一些作为应用程序而不是作为服务运行的东西
  • 您是如何获得 Connectify 的源代码的?
  • 这是一个 .NET 应用程序,老天爷。运用你的常识。
  • 这里不需要那种态度; Nate 提出了一个合理的问题。 @Nate:您可以使用 .NET Reflector 等应用程序从二进制文件中对 .NET 代码进行逆向工程。它不是原始来源,但除非应用程序被混淆,否则它是可以理解的。

标签: c# windows-7 virtual wireless wifi


【解决方案1】:

既然您已经找到了一个完全符合您要求的项目,为什么不努力理解该项目呢?

看起来您感兴趣的大部分代码都在“VirtualRouter.Wlan”项目中。从那里开始,如果您不理解,请尝试提出具体问题。

【讨论】:

    【解决方案2】:

    您是否考虑过查看这个 Code-Plex 项目 Virtual Router

    【讨论】:

      【解决方案3】:
              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;
              using System.Security.Principal;
      
              namespace WifiRouter
              {
                  public partial class Form1 : Form
                  {
                      bool connect = false;
                      public Form1()
                      {
      
                          InitializeComponent();
                      }
      
                      public static bool IsAdmin()
                      {
                          WindowsIdentity id = WindowsIdentity.GetCurrent();
                          WindowsPrincipal p = new WindowsPrincipal(id);
                          return p.IsInRole(WindowsBuiltInRole.Administrator);
                      }
                      public void RestartElevated()
                      {
                          ProcessStartInfo startInfo = new ProcessStartInfo();
                          startInfo.UseShellExecute = true;
                          startInfo.CreateNoWindow = true;
                          startInfo.WorkingDirectory = Environment.CurrentDirectory;
                          startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
                          startInfo.Verb = "runas";
                          try
                          {
                              Process p = Process.Start(startInfo);
                          }
                          catch
                          {
      
                          }
      
                          System.Windows.Forms.Application.Exit();
                      }
                      private void button1_Click(object sender, EventArgs e)
                      {
                          string ssid = textBox1.Text, key = textBox2.Text;
                          if (!connect)
                          {
                              if (String.IsNullOrEmpty(textBox1.Text))
                              {
                                  MessageBox.Show("SSID cannot be left blank !",
                                  "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                              }
                              else
                              {
      
                                  if (textBox2.Text == null || textBox2.Text == "")
                                  {
                                      MessageBox.Show("Key value cannot be left blank !",
                                      "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                  }
                                  else
                                  {
                                      if (key.Length >= 6)
                                      {
                                          Hotspot(ssid, key, true);
                                          textBox1.Enabled = false;
                                          textBox2.Enabled = false;
                                          button1.Text = "Stop";
                                          connect = true;
                                      }
                                      else
                                      {
                                          MessageBox.Show("Key should be more then or Equal to 6 Characters !",
                                          "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                      }
                                  }
                              }
                          }
                          else
                          {
                              Hotspot(null, null, false);
                              textBox1.Enabled = true;
                              textBox2.Enabled = true;
                              button1.Text = "Start";
                              connect = false;
                          }
                      }
                      private void Hotspot(string ssid, string key,bool status)
                      {
                          ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
                          processStartInfo.RedirectStandardInput = true;
                          processStartInfo.RedirectStandardOutput = true;
                          processStartInfo.CreateNoWindow = true;
                          processStartInfo.UseShellExecute = false;
                          Process process = Process.Start(processStartInfo);
      
                          if (process != null)
                          {
                              if (status)
                              {
                                  process.StandardInput.WriteLine("netsh wlan set hostednetwork mode=allow ssid=" + ssid + " key=" + key);
                                  process.StandardInput.WriteLine("netsh wlan start hosted network");
                                  process.StandardInput.Close();
                              }
                              else
                              {
                                  process.StandardInput.WriteLine("netsh wlan stop hostednetwork");
                                  process.StandardInput.Close();
                              }
                          }
                      }
      
                      private void Form1_Load(object sender, EventArgs e)
                      {
                          if (!IsAdmin())
                          {
                              RestartElevated();
                          }
                      }
      
                      private void Form1_FormClosing(object sender, FormClosingEventArgs e)
                      {
                          Hotspot(null, null, false);
                          Application.Exit();
                      }
                  }
              }
      

      【讨论】:

        猜你喜欢
        • 2012-02-23
        • 2010-09-20
        • 2011-02-22
        • 2011-10-30
        • 1970-01-01
        • 1970-01-01
        • 2013-11-10
        • 2012-05-11
        • 2015-02-23
        相关资源
        最近更新 更多