Created
September 11, 2013 01:56
-
-
Save thefinn93/6518460 to your computer and use it in GitHub Desktop.
List cjdns peers connected.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import subprocess | |
try: | |
import cjdnsadmin | |
except: | |
print "Failed to find cjdnsadmin in the normal search path. Hax in progress..." | |
sys.path.append("/opt/cjdns/contrib/python/cjdnsadmin") | |
try: | |
import cjdnsadmin | |
except: | |
print "Failed to import cjdnsadmin!" | |
sys.exit(1) | |
searchfor = None | |
if len(sys.argv) > 1: | |
searchfor = sys.argv[1] | |
def publictoip6(pubkey): | |
proc = subprocess.Popen(["/opt/cjdns/build/publictoip6", pubkey], stdout=subprocess.PIPE) | |
proc.wait() | |
return proc.stdout.read().strip() | |
cjdns = cjdnsadmin.connectWithAdminInfo() | |
peers = {} | |
i = 0 | |
more = True | |
while more: | |
data = cjdns.InterfaceController_peerStats(i) | |
more = "more" in data | |
i += 1 | |
for peer in data['peers']: | |
peers[peer['publicKey']] = None | |
if "user" in peer: | |
peers[peer['publicKey']] = peer['user'] | |
if peer['publicKey'] == searchfor: | |
more = False | |
if searchfor is None: | |
for pubkey in peers: | |
print "%s\t%s\t%s" % (pubkey, publictoip6(pubkey), peers[pubkey]) | |
else: | |
if searchfor in peers: | |
print "%s\t%s\t%s" % (searchfor, publictoip6(searchfor), peers[searchfor]) | |
else: | |
print "Failed to find %s" % searchfor | |
sys.exit(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment