2009-12-29 3 views
1

Windows 7은 핫스팟을 만들 수있는 가상 WiFi를 도입했습니다. 그러나 C#에서 그것을 수행하는 자습서를 찾을 수 없습니다. 내가 찾은 가상 라우터 (그것은 오픈 소스이며 C#으로 작성되었습니다)하지만 서비스로 구현되기 때문에 많은 관련이없는 코드를 가지고 있기 때문에 어떻게 작동하는지 알 수 없습니다.C#을 사용하는 Windows 7 가상 WiFi?

어떻게 핫스팟을 만들고 클라이언트에게 IP 주소를 할당 할 수 있습니까? ICS와 같은 기능은 필요 없지만 브로드 캐스트 게이트웨이와 DNS 정보를 원합니다.

Connectify라는 폐쇄 소스 대안이 있습니다. 나는 그 근원을 얻을 수 있었지만 많이 도움이되지 못했다. 오픈 소스 라이브러리를 사용하지만 핫스팟을 만드는 방법을 모르겠습니다.

+0

MSI (Virtual Router)를 설치하지 않는 이유는 무엇입니까? –

+0

내가 몇 가지 측면을 수정해야하기 때문에 + 서비스가 아닌 앱으로 실행해야하는 것이 있습니다. –

+2

어떻게 Connectify의 소스를 얻었습니까? – Nate

답변

0

코드 플렉스 프로젝트 Virtual Router을 살펴 보았습니까?

+0

또는 [MyRouter] (http://myrouter.codeplex.com/)를 볼 수 있습니다. –

1

원하는대로 정확하게 수행 한 프로젝트를 발견 했으므로 해당 프로젝트를 이해하지 못하는 이유는 무엇입니까?

관심있는 대부분의 코드가 "VirtualRouter.Wlan"프로젝트에있는 것처럼 보입니다. 거기서 시작해서 이해하지 못한다면 구체적인 질문을하십시오.

0
 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(); 
       } 
      } 
     }