Created
June 15, 2017 20:13
-
-
Save laanwj/27241686db0db712cd94f692a491ad78 to your computer and use it in GitHub Desktop.
Count statistics about connections for bitcoind RPC
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/local/bin/python3 [5/1819] | |
import sys | |
sys.path.append('./bitcoin/test/functional') | |
from test_framework.authproxy import AuthServiceProxy, JSONRPCException | |
import time | |
import os | |
datadir = os.path.join(os.getenv('HOME'), '.bitcoin') | |
with open(os.path.join(datadir,'.cookie'),'r') as f: | |
cookie = f.read() | |
tgt = "http://%s@127.0.0.1:8332/" % (cookie) | |
proxy = AuthServiceProxy(tgt) | |
out = sys.stdout # stream to write to | |
while True: | |
now = time.time() | |
peers = proxy.getpeerinfo() | |
in_ipv4 = 0 | |
in_ipv6 = 0 | |
in_tor = 0 | |
out_ipv4 = 0 | |
out_ipv6 = 0 | |
out_tor = 0 | |
for peer in peers: | |
addr = peer['addr'] | |
if peer['inbound']: | |
if addr.startswith('['): | |
in_ipv6 += 1 | |
elif addr.startswith('127.0.0.1:'): | |
in_tor += 1 | |
else: | |
in_ipv4 += 1 | |
else: | |
if addr.startswith('['): | |
out_ipv6 += 1 | |
elif '.onion' in addr: | |
out_tor += 1 | |
else: | |
out_ipv4 += 1 | |
print('[by network]') | |
print('in: ipv4 %3d ipv6 %3d tor %3d' % (in_ipv4, in_ipv6, in_tor)) | |
print('out: ipv4 %3d ipv6 %3d tor %3d' % (out_ipv4, out_ipv6, out_tor)) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment