Skip to content

Latest commit

 

History

History
105 lines (83 loc) · 2.49 KB

README.md

File metadata and controls

105 lines (83 loc) · 2.49 KB

local-proxy

Flow chart by Psuedo code

drawing

How to run

Check detail proxy setting here

cd src
python3 proxy.py 8080

How it works

Parsing for get “User-Agent” data

request_data_dict = {}

for line in request_data.decode().splitlines():
    try:
        title, content = line.split(": ")
        request_data_dict[title] = content
    except:
        pass

response_user_agent = request_data_dict['User-Agent']
end_index = response_user_agent.find(")")
cleaned_user_agent = response_user_agent[:end_index+1].replace("User-Agent: ", "")

Redirection to “mnet.Yonsei.ac.kr” when URL has “korea”

# Connect to the destination server
server_socket = None
response_data = None

try: 
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if url_filter == "O":
        destination_host = "mnet.yonsei.ac.kr"
    server_socket.connect((destination_host,  80))
except Exception as e:
    print("\nServer socket error: " + str(e))
    

server_socket.sendall(request_data)

Image Filtering
Log response through proxy
It logs also http status, content-type, content-length and send response_data to client
But It don’t send response_data when drop image

# Print log for the received response
print(f"[CLI <== PRX --- SRV]")

if image_filter == "O":
    if response_content.startswith("image"):
        print(f" > 404 Not Found")
    else:
        print(f" > {cleaned_status}")
        print(f" > {response_content} {response_bytes}bytes")
        client_socket.sendall(response_data)
else:
    print(f" > {cleaned_status}")
    print(f" > {response_content} {response_bytes}bytes")

    # Forward the modified response to the client
    client_socket.sendall(response_data)

Snapshots

Mac proxy server setup

drawing

Image filtering

Image filtering at test page

drawing

Redirection

Redirection from Korea univ page to Yonsei univ page

drawing

Image filtering with Redirection

drawing

Environment

OS: Mac Sonoma
Language: Python(3.8.5)