import socket
# SOCKS5 constants
SOCKS_VERSION = 5
SOCKS_CMD_CONNECT = 1
SOCKS_ATYP_DOMAIN = 3
# 요약: socket을 열고 그 소켓을 프록시가 맺어지고 이 프록시를 통해 HTTP 통신을 한다는 점이다.
def socks5_connect(proxy_host, proxy_port, target_host, target_port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((proxy_host, proxy_port))
# Step 1: Greeting
s.sendall(bytes([SOCKS_VERSION, 1, 0x00])) # No authentication
# Step 2: Server chooses auth method
version, method = s.recv(2)
if method != 0x00:
raise Exception("Proxy requires unsupported authentication")
# Step 3: CONNECT request
domain = target_host.encode()
req = bytes([
SOCKS_VERSION,
SOCKS_CMD_CONNECT,
0x00, # reserved
SOCKS_ATYP_DOMAIN,
len(domain)
]) + domain + target_port.to_bytes(2, 'big')
s.sendall(req)
# Step 4: Server response
response = s.recv(10)
if response[1] != 0x00:
raise Exception(f"Connection failed, error code: {response[1]}")
print("Connection through SOCKS5 proxy established!")
return s
# 예시: 프록시를 통해 example.com의 80포트에 접속
proxy_sock = socks5_connect("127.0.0.1", 1080, "example.com", 80)
proxy_sock.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
print(proxy_sock.recv(4096).decode())

| 프로토콜 | 보안성 | 속도 | 호환성 | 설정 용이성 | 모바일 친화성 |
|---|---|---|---|---|---|
| OpenVPN | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ |
| WireGuard | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| IKEv2/IPSec | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| L2TP/IPSec | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐ |
| SSTP | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
VPN 선택 기준 (이론 중심)
사실 VPN은 일반적인 상황이라면 surfshark, nordvpn 과 같은 업체망을 활용하는게 가장 빠르고 비용 효율적이긴 하다.

공유기는 대부분 VPN을 지원함
