Jump to content

Photo

Connecting to a network through c#[help please]


  • Please log in to reply
2 replies to this topic

#1 Delta22

Delta22

    Kilobyte

  • Members
  • 139 posts
  • LocationAustralia

Posted 16 April 2013 - 08:09 PM

Ok, so I've created a small program that lists available networks, but how do i connect to them(through code)?

any language really, but preferably c#

thanks in advance.


Programmer(in training), hacker(in minimal training), good with computers and mature, all you need to know about me but feel free to talk to me, contact me or whatever, i am no danger.


#2 Delta22

Delta22

    Kilobyte

  • Members
  • 139 posts
  • LocationAustralia

Posted 16 April 2013 - 08:35 PM

using NativeWifi;
using System.Net.NetworkInformation;
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;
 
namespace Wifi
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        static string GetStringForSSID(Wlan.Dot11Ssid ssid)
        {
            return Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            WlanClient client = new WlanClient();
            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {
                Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                {
                    if (network.dot11DefaultCipherAlgorithm == Wlan.Dot11CipherAlgorithm.WEP)
                    {
                        textBox1.Text = ("Found WEP network with SSID {0}." + GetStringForSSID(network.dot11Ssid));
                    }
                }
                foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles())
                {
                    string name = profileInfo.profileName;
                    string xml = wlanIface.GetProfileXml(profileInfo.profileName);
                }
                string profileName = "CheeseCake";
                string mac = "52544131303235572D454137443638";
                string key = "hello";
                string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft...LAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, key);
                wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
                wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                {
                    textBox1.Text = textBox1.Text + GetStringForSSID(network.dot11Ssid) + Environment.NewLine;
 
                }
                foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) //Get Mac adress
                {
                    string MACAddress = nic.GetPhysicalAddress().ToString();
                    textBox1.Text = textBox1.Text + MACAddress + Environment.NewLine;
 
                }
 
 
 
            }
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
        }
    }
}

Programmer(in training), hacker(in minimal training), good with computers and mature, all you need to know about me but feel free to talk to me, contact me or whatever, i am no danger.


#3 Champion of Cyrodiil

Champion of Cyrodiil

    Gigabyte

  • Members
  • 776 posts
  • LocationVirginia

Posted 29 April 2013 - 02:00 PM

For connecting to a wlan use:

http://msdn.microsof...3(v=vs.85).aspx

 

Here is the parent page to the one above.

http://msdn.microsof...5(v=vs.85).aspx