v6d3music/v6d3music/utils/tor_prefix.py
2022-11-11 13:27:58 +00:00

25 lines
575 B
Python

__all__ = ('tor_prefix',)
import os
if (address := os.getenv('v6tor', None)) is not None:
print('tor through torsocks')
try:
import socket
address = socket.gethostbyname_ex(address)[2][0]
except:
print('failed tor resolution')
_tor_prefix = None
else:
print('tor successfully resolved')
_tor_prefix = ['torsocks', '--address', address]
else:
print('tor unavailable')
_tor_prefix = None
def tor_prefix():
if _tor_prefix is None:
raise ValueError('tor unavailable')
return _tor_prefix