1 金钱
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = @"f:\网站名.txt";
textBox2.Text = @"f:\文件名.txt";
Control.CheckForIllegalCrossThreadCalls = false;//不可在多线程中随便使用
}
public List<String> list_domins = new List<String>();//list是个集合,为String型。名字为list_domins,开始之前先初始化。
public List<String> list_dirs = new List<String>();//把集合中的字符串放入到list_dirs中。
public ServerInfo[] serverinfos = { };//定义数组可以用于确定有关在哪里发布表单的信息。该数组名字为serverinfos的空数组。
//public List<ServerInfo> sucess_result = new List<ServerInfo>();
public Thread th;//扫描线程
public Thread c_th;//更新扫描数量线程
public List<Thread> list_th = new List<Thread>();//http访问线程的集合,放这里方便控制
public int maxThead = 5;//最大线程数,默认10个
public int sleepTime = 0;//扫描休息时间,默认不休息
public int timeout = 10000; //默认超时10秒
public int scanCount = 0;//目录扫描次数
//public long usedtime = 0;//扫描完成域名数
public String method = "HEAD";//默认HEAD扫描方式
public String showCode = "403,200";//显示状态
private void button1_Click(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;//不可在多线程中随便使用
//kaishi();
zhixing();//方法
}
public void zhixing()
{
//拼接字符
string[] wangzhi = File.ReadAllLines(textBox1.Text.Trim());//读取txt
string[] wenjianming = File.ReadAllLines(textBox2.Text.Trim());
int shuliang = (int)wangzhi.Length * (int)wenjianming.Length;//计算需要循环多少次
foreach (string wangzhi1 in wangzhi)//循环读取txt文件的内容
{
foreach (string wenjianming1 in wenjianming)
{
string strurl1 = "http://" + wangzhi1 + "/" + wenjianming1;
ThreadPool.QueueUserWorkItem(new WaitCallback(GetGeneralContent), strurl1);//创建一个线程池,并执行auto方法,strurl1是auto方法的参数
}
}
}
public void GetGeneralContent(object strUrl)
{
string strurl = strUrl as string;
string strMsg = string.Empty;
try
{
WebRequest request = WebRequest.Create(strurl);//链接浏览器
WebResponse response = request.GetResponse();//取链接返回内容
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
strMsg = reader.ReadToEnd();
if (strMsg.Contains("404 - Page Not Found"))//判断是否出现404
{
richTextBox1.AppendText(strurl + " " + "[404]" + "\n");
}
else
{
richTextBox1.AppendText(strurl + " " + "[200]" + "\n");
}
reader.Close();
reader.Dispose();
response.Close();
}
catch
{ }
}
public static int getHttpCode(String header)
{
int code = 0;
try
{
//查找状态码
if (header != null && !"".Equals(header))
{
code = int.Parse(header.Split(' ')[1]);
}
}
catch (Exception e)
{
}
return code;
}
public static int getLength(String header)
{
int s_index = -1;
int s_endIndex = -1;
int length = 0;
try
{
if ((s_index = header.IndexOf("content-length:")) != -1)
{
if ((s_endIndex = header.IndexOf("\r", s_index, header.Length - s_index)) != -1)
{
String slength = header.Substring(s_index + 15, s_endIndex - s_index - 15).Trim();
length = int.Parse(slength);
}
}
}
catch (Exception e)
{
}
return length;
}
public void scan(Object osvinfo)
{
ServerInfo svinfo = (ServerInfo)osvinfo;
if (svinfo.up404)
{
if (svinfo.powerBy.IndexOf("waf") != -1)
{
return;
}
String header = HttpTools.getHttpHeaderByTCP(this.method, svinfo.url, this.timeout, 2048);
int code = getHttpCode(header);
int length = getLength(header);
if (code == 302 || code == 200)
{
if (svinfo.code == code && length == svinfo.length)
{
svinfo.code = 404;
}
else if (this.method.Equals("GET") && !svinfo.html_404.Equals(""))
{
svinfo.code = 404;
}
}
// else if (Tools.have404str(header))
//{
// svinfo.code = 404;
//}
else { svinfo.code = code; }
}
//else if ((code == 403 && length > 0))
//{ svinfo.code = 404; }
else
{
// svinfo.code = Tools.getHttpCode(HttpTools.getHttpHeaderByTCP(this.method, svinfo.url, this.timeout, 15));
}
if (svinfo.isdir == 0)
{
this.showCode = this.showCode.Replace("403", "").Replace("301", "");
}
if (this.showCode.IndexOf(svinfo.code + "") != -1 && svinfo.code != 0)
{
// this.Invoke(new DelegateAddItemToListView(), svinfo);
}
scanCount++; }
//指纹IP扫描
public void zwScan(Object osvinfo)
{
ServerInfo svinfo = (ServerInfo)osvinfo;
if (svinfo.up404)
{
svinfo.url += "/aabcdsgsgshsft/page404404.php.xxx";
}
String header = HttpTools.getHttpHeaderByTCP(this.method, svinfo.url, this.timeout, 600);
//svinfo.html_404 = get404code(header);//方便页面不反回状态码时,智能404判断
svinfo.code =getHttpCode(header);
if (svinfo.up404)
{
svinfo.length = getLength(header);
}
if (svinfo.upzw)
{
svinfo.server = (header);
svinfo.powerBy = (header);
}
if (svinfo.upip)
{
svinfo.ip = (svinfo.url);
}
if (svinfo.code != 0 && (svinfo.upip | svinfo.upzw))
{
this.Invoke(new DelegateAddItemToListView(AddItemToListView), svinfo);
}
if (svinfo.code == 0)
{
//响应为0,超时域名记录到日志
FileTool.AppendLogToFile("logs/failed_domains.txt", svinfo.url);
}
else
{ //404信息按顺序放到集合
serverinfos[svinfo.domainid] = svinfo; }
//扫描成功数加一
scanCount++;
}
public void clearThread()
{
for (int i = 0; i < list_th.Count; i++)
{
if (list_th.Count <= 0) break;
Thread cth = list_th;
if (cth.IsAlive == false)
{
list_th.Remove(cth);
}
Thread.Sleep(this.sleepTime);
}
}
public void initThread(ServerInfo server, int type)
{
while (true)
{
clearThread();
if (list_th.Count < this.maxThead)
{
Thread th = null;
if (type == 1)
{
//th = new Thread(new ParameterizedThreadStart(Scan));
}
else
{
th = new Thread(new ParameterizedThreadStart(scan));
}
list_th.Add(th);
th.Start(server);
break;
}
}
}
delegate void DelegateAddItemToListView(ServerInfo svinfo);
public void AddItemToListView(ServerInfo svinfo)
{
ListViewItem lvi = new ListViewItem(svinfo.id + "");
lvi.SubItems.Add(svinfo.url);
lvi.SubItems.Add(svinfo.code + "");
lvi.SubItems.Add(svinfo.server + "");
lvi.SubItems.Add(svinfo.powerBy + "");
lvi.SubItems.Add(svinfo.ip + "");
lvi.SubItems.Add(svinfo.type + "");
// this.richTextBox1.Items.Add(lvi);
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
}
}
我的界面,2个textBox,2个button,1个lable,1个richTextBox1,1个ComboBox.ComboBox名字cmb_threadCount。 真心不会整了 求高手们帮忙。
我来回答