ipopbb
Power Member
- Feb 24, 2008
- 626
- 855
Mac OS X Proxy Testing & Switching
I recently did some work with some PVAs from XGC Media. The list of 200 accounts they sent me only had 16 working accounts in it. Within a day they had a new list of 200 for me that was perfect. I'm impressed. But the real reason for this post is that to work with these accounts it requires a large number of proxy servers and an efficient way to test them, configure them , and then reset safari so you don't get narc'ed by cookies. Below is the source code I used to automate all this by command line on OS X Lion. No need to buy proxy switching software on a mac.
First you need a web page that tells you your IP address and nothing else.
Next we need a shell script called "randomproxy" to execute from the terminal window.
Remember to "chmod 755 randomproxy" this script!
Then we need an applescript file called "resetsafari" to automate resetting Safari
Remember to "chmod 755 resetsafari" this script too!
Then optionally we need a script called "disableproxies" to turn the proxy config off when we are done
Remember to "chmod 755 disableproxies" this script too!
In a Terminal Window:
To pick a random proxy, test it, and configure it in your network settings if it passes and reset Safari just type:
To disable proxy settings when you are done just type:
I recently did some work with some PVAs from XGC Media. The list of 200 accounts they sent me only had 16 working accounts in it. Within a day they had a new list of 200 for me that was perfect. I'm impressed. But the real reason for this post is that to work with these accounts it requires a large number of proxy servers and an efficient way to test them, configure them , and then reset safari so you don't get narc'ed by cookies. Below is the source code I used to automate all this by command line on OS X Lion. No need to buy proxy switching software on a mac.
First you need a web page that tells you your IP address and nothing else.
Code:
<?php
// myip.php
header('Content-type: text/plain');
$ip = getenv("REMOTE_ADDR");
Echo $ip;
?>
Next we need a shell script called "randomproxy" to execute from the terminal window.
Code:
#!/bin/tcsh
set gateway = `curl -s "http://www.mywebsite.com/myip.php"`
set num = `jot -r 1 1 25`
set port = 60001
set login = "username"
set password = "password"
if ($num == 1) set pick = 100.200.300.1
else if ($num == 2) set pick = 100.200.300.2
else if ($num == 3) set pick = 100.200.300.3
else if ($num == 4) set pick = 100.200.300.4
else if ($num == 5) set pick = 100.200.300.5
endif
set proxy = "http://"$login":"$password"@"$pick":$port"
set unused = `curl -s -x "$proxy" "http://www.mywebsite.com/myip.php" -o "test.txt"`
set test = `more test.txt`
if ($test == $gateway) then
echo "FAILED: chose $pick and got $test and gateway $gateway"
else if ($pick == $test) then
echo "PASSED: chose $pick and got $test and gateway $gateway"
networksetup -setwebproxystate "Wi-Fi" On
networksetup -setsecurewebproxystate "Wi-Fi" On
networksetup -setwebproxy "Wi-Fi" $pick $port On $login $password
networksetup -setsecurewebproxy "Wi-Fi" $pick $port On $login $password
./resetsafari
else
echo "FAILED: chose $pick and got $test and gateway $gateway"
endif
Remember to "chmod 755 randomproxy" this script!
Then we need an applescript file called "resetsafari" to automate resetting Safari
Code:
#!/usr/bin/osascript
tell application "System Events"
tell process "Safari"
set frontmost to true
click menu item "Reset Safari?" of menu 1 of menu bar item "Safari" of menu bar 1
--delay 1 --may be uncommented if needed
click button "Reset" of window 1
end tell
end tell
Remember to "chmod 755 resetsafari" this script too!
Then optionally we need a script called "disableproxies" to turn the proxy config off when we are done
Code:
networksetup -setwebproxystate "Wi-Fi" Off
networksetup -setsecurewebproxystate "Wi-Fi" Off
Remember to "chmod 755 disableproxies" this script too!
In a Terminal Window:
To pick a random proxy, test it, and configure it in your network settings if it passes and reset Safari just type:
Code:
./randomproxy
To disable proxy settings when you are done just type:
Code:
./disableproxies