proxy socks via tunnel SSH avec Putty et C# .NET

Suite à l’excellent tuto : http://www.geeknewz.fr/tuto-proxy-socks-via-ssh-sur-synology-15567

Voici la même chose mais automatisé en C#:

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyProxyTunnel
{
class Program
{
static void Main(string[] args)
{
//checks which browsers are installed
RegistryKey browserKeys;
//on 64bit the browsers are in a different location
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
if (browserKeys == null)
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");

string[] browserNames = browserKeys.GetSubKeyNames();
if (browserNames.Contains("Google Chrome"))
{ //starts chrome with custom proxy settings (if chrome is installed)
Process browser = new Process();
browser.StartInfo.FileName = "chrome";
browser.Start();
browser.StartInfo.Arguments = "--proxy-server=\"socks5://localhost:443\"";
}
else
if (browserNames.Contains("FIREFOX.EXE"))
{ //else starts firefox
Process.Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
}

Process cmd = new Process();
cmd.StartInfo.FileName = @"C:\Program Files (x86)\PuTTY\plink.exe";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.Arguments = " -ssh admin@votreDNS_OU_IP_DU_SYNOLOGY_ICI:443 -pw VOTREMOTDEPASSE_SYNO_ICI -C -T -D 443 -N";
cmd.Start();
cmd.StandardInput.WriteLine("./myscript.sh");
cmd.StandardInput.WriteLine("y");
cmd.StandardInput.WriteLine("exit");
string output = cmd.StandardOutput.ReadToEnd();
}
}
}

A propos Xavier

7 years+ .net consulting
Taggé , , , , , , .Lien pour marque-pages : Permaliens.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Captcha * Time limit is exhausted. Please reload CAPTCHA.