-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProxyManager.cs
115 lines (80 loc) · 2.49 KB
/
ProxyManager.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
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Created by SharpDevelop.
* User: Elite
* Date: 7/10/2020
* Time: 10:43 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.IO;
using System.Net;
namespace ProxyScraper {
/// <summary>
/// Proxy manager
/// </summary>
public class ProxyManager {
private List<String> proxies = null;
private Ping ping = null;
private List<String> proxiesDebug = null;
public ProxyManager () {
this.proxies = new List<String>();
this.ping = new Ping();
this.proxiesDebug = new List<String>();
}
public void inputProxy (string proxy) { if (Int32.Parse(proxy.Split(':')[1]) > 65535) return;
if (this.proxies.Contains(proxy)) return;
this.proxies.Add(proxy);
Program.debug(proxy);
++Program.proxiesScraped;
Program.cm.updateProxies();
}
private void removeDupes () {
List<String> noDupes = new List<String>();
foreach (string s in this.proxies)
if (!(noDupes.Contains(s)) && !(Program.blacklist.Contains(s)))
noDupes.Add(s);
this.proxies = noDupes;
}
public void save () {
Program.cm.updateStatus(Status.SAVING);
this.removeDupes();
//this.pingProxies();
using (StreamWriter sw = new StreamWriter("./proxies/scraped.txt", false)) {
foreach (string s in this.proxies)
sw.WriteLine(s);
}
#if DEBUG
Program.cm.updateStatus(Status.SAVING);
this.removeDupes();
using (StreamWriter sw = new StreamWriter("./proxies/debug_scraped.txt", false)) {
foreach (string s in this.proxiesDebug)
sw.WriteLine(s);
}
Program.debug("--- Finished ProxyScraper: " + DateTime.Now + " ---");
#endif
Program.cm.disposeTimers();
Program.cm.fixConsole();
}
public void pingProxies () {
Program.cm.updateStatus(Status.PINGING);
List<String> pinged = new List<String>();
foreach (string s in this.proxies) {
string[] sp = s.Split(':');
if (this.ping.Send(sp[0], Int32.Parse(sp[1])).Status == IPStatus.Success)
pinged.Add(s);
}
proxies = pinged;
}
public void inputDebugProxy (string proxy) { this.proxiesDebug.Add(proxy); }
#if DEBUG
/// <summary>
/// For debug
/// </summary>
/// <returns>The proxy list</returns>
public List<string> getProxies () { return this.proxies; }
#endif
}
}