Advertisement
Guest User

IP Range Transparent Proxy Script

a guest
Jul 7th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. # Firewall settings
  2.  
  3. for MASK in ...IP RANGE...; do
  4.     iptables -t nat -A PREROUTING -i "$LAN_IFACE" -s "$LAN_TYPE.$MASK" -p tcp --dport 80 -j DNAT --to "$PROXY_IP:$PROXY_PORT"
  5.     iptables -I FORWARD -s "$LAN_TYPE.$MASK" -d ! "$LAN_NET" -p tcp -j DROP
  6.     iptables -I FORWARD -d "$LAN_TYPE.$MASK" -s ! "$LAN_NET" -p tcp -j DROP
  7. done
  8.  
  9. # Startup settings
  10.  
  11. while :; do nc -l -p $PROXY_PORT -e /path/to/proxy_script; done &
  12.  
  13. # Proxy script
  14.  
  15. # read headers
  16.  
  17. if [ "$HTTP_HOST" == "$SERVER" ]; then
  18.     echo "HTTP/1.0 403 Forbidden"
  19. else
  20.     echo "HTTP/1.0 307 Temporary Redirect"
  21.     echo "Location: http://$SERVER/"
  22. fi
  23.  
  24. cat <<EOF
  25. Content-Type: text/html; charset=UTF-8
  26.  
  27. <html>
  28. <head>
  29. ...
  30. EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement