Created
August 19, 2013 10:35
-
-
Save andrewmackrodt/6267809 to your computer and use it in GitHub Desktop.
Launch Google Chrome on Windows using a Socks 5 Proxy Connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| echo. | |
| :: set the local (dynamic) port for the Socks5 proxy | |
| set lport=3128 | |
| :: ssh details | |
| set rport=22 | |
| set username=andrew | |
| set hostname=myproxy.tld | |
| :: set the program files directory dependent on x86 or x64 install | |
| set apphome=%programfiles% | |
| if exist "%programfiles(x86)%" set apphome=%programfiles(x86)% | |
| :: set the location to PuTTY link | |
| set plink=%apphome%\PuTTY\plink.exe | |
| if not exist "%plink%" ( | |
| echo PuTTY link was not found | |
| echo http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html | |
| goto error | |
| ) | |
| :: set the location to the PuTTY private key | |
| set pkey=%userprofile%\.ssh\id_rsa.ppk | |
| if not exist "%pkey%" ( | |
| echo PuTTY private key was not found in %pkey% | |
| goto error | |
| ) | |
| :: set the location to Google Chrome | |
| set chrome=%apphome%\Google\Chrome\Application\chrome.exe | |
| if not exist "%chrome%" chrome=%localappdata%\Google\Chrome\Application\chrome.exe | |
| if not exist "%chrome%" ( | |
| echo Google Chrome was not found | |
| echo https://www.google.com/intl/en/chrome/browser/ | |
| goto error | |
| ) | |
| echo Do not close this window or the one containing has the text | |
| echo 'Using username "%username%".' until you close Google Chrome | |
| :: start the tunnel and store the process id | |
| for /f "delims=" %%i in ('wmic process call create "%plink% -noagent -i \"%pkey%\" -N -D %lport% -P %rport% %username%@%hostname%" ^| find "ProcessId"') do set pid=%%i | |
| set pid=%pid:~13, -1% | |
| :: generate a name for Google Chrome's profile directory using the current time | |
| set profile=%date:~8,2%%date:~3,2%%date:~0,2%%time:~0,2%%time:~3,2%%time:~6,2% | |
| set profile=%temp%\sshproxy_%profile% | |
| :: sleep for 2 seconds before launching Google Chrome | |
| timeout 2 > nul | |
| "%chrome%" --no-default-browser-check --proxy-server="socks5://127.0.0.1:%lport%" --user-data-dir="%profile%" http://www.whatismyip.com/ | |
| :: kill the PuTTY link process | |
| taskkill /pid %pid% > nul | |
| :: remove the temporary profile | |
| rmdir /s /q %profile% | |
| :: program execution occurred with no errors | |
| echo Success | |
| goto end | |
| :error | |
| goto end | |
| :end | |
| echo. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment