Onionr/scripts/generate-onions.py

41 lines
957 B
Python
Raw Permalink Normal View History

2020-10-24 16:50:25 +00:00
#!/usr/bin/env python3
import sys
import os
import stem
from stem import process
from stem.control import Controller
if not os.path.exists('onionr.sh'):
os.chdir('../')
sys.path.append("src/")
2020-10-25 04:12:42 +00:00
try:
sys.argv[1]
except IndexError:
sys.exit(1)
2020-10-24 16:50:25 +00:00
tor_process = process.launch_tor_with_config(
completion_percent=0,
config = {
'ControlPort': '2778',
'DisableNetwork': '1',
'Log': [
'NOTICE stdout',
'ERR file /tmp/tor_error_log',
],
},
)
with Controller.from_port('127.0.0.1', 2778) as controller:
controller.authenticate()
2020-10-25 04:12:42 +00:00
for i in range(1024, 1024 + int(sys.argv[1])):
2020-10-24 16:50:25 +00:00
hs = controller.create_ephemeral_hidden_service(
{80: i},
key_type='NEW',
key_content='ED25519-V3',
await_publication=False,
detached=True)
2020-10-25 04:12:42 +00:00
print(hs.service_id + ".onion")
controller.remove_ephemeral_hidden_service(hs.service_id)
2020-10-24 16:50:25 +00:00
tor_process.kill()