#!/usr/bin/env ruby port = 3128 proxy_host = "localhost" proxy_port = "8080" require 'socket' serv = TCPserver.open(3128) while TRUE Thread.start(serv.accept) do |s| print(s, " is accepted\n") req = s.sysread(65536) req =~ /^[A-Z]* [a-z]*:\/\/([^:\/]*)(:(\d*))?(\/[^ ]*)/; host = $1 port = ($3 != nil) ? $3.to_i : 80 path = $4 if proxy_host == nil client = TCPsocket.open(host, port) print "open connection to #{host}:#{port}\n" else client = TCPsocket.open(proxy_host, proxy_port) print "open connection to #{proxy_host}:#{proxy_port}\n" end print "client to server: #{req}\n" client.syswrite(req) socks = [s, client] done = false while ! done; nsock = IO.select(socks) nsock.each { |ns| for sock in ns if sock == client begin $_ = client.sysread(65536) #print "server to client: #{$_}\n" if host =~ /2ch/ $_.gsub! /