-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxy.cs
More file actions
84 lines (75 loc) · 2.25 KB
/
Proxy.cs
File metadata and controls
84 lines (75 loc) · 2.25 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Diagnostics;
namespace ProxyChecker
{
public class Proxy
{
public IPEndPoint IPEndPoint { get; set; }
public string Type { get; set; }
public string Status
{
get
{
if (this._working == true)
{
return "online";
}
else if (this._working == null)
{
return "uknown";
}
return "offline";
}
}
private Nullable<bool> _working = false;
public Proxy(IPEndPoint endPoint, string type = null, Nullable<bool> working = null)
{
this.IPEndPoint = endPoint;
this.Type = type;
this._working = working;
}
public void PerformTest()
{
this._working = Proxy.TestProxy(this);
}
public static Proxy Parse(string str)
{
str = str.Replace(';', ':');
str = str.Replace(',', ':');
string[] parts = str.Split(':');
try
{
string ipStr = parts[0];
string portStr = parts[1];
IPAddress ip;
IPAddress.TryParse(ipStr, out ip);
return new Proxy(new IPEndPoint(ip, int.Parse(portStr)));
}
catch (Exception e)
{
return null;
}
}
public static bool TestProxy(Proxy proxy)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://google.com");
request.Proxy = new WebProxy(proxy.IPEndPoint.Address.ToString(), proxy.IPEndPoint.Port);
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36";
request.Timeout = 2000;
try
{
WebResponse response = request.GetResponse();
}
catch (Exception)
{
return false;
}
return true;
}
}
}