-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwo_hop_vpn.py
More file actions
66 lines (50 loc) · 2.01 KB
/
Copy pathtwo_hop_vpn.py
File metadata and controls
66 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from anyone_protocol_sdk import Control, Process, Config, Socks, StreamStatus, Flag, EventType, Stream
print("Starting Anon...")
# Create a configuration
config = Config(
auto_terms_agreement=True,
display_log=False
)
# Initialize and start the runner
anon = Process.launch_anon(anonrc_path=config.to_file())
control = Control.from_port()
socks = Socks()
try:
print("Connecting to Control Port...")
control.authenticate()
relays = control.get_relays()
print("Total Relays:", len(relays))
nl_relays = control.filter_relays_by_countries(relays, "de")
exit_relays = control.filter_relays_by_flags(nl_relays, Flag.Exit)
exit = exit_relays[0].fingerprint
print("Exit Relay:", exit)
guard_relays = control.filter_relays_by_flags(nl_relays, Flag.Guard)
guard = guard_relays[0].fingerprint
print("Guard Relay:", guard)
print("Creating a new circuit through specified relays")
path = [guard, exit]
circuit_id = control.new_circuit(path=path, await_build=True)
print(f"New circuit created with ID: {circuit_id}")
circuit = control.get_circuit(circuit_id)
print(f"Created circuit. ID: {circuit.id}, Path: {circuit.path}")
control.disable_stream_attachment()
print("Stream attachment disabled.")
def attach_stream(stream: Stream):
print(f"Stream status: {stream.status}. Purpose: {stream.purpose}")
if stream.status == StreamStatus.NEW:
control.attach_stream(stream.id, circuit_id)
control.add_event_listener(attach_stream, EventType.STREAM)
print("Stream listener added.")
print("Executing a new get request...")
resp = socks.get("http://ip-api.com/json")
print(resp.text)
control.remove_event_listener(attach_stream)
print("Stream listener removed.")
print("Closing the manual circuit...")
control.close_circuit(circuit_id)
print(f"Manual circuit {circuit_id} closed successfully.")
finally:
control.close()
print("Controller connection closed.")
print("Stopping Anon...")
anon.stop()