Skip to content

Commit

Permalink
- Add SOCKS 4/4a/5 proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaBear84 committed Oct 5, 2021
1 parent 2833ed3 commit 67a1e26
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Command line parameters:
|   | `--username` | Username |
|   | `--password` | Password |
|   | `--output-file` | Output file to use for urls file |
|   | `--proxy-address` | Proxy Address, like "socks5://127.0.0.1:9050" (needed for .onion) |
|   | `--proxy-username` | Proxy username |
|   | `--proxy-password` | Proxy password |

### Example

Expand All @@ -61,7 +64,7 @@ Command line parameters:

#### Linux

`./OpenDirectoryDownloader -u "https://myopendirectory.com"`
`./OpenDirectoryDownloader --url "https://myopendirectory.com"`

If you want to learn more or contribute, see the following paragraphs!

Expand All @@ -83,6 +86,12 @@ It will save the URLs files onto C:\\Scans (windows), or replace with a custom f

\* You can also run it without `-v c:/scans:/app/Scans` if you don't want to save the results on your host.

## Onion / Tor support

1. Make sure the Tor is running on your machine
2. Use the correct proxy address notation, default for Tor is: "socks5://127.0.0.1:9050"
3. Start it with --proxy-address parameter: `OpenDirectoryDownloader.exe --url "http://*.onion/" --proxy-address "socks5://127.0.0.1:9050"`

## Getting the code

### For Visual Studio (Windows)
Expand Down
9 changes: 9 additions & 0 deletions src/OpenDirectoryDownloader/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public class CommandLineOptions
[Option("fast-scan", Required = false, Default = false, HelpText = "Only perform actions that are fast, so no HEAD requests, etc. Might result in missing file sizes")]
public bool FastScan { get; set; }

[Option("proxy-address", Required = false, Default = "", HelpText = "Proxy address, like: socks5://127.0.0.1:9050")]
public string ProxyAddress { get; set; }

[Option("proxy-username", Required = false, Default = "", HelpText = "Proxy username")]
public string ProxyUsername { get; set; }

[Option("proxy-password", Required = false, Default = "", HelpText = "Proxy password")]
public string ProxyPassword { get; set; }

// TODO: Future use
//[Option('d', "download", Required = false, HelpText = "Downloads the contents (after indexing is finished)")]
//public bool Download { get; set; }
Expand Down
15 changes: 15 additions & 0 deletions src/OpenDirectoryDownloader/OpenDirectoryIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ public OpenDirectoryIndexer(OpenDirectoryIndexerSettings openDirectoryIndexerSet
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli
};

if (!string.IsNullOrWhiteSpace(OpenDirectoryIndexerSettings.CommandLineOptions.ProxyAddress))
{
WebProxy webProxy = new WebProxy
{
Address = new Uri(OpenDirectoryIndexerSettings.CommandLineOptions.ProxyAddress),
};

if (!string.IsNullOrWhiteSpace(OpenDirectoryIndexerSettings.CommandLineOptions.ProxyUsername) || !string.IsNullOrWhiteSpace(OpenDirectoryIndexerSettings.CommandLineOptions.ProxyPassword))
{
webProxy.Credentials = new NetworkCredential(OpenDirectoryIndexerSettings.CommandLineOptions.ProxyUsername, OpenDirectoryIndexerSettings.CommandLineOptions.ProxyPassword);
}

HttpClientHandler.Proxy = webProxy;
}

HttpClient = new HttpClient(HttpClientHandler)
{
Timeout = TimeSpan.FromSeconds(OpenDirectoryIndexerSettings.Timeout)
Expand Down

0 comments on commit 67a1e26

Please sign in to comment.