-
Notifications
You must be signed in to change notification settings - Fork 6
/
lookupFallbackDirContact.py
executable file
·51 lines (41 loc) · 1.46 KB
/
lookupFallbackDirContact.py
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
#!/usr/bin/env python
# Lookup fallback directory contact lines for every fingerprint passed as an
# argument.
#
# Usage:
# lookupFallbackDirContact.py fingerprint ...
# Future imports for Python 2.7, mandatory in 3.0
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import sys
import stem.descriptor.remote as remote
import stem.util.tor_tools as tor_tools
if len(sys.argv) <= 1:
print("Usage: {} fingerprint ...".format(sys.argv[0]))
sys.exit(1)
input_list = sys.argv[1:]
for fingerprint in input_list:
if not tor_tools.is_valid_fingerprint(fingerprint):
print("'%s' isn't a valid relay fingerprint" % fingerprint)
sys.exit(2)
found_list = []
# we need descriptors, because the consensus does not have contact infos
desc_query = remote.get_server_descriptors(input_list,
retries=3,
timeout=30)
for desc in desc_query.run():
assert desc.fingerprint in input_list
# Skip duplicates on retries
if desc.fingerprint in found_list:
continue
found_list.append(desc.fingerprint)
if desc.contact:
# Most ContactInfos should be UTF-8
contact = desc.contact.decode(encoding="utf-8", errors="replace")
else:
contact = "(no contact)"
print("{} {}".format(desc.fingerprint, contact))
for fingerprint in input_list:
if fingerprint not in found_list:
print("{} (descriptor not found)".format(fingerprint))