forked from RcoIl/CSharp-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
134 lines (126 loc) · 4.69 KB
/
Program.cs
File metadata and controls
134 lines (126 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace SharpWebScan
{
class Program
{
/// <summary>
/// ip处理,线程分配
/// </summary>
/// <param name="ip"></param>
public static void ThreadList(string ip, string port)
{
Console.WriteLine("");
try
{
ip = ip.Trim();
string cip = "";
if (regexAll(ip))
{
cip = ip.Substring(0, ip.LastIndexOf('.'));
}
else if (regexAll_1(ip))
{
cip = ip;
}
for (int i = 1; i < 255; i++)
{
arrayList.Add(new threadStart(cip + "." + i.ToString(), port));
}
Thread[] array = new Thread[arrayList.Count];
for (int j = 0; j < arrayList.Count; j++)
{
array[j] = new Thread(new ThreadStart(((threadStart)arrayList[j]).method_0));
array[j].Start();
}
for (int j = 0; j < array.Length; j++)
{
array[j].Join();
}
GC.Collect();
arrayList.Clear();
}
catch (Exception ex)
{
Debug.Print(ex.Message);
}
}
/// <summary>
/// 输出 站点容器、标题信息
/// </summary>
/// <param name="ip"></param>
public static void GetAll(string ip, string port)
{
string url = String.Format("http://{0}:{1}",ip , port);
String regex = @"<title>.+</title>";
try
{
var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
req.Method = "GET";
req.Timeout = 10000;
var res = (HttpWebResponse)req.GetResponse();
if (res.StatusCode == HttpStatusCode.OK || res.StatusCode == HttpStatusCode.Forbidden || res.StatusCode == HttpStatusCode.Redirect || res.StatusCode == HttpStatusCode.MovedPermanently)
{
int_0++;
try
{
WebClient web = new WebClient();
byte[] buffer = web.DownloadData(url);
string html = Encoding.UTF8.GetString(buffer);
String title = Regex.Match(html, regex).ToString();
title = Regex.Replace(title, @"<title>", "");
title = Regex.Replace(title, @"</title>", "");
Console.WriteLine("{0,-25} {1,-15} {2,-25} {3,-25}", url, Convert.ToInt32(res.StatusCode), res.Server, title);
}
catch (Exception ex)
{
}
}
}
catch (WebException ex)
{
}
}
public static int int_0 = 0;
public static ArrayList arrayList = new ArrayList();
public static bool regexAll(string string_0)
{
Regex regex = new Regex("^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$");
return regex.IsMatch(string_0);
}
public static bool regexAll_1(string string_0)
{
Regex regex = new Regex("^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$");
return regex.IsMatch(string_0);
}
static void Main(string[] args)
{
// 加入多端口扫描
Console.WriteLine();
Console.WriteLine("Scaning Web Title....");
Console.WriteLine("{0,-25} {1,-15} {2,-25} {3,-25}", "URL", "StatusCode", "res.Server", "Title");
string ports = args[2];
string[] port = ports.Split(new char[] { ',' });
for (int i = 0; i < port.Length; i++)
{
if (args.Contains("-CIP"))
{
ThreadList(args[1], port[i]);
}
else if (args.Contains("-IP"))
{
GetAll(args[1], port[i]);
}
}
Console.WriteLine("Count:" + int_0);
Console.WriteLine("Finish!");
}
}
}