7

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.

1
  • 1
    Instead of hacking the source a simple patch may do. The RPC server is a bit thin after all.
    – Lodewijk
    May 4, 2012 at 18:40

2 Answers 2

5

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

3

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/"$//'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.