下面是我做的一段批量注册163邮箱的代码,经测试是有效的能够批量注册邮箱,可以换成其他的。欢迎大家
欣赏啊,请不要用于不正当的途径。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using mshtml;
using System.Threading;
using System.Text.RegularExpressions;
namespace _163邮箱批量注册
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
refresh();
}
public string emailName(int j)//生成邮箱名
{
char[] c = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
Random ran = new Random();
string sd = "m";
for (int i = 0; i <= j; i++)//5个char类型的字符赋值给一个string类形的字符串sd,sd的任务是每次刷新,str的作用是全局变量
{
sd += c[ran.Next(c.Length)];
}
string emailName = sd.ToString();
return emailName.ToLower();
}
public string MobileNumber()//生成邮箱名
{
char[] c = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
Random ran = new Random();
string sd = "187";
for (int i = 0; i <8; i++)//5个char类型的字符赋值给一个string类形的字符串sd,sd的任务是每次刷新,str的作用是全局变量
{
sd += c[ran.Next(c.Length)];
}
string mobileNumber = sd.ToString();
return mobileNumber.ToLower();
}
private void btnRegister_Click(object sender, EventArgs e)
{
submit();
}
public void submit()
{
try
{
if (Convert.ToString(webBrowser1.Url) == "http://reg.email.163.com/mailregAll/reg0.jsp?from=163mail_right")
{
webBrowser1.Document.GetElementById("verifyInp").InnerText = txtVerification.Text.ToString();
webBrowser1.Document.GetElementById("verifyInp").Focus();
webBrowser1.Document.GetElementById("regBtn").InvokeMember("Click");
//HtmlElement form = webBrowser1.Document.GetElementById("regBtn");
//form.InvokeMember("Click");
}
else
{
webBrowser1.Document.GetElementById("verifyInp").InnerText = txtVerification.Text.ToString();
webBrowser1.Document.GetElementById("verifyInp").Focus();
webBrowser1.Document.GetElementById("createmailbutton").InvokeMember("Click");
}
}
catch (Exception ex)
{
throw ex;
}
}
#region 获取网页中的验证码
public Image GetRegCodePic(WebBrowser wbMail, string ImgName, string Src, string Alt)
{
HTMLDocument doc = (HTMLDocument)wbMail.Document.DomDocument;
HTMLBody body = (HTMLBody)doc.body;
IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
IHTMLControlElement Img;
if (ImgName == "") //如果没有图片的名字,通过Src或Alt中的关键字来取
{
int ImgNum = GetPicIndex(wbMail, Src, Alt);
if (ImgNum == -1)
return null;
Img = (IHTMLControlElement)wbMail.Document.Images[ImgNum].DomElement;
}
else
{
Img = (IHTMLControlElement)wbMail.Document.All[ImgName].DomElement;
}
rang.add(Img);
rang.execCommand("Copy", false, null);
Image RegImg = Clipboard.GetImage();
Clipboard.Clear();
return RegImg;
}
public static int GetPicIndex(WebBrowser wbMail, string Src, string Alt)
{
int imgnum = -1;
for (int i = 0; i < wbMail.Document.Images.Count; i++) //获取所有的Image元素
{
IHTMLImgElement img = (IHTMLImgElement)wbMail.Document.Images[i].DomElement;
if (Alt == "")
{
if (img.src.Contains(Src)) return i;
}
else
{
if (!string.IsNullOrEmpty(img.alt))
{
if (img.alt.Contains(Alt)) return i;
}
}
}
return imgnum;
}
#endregion
public void refresh()
{
this.webBrowser1.Url = new Uri("http://reg.email.163.com/mailregAll/reg0.jsp?from=163mail_right");
picVerification.Image = this.GetRegCodePic(webBrowser1, "vcode_img", "", "");
}
private void btnContinue_Click(object sender, EventArgs e)
{
refresh();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
this.picVerification.Image = GetRegCodePic(webBrowser1, "vcode_img", "", "");
webBrowser1.Document.GetElementById("unameInp").Focus();
webBrowser1.Document.GetElementById("unameInp").InnerText = emailName(10);
webBrowser1.Document.GetElementById("passwInp").Focus();
webBrowser1.Document.GetElementById("passwInp").InnerText = "minotmin";
webBrowser1.Document.GetElementById("passConfim").Focus();
webBrowser1.Document.GetElementById("passConfim").InnerText = "minotmin";
webBrowser1.Document.GetElementById("mobileInp").Focus();
webBrowser1.Document.GetElementById("mobileInp").InnerText = MobileNumber();
}
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)//新窗体中
{
e.Cancel = true;
this.webBrowser1.Url = new Uri(((WebBrowser)sender).StatusText);
picVerification.Image = this.GetRegCodePic(webBrowser1, "vcode_img", "", "");
}
private void picVerification_Click(object sender, EventArgs e)
{
this.webBrowser1.Document.GetElementById("vcode_img").InvokeMember("Click");
//picVerification.Image = this.GetRegCodePic(webBrowser1, "vcode_img", "", "");
}
private void button1_Click(object sender, EventArgs e)
{
picVerification.Image = this.GetRegCodePic(webBrowser1, "vcode_img", "", "");
}
private void button2_Click(object sender, EventArgs e)
{
//this.webBrowser1.Document.GetElementById("emailVal");
//this.webBrowser1.Document.GetElementsByTagName("p");
if (webBrowser1.Document != null)
{
try
{
this.webBrowser1.Refresh();
HtmlElement he = webBrowser1.Document.GetElementById("emailVal");//获取id为pvshow的值,在上面那个网址中有一个id为pvshow的标签.
MessageBox.Show( he.OuterHtml);//he.OuterText是将获取的值输出来
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
// HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;
// HTMLBody body = (HTMLBody)doc.body;
// string Str = "";
// Match m = Regex.Match(Str, @"^[m]\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$");
//if (m.Success)
//{
// string resultStr = m.Value;
// this.label3.Text = resultStr;
//}
}
}
}