-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProxy.cs
102 lines (95 loc) · 3.27 KB
/
Proxy.cs
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
using System;
using System.Net;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ADS_Web后台弱口令扫描
{
public partial class Proxy : Form
{
public Proxy()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
try
{
string server = textBox_server.Text;
string port = textBox_port.Text;
//测试连接
var url = textBox1.Text;
var proxy = new WebProxy(server + ":" + port, true);
//创建要请求的对象
var req = (HttpWebRequest)WebRequest.Create(url);
req.Proxy = proxy;
var res = (HttpWebResponse)req.GetResponse();
//超时时间 5秒后无响应就放弃
req.Timeout = 5000;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("utf-8"));
//读取返回的内容
var html = sr.ReadToEnd();
if (html != null)
{
MessageBox.Show("连接成功");
}
else
{
MessageBox.Show("连接失败");
}
}
catch (Exception)
{
MessageBox.Show("连接超时");
}
}
private void button1_Click(object sender, EventArgs e)
{
//保存代理内容
try
{
string server = textBox_server.Text;
string port = textBox_port.Text;
//测试连接
var url = textBox1.Text;
var proxy = new WebProxy(server + ":" + port, true);
//创建要请求的对象
var req = (HttpWebRequest)WebRequest.Create(url);
req.Proxy = proxy;
var res = (HttpWebResponse)req.GetResponse();
//超时时间 5秒后无响应就放弃
req.Timeout = 5000;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("utf-8"));
//读取返回的内容
var html = sr.ReadToEnd();
if (html != null)
{
Form1.Proxy_server = textBox_server.Text;
Form1.Proxy_port = textBox_port.Text;
MessageBox.Show("代理设置已保存");
this.Hide();
}
else
{
MessageBox.Show("连接失败");
}
}
catch (Exception)
{
MessageBox.Show("连接超时");
}
}
private void Proxy_Load(object sender, EventArgs e)
{
textBox_server.Text = Form1.Proxy_server;
textBox_port.Text = Form1.Proxy_port;
}
}
}