{"id":781,"date":"2017-02-20T19:52:39","date_gmt":"2017-02-20T17:52:39","guid":{"rendered":"https:\/\/blog.avxt.fr\/?p=781"},"modified":"2019-09-02T15:25:07","modified_gmt":"2019-09-02T13:25:07","slug":"proxy-socks-via-tunnel-ssh-avec-synology-putty-et-c-net","status":"publish","type":"post","link":"https:\/\/blog.avxt.fr\/fr\/proxy-socks-via-tunnel-ssh-avec-synology-putty-et-c-net\/","title":{"rendered":"proxy socks via tunnel SSH avec Putty et C# .NET"},"content":{"rendered":"<p>Suite \u00e0 l&rsquo;excellent tuto (qui date un peu mais excellent quand m\u00eame ! ) :\u00a0<a href=\"http:\/\/www.geeknewz.fr\/tuto-proxy-socks-via-ssh-sur-synology-15567\">http:\/\/www.geeknewz.fr\/tuto-proxy-socks-via-ssh-sur-synology-15567<\/a><\/p>\n<p>Voici la m\u00eame chose, mais automatis\u00e9e en C#: n&rsquo;oubliez pas de remplacer\u00a0YOUR_SYNOLOGY_DNS_OR_IP_HERE \u00a0par l&rsquo;adresse ou le dns name de votre synology<\/p>\n<p>et aussi le mot de passe admin de votre syno \u00e0 la place de\u00a0YOUR_SYNOLOGY_PASSWORD_HERE<\/p>\n<p>on peut l\u00e9g\u00e8rement modifier le code pour ne pas mettre en dur le mot de passe et l&rsquo;entrer \u00e0 chaque nouvelle connexion (Console.ReadLine()&#8230;\u00a0et supprimer:<\/p>\n<pre class=\"lang:c#\">cmd.StandardInput.WriteLine(\".\/myscript.sh\");\r\n            cmd.StandardInput.WriteLine(\"y\");\r\n            cmd.StandardInput.WriteLine(\"exit\");<\/pre>\n<pre class=\"lang:c#\">using Microsoft.Win32;\r\nusing Microsoft.Win32;\r\nusing OpenQA.Selenium;\r\nusing OpenQA.Selenium.Chrome;\r\nusing OpenQA.Selenium.Firefox;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Diagnostics;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Reflection;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace MyProxyTunnel\r\n{\r\n    class Program\r\n    {\r\n\r\n        private static bool keepRunning = true;\r\n        static void Main(string[] args)\r\n        {\r\n            \/\/CTRL+C to quit console app\r\n            Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)\r\n            {\r\n                e.Cancel = true;\r\n                Program.keepRunning = false;\r\n\r\n            };\r\n\r\n            \/\/PART 1 :\r\n            \/\/checks which browsers are installed\r\n            RegistryKey browserKeys;\r\n            \/\/on 64bit the browsers are in a different location\r\n            browserKeys = Registry.LocalMachine.OpenSubKey(@\"SOFTWARE\\WOW6432Node\\Clients\\StartMenuInternet\");\r\n            if (browserKeys == null)\r\n                browserKeys = Registry.LocalMachine.OpenSubKey(@\"SOFTWARE\\Clients\\StartMenuInternet\");\r\n\r\n            string[] browserNames = browserKeys.GetSubKeyNames();\r\n            var driverpath = Path.GetDirectoryName(Assembly.GetExecutingAssembl\u200c\u200by().Location);\r\n            IWebDriver driver = null;\r\n\r\n            \/\/PART II : run proxy tunnel\r\n            Process cmd = new Process();\r\n            cmd.StartInfo.FileName = @\"C:\\Program Files (x86)\\PuTTY\\plink.exe\";\r\n            cmd.StartInfo.UseShellExecute = false;\r\n            cmd.StartInfo.RedirectStandardInput = true;\r\n            cmd.StartInfo.RedirectStandardOutput = true;\r\n            cmd.StartInfo.Arguments = \" -ssh admin@YOUR_SYNOLOGY_DNS_OR_IP_HERE:443 -pw YOUR_SYNOLOGY_PASSWORD_HERE  -C -T -D 443 -N\";\r\n            cmd.Start();\r\n            \/\/this below is for removing the 'enter \"yes\"' keyboard confirmation \r\n            cmd.StandardInput.WriteLine(\".\/myscript.sh\");\r\n            cmd.StandardInput.WriteLine(\"y\");\r\n            cmd.StandardInput.WriteLine(\"exit\");\r\n          \/\/  string output = cmd.StandardOutput.ReadToEnd();\r\n\r\n            \/\/PART III : run browser\r\n            if (browserNames.Contains(\"Google Chromes\"))\r\n            { \/\/starts chrome with custom proxy settings ; you need chromedriver.exe \/\/just install the WebDriver from Nuget Package manager\r\n\r\n                ChromeOptions options = new ChromeOptions();\r\n                options.AddArguments(\"--proxy-server=socks5:\/\/localhost:443\");\r\n                driver = new ChromeDriver(driverpath, options);\r\n\r\n\r\n            }\r\n            else\r\n                if (browserNames.Contains(\"FIREFOX.EXE\"))\r\n            { \/\/else starts firefox\r\n              \/\/Create a new Firefox profile\r\n                var firefoxProfile = new FirefoxProfile();\r\n                \/\/Create a new proxy object\r\n                var proxy = new Proxy()\r\n                {\r\n                    SocksProxy = \"localhost:443\"\r\n                };\r\n                \/\/We then add this proxt setting to the Firefox profile we created\r\n                firefoxProfile.SetProxyPreferences(proxy);\r\n                \/\/Then create a new Firefox Driver passing in the profile we created\r\n                \/\/WebDriver we open a Firefox using this profile now\r\n                driver = new FirefoxDriver(firefoxProfile);\r\n\r\n            }\r\n            if (driver != null)\r\n                driver.Navigate().GoToUrl(\"http:\/\/www.google.fr\");\r\n\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Suite \u00e0 l&rsquo;excellent tuto (qui date un peu mais excellent quand m\u00eame ! ) :\u00a0http:\/\/www.geeknewz.fr\/tuto-proxy-socks-via-ssh-sur-synology-15567 Voici la m\u00eame chose, mais automatis\u00e9e en C#: n&rsquo;oubliez pas de remplacer\u00a0YOUR_SYNOLOGY_DNS_OR_IP_HERE \u00a0par l&rsquo;adresse ou le dns name de votre synology et aussi le mot de passe admin de votre syno \u00e0 la place de\u00a0YOUR_SYNOLOGY_PASSWORD_HERE \u2026 <a class=\"continue-reading-link\" href=\"https:\/\/blog.avxt.fr\/fr\/proxy-socks-via-tunnel-ssh-avec-synology-putty-et-c-net\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[77,106],"tags":[137,132,136,133,135,82,134],"class_list":["post-781","post","type-post","status-publish","format-standard","hentry","category-programming","category-synology-computers","tag-c-net","tag-proxy","tag-putty","tag-socks","tag-ssh","tag-synology","tag-tunnel"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts\/781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/comments?post=781"}],"version-history":[{"count":21,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts\/781\/revisions"}],"predecessor-version":[{"id":862,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts\/781\/revisions\/862"}],"wp:attachment":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/media?parent=781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/categories?post=781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/tags?post=781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}