Skip to content

Instantly share code, notes, and snippets.

@alecmuffett
Created February 12, 2017 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecmuffett/5bcda6ed8805ede8ba017012182652c4 to your computer and use it in GitHub Desktop.
Save alecmuffett/5bcda6ed8805ede8ba017012182652c4 to your computer and use it in GitHub Desktop.
ls-hsdir.py
#!/usr/bin/env python
import sys
import stem
import datetime
from time import gmtime, strftime
from stem.control import Controller
now = datetime.datetime.utcnow()
now2 = now.strftime('%Y-%m-%d %H:%M:%S')
def print_hsdir(controller, name):
try:
x = controller.get_hidden_service_descriptor(name)
except stem.DescriptorUnavailable:
print "# unavailable", name
return
ips = sorted([ "%s:%d" % (ip.address, ip.port) for ip in x.introduction_points()])
age = now - x.published
print "v=%d age=%d nip=%d pub(%s) now(%s) %s" % (
x.version,
age.total_seconds(),
len(ips),
x.published,
now2,
name
)
i = 0
for ip in ips:
print "\t%d: %s" % (i, ip)
i = i + 1
with Controller.from_port(port = 9151) as controller:
controller.authenticate()
for name in sys.argv[1:]:
if name.endswith('.onion'):
name = name[0:-6]
print_hsdir(controller, name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment