Ticket #32314: test-connect.py

File test-connect.py, 784 bytes (added by liberat, 3 months ago)

Script demonstrating various SOCKS5 connection requests

Line 
1#!/usr/bin/python3
2
3import socket
4
5tor_addr = ('127.0.0.1', 9150)
6
7def test_connect(name=None, addr=None):
8    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9    s.connect(tor_addr)
10    s.send(b'\x05\x01\x00')
11    s.recv(50)
12    if name:
13        print('Testing name=%r:' % (name,))
14        s.send(b'\x05\x01\x00\x03' + bytes([len(name)]) + name + b'\x00\x50')
15    else:
16        print('Testing addr=%x:' % (addr,))
17        s.send(b'\x05\x01\x00\x04' + addr.to_bytes(16, 'big') + b'\x00\x50')
18    print(s.recv(50))
19    s.send(b'HEAD / HTTP/1.0\r\n\r\n')
20    print(s.recv(15))
21
22test_connect(addr=0x2a00145040010800000000000000200e)
23test_connect(name=b'[2a00:1450:4001:800::200e]')
24test_connect(name=b'2a00:1450:4001:800:0:0:0:200e')
25test_connect(name=b'2a00:1450:4001:800::200e')