Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ergatea
Created January 20, 2013 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ergatea/4578877 to your computer and use it in GitHub Desktop.
Save ergatea/4578877 to your computer and use it in GitHub Desktop.
shell gfwlist
#!/bin/bash
cat << EOF
/*
* Proxy Auto-Config file generated by autoproxy2pac
* Rule source: http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
* Last update: Sat, 16 Jun 2012 16:35:28 GMT
*/
function FindProxyForURL(url, host) {
var PROXY = "SOCKS 192.168.11.254:1080; SOCKS5 192.168.11.254:1080";
var DEFAULT = "DIRECT";
if (localHosts(url, host)) {
return DEFAULT;
}
if (unresolvableDomains(url, host)) {
return PROXY;
}
if (gfwlistDomains(url, host)) {
return PROXY;
}
return DEFAULT;
}
EOF
echo -e "function gfwlistDomains (url, host) {\n\tif (false"
curl 'http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt' 2>/dev/null \
| base64 -d \
| sed 's/@\||\|^\.\|\/$//g' |sort -u \
| awk '!(/^$/||/^!/||/\[Auto/||/\^h/) {print "\t\t|| shExpMatch(url, \"*"$1"*\")"}'
echo -e "\t{\n\t\treturn true;\n\t}\telse\n\t\treturn false;\n}"
cat << EOF
function unresolvableDomains (url, host) {
if (false
) {
return true;
}
return false;
}
function localHosts (url, host) {
if(isPlainHostName(host)
|| isInNet(host, '192.168.0.0', '255.255.0.0')
|| isInNet(host, '10.0.0.0', '255.0.0.0')
|| isInNet(host, '172.0.0.0', '255.0.0.0')
|| isInNet(host, '127.0.0.0', '255.255.255.0')
)
return true;
else
return false;
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment