2009-12-29 4 views
1

Windows 7 introduit WiFi virtuel qui vous permet de créer des points chauds . Cependant, je ne trouve aucun tutoriel sur le faire en C#. J'ai trouvé Virtual Router (Il est open source et est écrit en C#) mais je ne peux pas sembler comprendre comment cela fonctionne, car il a beaucoup de code indépendant puisqu'il est mis en œuvre en tant que service.Windows 7 WiFi virtuel utilisant C#?

Quelqu'un peut-il expliquer comment puis-je créer un point d'accès et attribuer des adresses IP aux clients? Je n'ai pas besoin de fonctionnalités comme ICS mais je veux être en mesure de passerelle de diffusion et DNS informations.

Il existe également une alternative à source fermée appelée Connectify. J'ai réussi à obtenir sa source, mais cela n'a pas aidé beaucoup. Il utilise une bibliothèque open source mais je ne sais pas comment créer des hotspots avec lui.

+0

Pourquoi ne pas simplement installer Virtual Router (MSI)? –

+0

Parce que je dois en modifier quelques aspects + J'ai besoin de quelque chose qui fonctionne comme une application et non comme un service –

+2

Comment avez-vous obtenu la source de Connectify? – Nate

Répondre

0

Avez-vous pensé à regarder dans ce projet de code-Plex Virtual Router?

+0

Ou vous pouvez voir [MyRouter] (http://myrouter.codeplex.com/) –

1

Depuis que vous avez trouvé un projet qui fait exactement ce que vous voulez, pourquoi ne pas travailler sur la compréhension de ce projet?

Il semble que la plupart du code qui vous intéresse est dans le projet « VirtualRouter.Wlan ». Commencez là et essayez de poser des questions spécifiques si vous ne le comprenez pas.

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