⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freebsd.cs

📁 无线网卡接口编程源码
💻 CS
字号:
using System.Diagnostics ;using System;using System.Collections;using System.Text.RegularExpressions;/// How ugly.....public class FreeBSD: OS{	private Regex rr;	private string regex = @"(?<ssid>(.+))\s*(?<mac>(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w))\s+(?<chan>(\d+))\s+(?<ratio>(\w+))\s+(?<signal>(\d+)):\d+\s+\d+\s+(?<caps>(\w+))";		public FreeBSD(){		rr = new Regex(regex);	}	private Hashtable AvaiableDevices(){			Process p = new Process();			p.StartInfo.FileName = "ifconfig";			p.StartInfo.Arguments = "-l";			p.StartInfo.UseShellExecute = false;			p.StartInfo.RedirectStandardOutput = true; 			p.Start();			 			string tmp = p.StandardOutput.ReadToEnd().Trim();			p.WaitForExit();						p.Close();			Hashtable hash = new Hashtable(); 			foreach (string dev in tmp.Split(' '))				hash.Add( dev.Substring(0,dev.Length-1) , dev);   // [driver, device]			return hash;	}	public override string[] WirelessDevices(){		string[] All = new string[8] {"an","iwi","ipw","ndis","ath","wi","ral","ural"};		Hashtable presentdevs = AvaiableDevices();		ArrayList list = new ArrayList();		foreach (string cand in All)			if ( presentdevs[cand]!=null )				list.Add(presentdevs[cand]); 		int i=0;		string[] devs = new string[list.Count];		foreach (string cand in list)			devs[i++] = cand;		return devs ;					}	public override ArrayList WirelessNetworks(){				ArrayList list = new ArrayList();			foreach (string line in Scan().Split('\n') ){			MatchCollection matches = rr.Matches(line);			foreach (Match match in matches){				Network net = _GetNetwork(match);				if (net!=null)					list.Add(net);			}		}		return list;			}	public string Scan(){		Process p = new Process();		p.StartInfo.FileName = "ifconfig";		p.StartInfo.Arguments = String.Format("{0} scan",SelectedDevice);		p.StartInfo.UseShellExecute = false;		p.StartInfo.RedirectStandardOutput = true; 		p.Start();		string outs = p.StandardOutput.ReadToEnd();		p.WaitForExit();		p.Close();		return outs;	}	public Network _GetNetwork(Match match){		string[] data = new string[6];		data[0] = match.Groups["ssid"].ToString().Trim();		if (data[0].Length<1)			return null;		data[1] = match.Groups["mac"].ToString();		data[2] = match.Groups["chan"].ToString();		data[3] = match.Groups["ratio"].ToString();		data[4] = match.Groups["signal"].ToString();		data[5] = match.Groups["caps"].ToString();		return new Network(data); 	}	public override void DHCP(string ssid, string wep){		if (wep!=null)			wep = String.Format(" wepmode on wepkey {0} ",wep);			Execute("route delete default");			Execute(String.Format("ifconfig {0} ssid {1} {2} up",SelectedDevice, ssid, wep ));		System.Threading.Thread.Sleep(200);		Execute(String.Format("dhclient {0}",SelectedDevice));	}	public override void StaticIP(string ssid,string ip,string netmask,string wep,string gateway){			if (wep!=null)			wep = String.Format(" wepmode on wepkey {0} ",wep);						Execute("route delete default");		Execute(String.Format("ifconfig {0} ssid {1} {2} {3} netmask {4} up",SelectedDevice, ssid, wep, ip, netmask) );		System.Threading.Thread.Sleep(200);		Execute(String.Format("route add default {0}",gateway));		}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -