由于原作者没时间管了,C#的客户端源码就公布于世吧,计算机系有部分童鞋喜欢C#,你们可以拿去研究。
里面已经添加验证码识别功能。
有需要的可以去试试下载
依旧是采用winpcap的EAP包进行认证,需要提前安装好winpcap4.1.3

下面是部分代码:
this.Icon = Properties.Resources.KJB_128;
notifyIcon1.Icon = Properties.Resources.KJB_128;
int FileCount = 0;
DirectoryInfo Dir = new DirectoryInfo(System.Environment.CurrentDirectory);
foreach (FileInfo FI in Dir.GetFiles())
{
if (System.IO.Path.GetExtension(FI.Name) == ".ini")
{
FileCount = 1; break;
}
}
if (FileCount == 0)
{
string Current;
Current = Application.StartupPath + "\\";//获取当前根目录
ini ini = new ini(Current + "config.ini");
ini.writeini("Setting", "key", "false");
ini.writeini("Setting", "key1", "false");
}
if (FileCount == 1)
{
string Current;
Current = Application.StartupPath + "\\";//获取当前根目录
ini ini = new ini(Current + "config.ini");
string user = ini.readini("Setting", "user");
string psw = ini.readini("Setting", "psw");
autogo= ini.readini("Setting", "key1");
textBox1.Text = user;
textBox2.Text = Security.DecryptDES(psw, "ABCD1234");
string WEBuser = ini.readini("Setting", "WEBuser");
string WEBpsw = ini.readini("Setting", "WEBpsw");
string stemp2 = ini.readini("Setting", "key");
string stemp3 = ini.readini("Setting", "key1");
textBox5.Text = WEBuser;
textBox4.Text = Security.DecryptDES(WEBpsw, "ABCD1234");
checkBox2.Checked = Convert.ToBoolean(stemp2);
checkBox1.Checked = Convert.ToBoolean(stemp3);
}
if (checkBox2.Checked == true)
{
panel2.Location = new Point(8, 238);
}
else { this.Height = this.Height - 65; panel2.Location = new Point(8, 176); textBox3.Height = 190; }
label9.Text = "离线";
classInstance = new ManagementClass("Win32_NetworkAdapterConfiguration");
objectCollection = classInstance.GetInstances();
devices = DeviceList.getalldevice(out errorbuf);
List<string> network_name = getnetworkname();
if (network_name.Count == 0)
{
MessageBox.Show("检测不到网卡?");
}
else
{
foreach (string d in network_name)
{
comboBox1.Items.Add(d);
}
comboBox1.SelectedIndex = bijiao();
}
if (autogo == "true")
{
button1_Click(sender, e); ;
}以上是winform加载代码
认证过程如下:
FlushClient fc = new FlushClient(textbox3add);
FlushClient fc2 = new FlushClient(xiaohua);
FlushClient1 fc1 = new FlushClient1(xiaxian);
FlushClient fc3 = new FlushClient(lab);
device.setfilter("(ether proto 0x888e) and (ether dst host " + mac_string + ")", out errorbuf);
t4 = new Thread(new ThreadStart(ceshi));
this.Invoke(fc, "发送START包...");
this.Invoke(fc3, "认证中...");
this.notifyIcon1.ShowBalloonTip(1000, "", "开始认证", ToolTipIcon.Info);
byte[] EAP_start = eap.getEAP_start(mac);
device.sendpacket(EAP_start, out errorbuf);
while (true)
{
byte[] packet = device.getpacketnext(out errorbuf);
if (packet != null)
{
if (packet[15] == 0x00)
{
if (packet[18] == 0x01)
{
if (packet[22] == 0x01)
{
this.Invoke(fc, "发送Identity包...");
// MessageBox.Show("mac:"+mac.ToString() + "----packet:" + packet.ToString()+ "----username:" +username.ToString()+ "----password:" +password.ToString());
byte[] EAP_respone_identity = eap.getEAP_respone_identity(mac, packet, username, out errorbuf);
device.sendpacket(EAP_respone_identity, out errorbuf);
}
else if (packet[22] == 0x04)
{
this.Invoke(fc, "发送RESPONSE包...");
byte[] EAP_respone_md5_challenge = eap.getEAP_respone_md5_challenge(mac, packet, username, password);
device.sendpacket(EAP_respone_md5_challenge, out errorbuf);
}
else if (packet[22] == 0x02)
{
try
{
byte[] n = new byte[packet.Length - 22];
Array.Copy(packet, 23, n, 0, packet.Length - 22);
this.Invoke(fc, "接收到系统发来的信息:" + System.Text.Encoding.Default.GetString(n) + "");
}
catch (Exception e) { e.ToString(); }
}
}
else if (packet[18] == 0x03)
{
this.Invoke(fc, "认证成功");
getip();
success = 1;
this.Invoke(fc, "开始网页认证....\n");
getweb();
this.Invoke(fc2, "");
}
else if (packet[18] == 0x04)
{
byte[] n = new byte[packet.Length - 24];
Array.Copy(packet, 24, n, 0, packet.Length - 24);
this.Invoke(fc, "认证失败\r\n错误信息:" + System.Text.Encoding.Default.GetString(n));
MessageBox.Show("认证失败,请查看日志", "错误");
this.Invoke(fc1);
}
} if (packet[15] == 0x03)
{
if (success == 1)
{
byte[] EAP_key2 = eap.getEAP_key2(mac, packet);
device.sendpacket(EAP_key2, out errorbuf);
}
}
}
}然后重头戏,网页认证代码如下:
int s = (int)DateTime.UtcNow.Subtract(DateTime.Parse("1970-1-1")).TotalSeconds;
StringBuilder sb = new StringBuilder();
// MessageBox.Show(s.ToString());
System.Net.ServicePointManager.Expect100Continue = false;
Uri uri = new Uri("http://125.88.59.131:10001/common/image.jsp?time=" + s.ToString());
HttpWebRequest requeszt = (HttpWebRequest)HttpWebRequest.Create(uri);
HttpWebResponse responsze = (HttpWebResponse)requeszt.GetResponse();
string cookie = responsze.Headers["set-cookie"];
Stream resStream = responsze.GetResponseStream();//得到验证码数据流
Bitmap sourcebm = new Bitmap(resStream);//初始化Bitmap图片
// sourcebm.Save(@"C:\test.gif");//可以保存到本地
sourcebm = CutMap(sourcebm);
Bitmap[] arrmap = SplitImg(sourcebm, 4, 1);
string c = DrawCode(arrmap);
string[] arrv = c.Split(new string[] { "=======" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < arrv.Length; i++)
{
sb.Append(new Compar(arrv[i]).GetCode());
}
string yzm = sb.ToString();
FlushClient fc = new FlushClient(textbox3add);
FlushClient fc3 = new FlushClient(lab);
string Current;
Current = Application.StartupPath + "\\";//获取当前根目录
ini ini = new ini(Current + "config.ini");
string WEBuser = "";
string WEBpsw = "";
string stemp2 = ini.readini("Setting", "key");
if (stemp2 == "true")
{
WEBuser = ini.readini("Setting", "WEBuser");
WEBpsw = Security.DecryptDES(ini.readini("Setting", "WEBpsw"), "ABCD1234");
} if (stemp2 == "false")
{
WEBuser = textBox1.Text;
WEBpsw = textBox2.Text;
}
IPAddress[] arrIPAddresses = Dns.GetHostAddresses(Dns.GetHostName());
string IPADD = "";
foreach (IPAddress ip in arrIPAddresses)
{
if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
{
if (ip.ToString().Substring(0, 2) == "10")
{
IPADD = ip.ToString(); break;
}
}
}
string url = "http://125.88.59.131:10001/login.do?edubas=113.98.13.29&eduuser=" + IPADD + "&userName1=" + WEBuser + "&password1=" + WEBpsw+"&rand="+yzm;
try{
WebRequest request = WebRequest.Create(url);
request.Headers.Add("Cookie", cookie);
WebResponse rea = request.GetResponse();
}catch (Exception e) { e.ToString(); }
if (Ping() == true)
{
this.Invoke(fc, "网页认证成功\n");
this.Invoke(fc3, "在线");
this.notifyIcon1.ShowBalloonTip(1000, "", "网页认证成功", ToolTipIcon.Info);
websuccess = 1;
t4.Start(); //检测网页是否掉线线程启动
}
else
{
this.Invoke(fc, "http_timeout\n");
this.notifyIcon1.ShowBalloonTip(1000, "", "网页认证超时", ToolTipIcon.Info);
if (websuccess == 0) { getweb(); }
}我就不细化讲解了,对于重要部分已经在上面贴了出来。
各位程序猿慢慢研究~
发表评论: