-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaptchaGuruClient.cs
More file actions
109 lines (94 loc) · 4.15 KB
/
CaptchaGuruClient.cs
File metadata and controls
109 lines (94 loc) · 4.15 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
public class CaptchaGuruClient
{
public string APIKey { get; private set; }
public CaptchaGuruClient(string apiKey)
{
APIKey = apiKey;
}
/// <summary>
/// Sends a solve request and waits for a response
/// </summary>
/// <param name="googleKey">The "sitekey" value from site your captcha is located on</param>
/// <param name="pageUrl">The page the captcha is located on</param>
/// <param name="proxy">The proxy used, format: "username:password@ip:port</param>
/// <param name="proxyType">The type of proxy used</param>
/// <param name="result">If solving was successful this contains the answer</param>
/// <returns>Returns true if solving was successful, otherwise false</returns>
public bool SolveRecaptchaV2(string googleKey, string pageUrl, out string result)
{
string requestUrl = "http://api.captcha.guru/in.php?key=" + APIKey + "&method=userrecaptcha&googlekey=" + googleKey + "&pageurl=" + pageUrl;
try
{
WebRequest req = WebRequest.Create(requestUrl);
using (WebResponse resp = req.GetResponse())
using (StreamReader read = new StreamReader(resp.GetResponseStream()))
{
string response = read.ReadToEnd();
if (response.Length < 3)
{
result = response;
return false;
}
else
{
if (response.Substring(0, 3) == "OK|")
{
string captchaID = response.Remove(0, 3);
for (int i = 0; i < 24; i++)
{
WebRequest getAnswer = WebRequest.Create("http://api.captcha.guru/res.php?key=" + APIKey + "&action=get&id=" + captchaID);
using (WebResponse answerResp = getAnswer.GetResponse())
using (StreamReader answerStream = new StreamReader(answerResp.GetResponseStream()))
{
string answerResponse = answerStream.ReadToEnd();
if (answerResponse.Length < 3)
{
result = answerResponse;
return false;
}
else
{
if (answerResponse.Substring(0, 3) == "OK|")
{
result = answerResponse.Remove(0, 3);
return true;
}
else if (answerResponse != "CAPCHA_NOT_READY")
{
result = answerResponse;
return false;
}
}
}
Thread.Sleep(5000);
}
result = "Timeout";
return false;
}
else
{
result = response;
return false;
}
}
}
}
catch { }
result = "Unknown error";
return false;
}
}
public enum ProxyType
{
HTTP,
HTTPS,
SOCKS4,
SOCKS5
}