Looking for a better way of listing all my peers

5

1

I am looking for a cheap and efficient way (rather than hacking through the Bitcoin source code) of listing my peers.

Something I have come up with:

#!/bin/bash

netstat -p tcp -nba | grep  '.8333.*ESTABLISHED' | perl -npe 's/.*\s+((\d+.){3}\d+)\.\d+\s+ESTABLISHED.*/$1/'

The script above generates a list of IPs.

Ning

Posted 2012-05-04T15:18:13.473

Reputation: 2 171

1Instead of hacking the source a simple patch may do. The RPC server is a bit thin after all.Lodewijk 2012-05-04T18:40:53.460

Answers

2

First, setup add the following to your bitcoin.conf to enable RPC (of course, you can use other values):

rpcuser=user 
rpcpassword=Pa55w0rd
rpcport=8333
server=1

After that, restart bitcoin and use following command to get IPs of all peers connected (you can probably make the parser part shorter by using perl instead of grep/sed):

USER=user
PASSWORD=Pa55w0rd
PORT=8333
curl --user $USER:$PASSWORD --data-binary \
'{"jsonrpc": "1.0", "id":"curltest", "method": "getpeerinfo", "params": [] }' \
-H 'content-type: text/plain;' http://127.0.0.1:$PORT/ 2>/dev/null \
| grep -o '"addr":"[^"]\+"' | cut -d":" -f2-3 | sed 's/^"//;s/"$//'

aland

Posted 2012-05-04T15:18:13.473

Reputation: 1 338

2

Use the getpeerinfo RPC command (available since v0.7.0).

Pieter Wuille

Posted 2012-05-04T15:18:13.473

Reputation: 54 032