Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/2captcha/2captcha-csharp

C# library for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
https://github.com/2captcha/2captcha-csharp

2captcha anti-captcha anticaptcha bypass-invisible-recaptcha bypass-on-captcha-recaptcha bypass-recaptcha-v2 bypasscaptcha captcha-breaking captcha-bypass captcha-recognition captcha-services-for-recaptcha-v2 captcha-solver captcha-solving deathbycaptcha google-recaptcha-solver hcaptcha-solver recaptcha-bypass-script recaptcha-solver recaptcha-solver-csharp recaptcha-v2-captcha-solver

Last synced: 2 days ago
JSON representation

C# library for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.

Awesome Lists containing this project

README

        

python library
javascript library
go library
ruby library
cpp library
php library
java library
csharp library

# C# Module for 2Captcha API (captcha solver)
The easiest way to quickly integrate [2Captcha] into your code to automate solving of any types of captcha.
Examples of API requests for different captcha types are available on the [C# captcha solver](https://2captcha.com/lang/csharp) page.

- [C# Module for 2Captcha API (captcha solver)](#c-module-for-2captcha-api-captcha-solver)
- [Installation](#installation)
- [Configuration](#configuration)
- [TwoCaptcha instance options](#twocaptcha-instance-options)
- [Solve captcha](#solve-captcha)
- [Captcha options](#captcha-options)
- [Basic example](#basic-example)
- [Normal Captcha](#normal-captcha)
- [Text Captcha](#text-captcha)
- [reCAPTCHA v2](#recaptcha-v2)
- [reCAPTCHA v3](#recaptcha-v3)
- [FunCaptcha](#funcaptcha)
- [GeeTest](#geetest)
- [GeeTest v4](#geetest-v4)
- [hCaptcha](#hcaptcha)
- [KeyCaptcha](#keycaptcha)
- [Capy](#capy)
- [Grid](#grid)
- [Canvas](#canvas)
- [ClickCaptcha](#clickcaptcha)
- [Rotate](#rotate)
- [Audio Captcha](#audio-captcha)
- [Yandex](#yandex)
- [Lemin Cropped Captcha](#lemin-cropped-captcha)
- [Cloudflare Turnstile](#cloudflare-turnstile)
- [Amazon WAF](#amazon-waf)
- [Friendly Captcha](#friendly-captcha)
- [MTCaptcha](#mtcaptcha)
- [Cutcaptcha](#cutcaptcha)
- [CyberSiARA](#cybersiara)
- [DataDome](#datadome)
- [atbCAPTCHA](#atbcaptcha)
- [Tencent](#tencent)
- [Other methods](#other-methods)
- [send / getResult](#send--getresult)
- [balance](#balance)
- [report](#report)
- [Proxies](#proxies)
- [Error handling](#error-handling)
- [Get in touch](#get-in-touch)
- [Join the team 👪](#join-the-team-)
- [License](#license)
- [Graphics and Trademarks](#graphics-and-trademarks)

## Installation
Install nuget package from [nuget]:

`dotnet add package 2captcha-csharp`

## Configuration
`TwoCaptcha` instance can be created like this:
```csharp
TwoCaptcha solver = new TwoCaptcha('YOUR_API_KEY');
```
Also there are few options that can be configured:
```csharp
solver.SoftId = 123;
solver.Callback = "https://your.site/result-receiver";
solver.DefaultTimeout = 120;
solver.RecaptchaTimeout = 600;
solver.PollingInterval = 10;
```

### TwoCaptcha instance options

| Option | Default value | Description |
| ---------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| softId | 4582 | your software ID obtained after publishing in [2captcha sofware catalog] |
| callback | - | URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account |
| defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from `res.php` API endpoint |
| recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from `res.php` API endpoint |
| pollingInterval | 10 | Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended |

> **IMPORTANT:** once `Callback` is defined for `TwoCaptcha` instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL.
To get the answer manually use [getResult method](#send--getresult)

## Solve captcha
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.

### Captcha options
| Option | Default Value | Description |
| ------------- | ------------- | -------------------------------------------------------------------------------------------------- |
| numeric | 0 | Defines if captcha contains numeric or other symbols [see more info in the API docs][post options] |
| minLength | 0 | minimal answer lenght |
| maxLength | 0 | maximum answer length |
| phrase | 0 | defines if the answer contains multiple words or not |
| caseSensitive | 0 | defines if the answer is case sensitive |
| calc | 0 | defines captcha requires calculation |
| lang | - | defines the captcha language, see the [list of supported languages] |
| hintImg | - | an image with hint shown to workers with the captcha |
| hintText | - | hint or task text shown to workers with the captcha |

Below you can find basic examples for every captcha type. Check out [examples directory] to find more examples with all available options.

### Basic example
Example below shows a basic solver call example with error handling.

```csharp
Normal captcha = new Normal();
captcha.SetFile("path/to/captcha.jpg");
captcha.SetMinLen(4);
captcha.SetMaxLen(20);
captcha.SetCaseSensitive(true);
captcha.SetLang("en");

try
{
await solver.Solve(captcha);
Console.WriteLine("Captcha solved: " + captcha.Code);
}
catch (Exception e)
{
Console.WriteLine("Error occurred: " + e.Message);
}
```

### Normal Captcha

[API method description.](https://2captcha.com/2captcha-api#solving_normal_captcha)

To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.

```csharp
Normal captcha = new Normal();
captcha.SetFile("path/to/captcha.jpg");
captcha.SetNumeric(4);
captcha.SetMinLen(4);
captcha.SetMaxLen(20);
captcha.SetPhrase(true);
captcha.SetCaseSensitive(true);
captcha.SetCalc(false);
captcha.SetLang("en");
captcha.SetHintImg(new FileInfo("path/to/hint.jpg"));
captcha.SetHintText("Type red symbols only");
```

### Text Captcha

[API method description.](https://2captcha.com/2captcha-api#solving_text_captcha)

This method can be used to bypass a captcha that requires to answer a question provided in clear text.

```csharp
Text captcha = new Text();
captcha.SetText("If tomorrow is Saturday, what day is today?");
captcha.SetLang("en");
```

### reCAPTCHA v2

[API method description.](https://2captcha.com/2captcha-api#solving_recaptchav2_new)

Use this method to solve reCAPTCHA V2 and obtain a token to bypass the protection.

```csharp
ReCaptcha captcha = new ReCaptcha();
captcha.SetSiteKey("6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-");
captcha.SetUrl("https://mysite.com/page/with/recaptcha");
captcha.SetInvisible(true);
captcha.SetEnterprise(false);
captcha.SetAction("verify");
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```
### reCAPTCHA v3

[API method description.](https://2captcha.com/2captcha-api#solving_recaptchav3)

This method provides reCAPTCHA V3 solver and returns a token.

```csharp
ReCaptcha captcha = new ReCaptcha();
captcha.SetSiteKey("6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-");
captcha.SetUrl("https://mysite.com/page/with/recaptcha");
captcha.SetVersion("v3");
captcha.SetEnterprise(false);
captcha.SetDomain("google.com");
captcha.SetAction("verify");
captcha.SetScore(0.3);
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

### FunCaptcha

[API method description.](https://2captcha.com/2captcha-api#solving_funcaptcha_new)

FunCaptcha (Arkoselabs) solving method. Returns a token.

```csharp
FunCaptcha captcha = new FunCaptcha();
captcha.SetSiteKey("69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC");
captcha.SetUrl("https://mysite.com/page/with/funcaptcha");
captcha.SetSUrl("https://client-api.arkoselabs.com");
captcha.SetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36");
captcha.SetData("anyKey", "anyValue");
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

### GeeTest

[API method description.](https://2captcha.com/2captcha-api#solving_geetest)

Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.

```csharp
GeeTest captcha = new GeeTest();
captcha.SetGt("f2ae6cadcf7886856696502e1d55e00c");
captcha.SetApiServer("api-na.geetest.com");
captcha.SetChallenge("12345678abc90123d45678ef90123a456b");
captcha.SetUrl("https://mysite.com/captcha.html");
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

### GeeTest v4

[API method description.](https://2captcha.com/2captcha-api#geetest-v4)

Method to solve GeeTest v4 puzzle captcha. Returns a set of tokens as JSON.

```csharp
GeeTestV4 captcha = new GeeTestV4();
captcha.SetCaptchaId("72bf15796d0b69c43867452fea615052");
captcha.SetChallenge("12345678abc90123d45678ef90123a456b");
captcha.SetUrl("https://mysite.com/captcha.html");
```

### hCaptcha

[API method description.](https://2captcha.com/2captcha-api#solving_hcaptcha)

Use this method to solve hCaptcha challenge. Returns a token to bypass captcha.

```csharp
HCaptcha captcha = new HCaptcha();
captcha.SetSiteKey("10000000-ffff-ffff-ffff-000000000001");
captcha.SetUrl("https://www.site.com/page/");
captcha.SetData("foo");
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

### KeyCaptcha

[API method description.](https://2captcha.com/2captcha-api#solving_keycaptcha)

Token-based method to solve KeyCaptcha.

```csharp
KeyCaptcha captcha = new KeyCaptcha();
captcha.SetUserId(10);
captcha.SetSessionId("493e52c37c10c2bcdf4a00cbc9ccd1e8");
captcha.SetWebServerSign("9006dc725760858e4c0715b835472f22");
captcha.SetWebServerSign2("2ca3abe86d90c6142d5571db98af6714");
captcha.SetUrl("https://www.keycaptcha.ru/demo-magnetic/");
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

### Capy

[API method description.](https://2captcha.com/2captcha-api#solving_capy)

Token-based method to bypass Capy puzzle captcha.

```csharp
Capy captcha = new Capy();
captcha.SetSiteKey("PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v");
captcha.SetUrl("https://www.mysite.com/captcha/");
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

### Grid

[API method description.](https://2captcha.com/2captcha-api#grid)

Grid method is originally called Old reCAPTCHA V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes.

```csharp
Grid captcha = new Grid();
captcha.SetFile("path/to/captcha.jpg");
captcha.SetRows(3);
captcha.SetCols(3);
captcha.SetPreviousId(0);
captcha.SetCanSkip(false);
captcha.SetLang("en");
captcha.SetHintImg(new FileInfo("path/to/hint.jpg"));
captcha.SetHintText("Select all images with an Orange");
```

### Canvas

[API method description.](https://2captcha.com/2captcha-api#canvas)

Canvas method can be used when you need to draw a line around an object on image. Returns a set of points' coordinates to draw a polygon.

```csharp
Canvas captcha = new Canvas();
captcha.SetFile("path/to/captcha.jpg");
captcha.SetPreviousId(0);
captcha.SetCanSkip(false);
captcha.SetLang("en");
captcha.SetHintImg(new FileInfo("path/to/hint.jpg"));
captcha.SetHintText("Draw around apple");
```

### ClickCaptcha

[API method description.](https://2captcha.com/2captcha-api#coordinates)

ClickCaptcha (Coordinates) method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.

```csharp
Coordinates captcha = new Coordinates();
captcha.SetFile("path/to/captcha.jpg");
captcha.SetLang("en");
captcha.SetHintImg(new FileInfo("path/to/hint.jpg"));
captcha.SetHintText("Select all images with an Orange");
```

### Rotate

[API method description.](https://2captcha.com/2captcha-api#solving_rotatecaptcha)

This method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.

```csharp
Rotate captcha = new Rotate();
captcha.SetFile("path/to/captcha.jpg");
captcha.SetAngle(40);
captcha.SetLang("en");
captcha.SetHintImg(new FileInfo("path/to/hint.jpg"));
captcha.SetHintText("Put the images in the correct way up");
```

### Audio Captcha

[API method description.](https://2captcha.com/2captcha-api#audio)

This method can be used to solve a audio captcha (mp3 formats only).
You must provide the language as `lang = 'en'`. Supported languages are "en", "ru", "de", "el", "pt", "fr".

```csharp
AudioCaptcha captcha = new AudioCaptcha();
byte[] bytes = File.ReadAllBytes("../../resources/audio-en.mp3");
string base64EncodedImage = Convert.ToBase64String(bytes);
captcha.SetBase64(base64EncodedImage);
```

### Yandex

Use this method to solve Yandex and obtain a token to bypass the protection.

```csharp
Yandex captcha = new Yandex();
captcha.SetSiteKey("Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV");
captcha.SetUrl("https://rutube.ru");
```

### Lemin Cropped Captcha

[API method description.](https://2captcha.com/2captcha-api#lemin)

Use this method to solve Lemin and obtain a token to bypass the protection.

```csharp
Lemin captcha = new Lemin();
captcha.SetCaptchaId("CROPPED_d3d4d56_73ca4008925b4f83a8bed59c2dd0df6d");
captcha.SetApiServer("api.leminnow.com");
captcha.SetUrl("http://sat2.aksigorta.com.tr");
```

### Cloudflare Turnstile

[API method description.](https://2captcha.com/2captcha-api#turnstile)

Use this method to solve Cloudflare Turnstile and obtain a token to bypass the protection.

```csharp
Turnstile captcha = new Turnstile();
captcha.SetSiteKey("0x4AAAAAAAChNiVJM_WtShFf");
captcha.SetUrl("https://ace.fusionist.io");
captcha.SetData("foo");
captcha.SetPageData("bar");
captcha.SetAction("baz");
```

### Amazon WAF

[API method description.](https://2captcha.com/2captcha-api#amazon-waf)

Use this method to solve Amazon WAF Captcha also known as AWS WAF Captcha is a part of Intelligent threat mitigation for Amazon AWS. Returns JSON with the token.

```csharp
AmazonWaf captcha = new AmazonWaf();
captcha.SetSiteKey("AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AF5H1K/siwSLK7RfstKtN5bAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglg");
captcha.SetUrl("https://non-existent-example.execute-api.us-east-1.amazonaws.com");
captcha.SetContext("test_iv");
captcha.SetIV("test_context");
```

### Friendly Captcha

[API method description.](https://2captcha.com/2captcha-api#friendly-captcha)

Use this method to solve Friendly Captcha. Returns a token to bypass the captcha.

> [!IMPORTANT]
> To successfully use the received token, the captcha widget must not be loaded on the page. To do this, you need to abort request to `/friendlycaptcha/...module.min.js` on the page. When the captcha widget is already loaded on the page, there is a high probability that the received token will not work.

```csharp
FriendlyCaptcha captcha = new FriendlyCaptcha();
captcha.SetSiteKey("2FZFEVS1FZCGQ9");
captcha.SetUrl("https://example.com");
```

### MTCaptcha

[API method description.](https://2captcha.com/2captcha-api#mtcaptcha)

Use this method to solve MTCaptcha. Returns a token to bypass the captcha.

```csharp
MTCaptcha captcha = new MTCaptcha();
captcha.SetSiteKey("MTPublic-KzqLY1cKH");
captcha.SetPageUrl("https://2captcha.com/demo/mtcaptcha");
```

### Cutcaptcha

[API method description.](https://2captcha.com/2captcha-api#cutcaptcha)

Use this method to solve Cutcaptcha. Returns a token to bypass the captcha.

```csharp
Cutcaptcha captcha = new Cutcaptcha();
captcha.SetMiseryKey("a1488b66da00bf332a1488993a5443c79047e752");
captcha.SetPageUrl("https://example.cc/foo/bar.html");
captcha.SetApiKey("SAb83IIB");
```

### CyberSiARA

[API method description.](https://2captcha.com/2captcha-api#cybersiara)

Use this method to solve CyberSiARA. Returns a token to bypass the captcha.

```csharp
CyberSiARA cyberSiARA = new CyberSiARA();
cyberSiARA.SetMasterUrlId("tpjOCKjjpdzv3d8Ub2E9COEWKt1vl1Mv");
cyberSiARA.SetPageUrl("https://demo.mycybersiara.com/");
cyberSiARA.SetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");
```

### DataDome

[API method description.](https://2captcha.com/2captcha-api#datadome)

Use this method to solve DataDome captcha.

> [!IMPORTANT]
> To solve the DataDome captcha, you must use a proxy. It is recommended to use [residential proxies].

```csharp
DataDome dataDome = new DataDome();
dataDome.SetCapthaUrl("https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAA...P~XFrBVptk&t=fe&referer=https%3A%2F%2Fhexample.com&s=45239&e=c538be..c510a00ea");
dataDome.SetPageUrl("https://example.com/");
dataDome.SetProxy("http", "username:[email protected]:5678");
dataDome.SetUserAgent("Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.3");
```

### atbCAPTCHA

[API method description.](https://2captcha.com/2captcha-api#atb-captcha)

Use this method to solve atbCAPTCHA. Returns a token to bypass the captcha.

```csharp
AtbCAPTCHA atbCAPTCHA = new AtbCAPTCHA();
atbCAPTCHA.SetAppId("af23e041b22d000a11e22a230fa8991c");
atbCAPTCHA.SetApiServer("https://cap.aisecurius.com");
atbCAPTCHA.SetPageUrl("https://www.example.com/");
```

### Tencent

[API method description.](https://2captcha.com/2captcha-api#tencent)

Use this method to solve Tencent captcha. Returns a token to bypass the captcha.

```csharp
Tencent tencent = new Tencent();
tencent.SetAppId("190014885");
tencent.SetPageUrl("https://www.example.com/");
```

## Other methods

### send / getResult
These methods can be used for manual captcha submission and answer polling.

```csharp
string captchaId = await solver.Send(captcha);

Task.sleep(20 * 1000);

string code = await solver.GetResult(captchaId);
```
### balance

[API method description.](https://2captcha.com/2captcha-api#additional-methods)

Use this method to get your account's balance

```csharp
double balance = await solver.Balance();
```
### report

[API method description.](https://2captcha.com/2captcha-api#complain)

Use this method to report good or bad captcha answer.

```csharp
await solver.Report(captcha.Id, true); // captcha solved correctly
await solver.Report(captcha.Id, false); // captcha solved incorrectly
```
## Proxies

You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, hcaptcha, keycaptcha, capy puzzle, lemin, cloudflare turnstile, amazon waf, friendly captcha, mtcaptcha, cutcaptcha, cybersiara, datadome, atbcaptcha, tencent and etc. The proxy will be forwarded to the API to solve the captcha.

We have our own proxies that we can offer you. [Buy residential proxies] for avoid restrictions and blocks. [Quick start].

```csharp
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

## Error handling
If case of an error captcha solver throws an exception. It's important to properly handle these cases. We recommend to use `try catch` to handle exceptions.
The list of all errors can be found in the [API documentation](https://2captcha.com/2captcha-api#list-of-inphp-errors).

```csharp
try
{
await solver.Solve(captcha);
}
catch (ValidationException e)
{
// invalid parameters passed
}
catch (NetworkException e)
{
// network error occurred
}
catch (ApiException e)
{
// api respond with error
}
catch (TimeoutException e)
{
// captcha is not solved so far
}
```

## Get in touch

Send email to support
Create ticket

## Join the team 👪

There are many ways to contribute, of which development is only one! Find your next job. Open positions: AI experts, scrapers, developers, technical support, and much more! 😍

Send email to support

# License

The code in this repository is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.

### Graphics and Trademarks

The graphics and trademarks included in this repository are not covered by the MIT License. Please contact support for permissions regarding the use of these materials.

[nuget]: https://www.nuget.org/packages/2captcha-csharp/
[2Captcha]: https://2captcha.com/
[2captcha sofware catalog]: https://2captcha.com/software
[Pingback settings]: https://2captcha.com/setting/pingback
[Post options]: https://2captcha.com/2captcha-api#normal_post
[list of supported languages]: https://2captcha.com/2captcha-api#language
[Examples directory]: /TwoCaptcha.Examples
[residential proxies]: https://2captcha.com/proxy/residential-proxies
[Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true