Skip to content

trio-socks provides a trio.abc.HalfCloseableStream that routes its traffic through a SOCKS proxy server

Notifications You must be signed in to change notification settings

Ostoic/trio-socks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT PyPi Version

trio-socks

trio-socks is a simple trio.abc.HalfCloseableStream that routes its traffic through a SOCKS proxy server

Example

import trio
from trio_socks import socks5

async def parse_public_ip(stream):
	await stream.send_all('GET / HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n'.encode())
	text = (await stream.receive_some()).decode()
	i = text.rfind('\r\n\r\n')
	my_ip = text[i + 4:]
	print(f'{my_ip=}')

async def print_public_ip():
	async with socks5.Socks5Stream(destination=('api.ipify.org', 80), proxy=('10.179.205.114', 1664)) as stream:
		await parse_public_ip(stream)

	async with await trio.open_tcp_stream('api.ipify.org', 80) as stream:
		await parse_public_ip(stream)

trio.run(print_public_ip)

Output:

my_ip='132.202.81.51'
my_ip='91.143.60.163'

About

trio-socks provides a trio.abc.HalfCloseableStream that routes its traffic through a SOCKS proxy server

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages