<p>Use the <code>getpeerinfo</code> RPC command (available since v0.7.0).</p>

CC BY-SA 3.0
2012-12-13T19:01:01.950Z
2012-12-13T19:01:01.950Z
Pieter Wuille
<p>First, setup add the following to your <code>bitcoin.conf</code> to enable RPC (of course, you can use other values):</p>

<pre><code>rpcuser=user 
rpcpassword=Pa55w0rd
rpcport=8333
server=1
</code></pre>

<p>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):</p>

<pre><code>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&gt;/dev/null \
| grep -o '"addr":"[^"]\+"' | cut -d":" -f2-3 | sed 's/^"//;s/"$//'
</code></pre>

CC BY-SA 3.0
2012-12-12T12:25:57.323Z
2012-12-12T12:25:57.323Z
aland
<p>I am looking for a cheap and efficient way (rather than hacking through the Bitcoin source code) of listing my peers.</p>

<p>Something I have come up with:</p>

<pre><code>#!/bin/bash

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

<p>The script above generates a list of IPs.</p>

CC BY-SA 3.0
2012-05-04T18:40:53.460Z
Instead of hacking the source a simple patch may do. The RPC server is a bit thin after all.
Lodewijk
<network><peers>
Looking for a better way of listing all my peers
Ning
# Looking for a better way of listing all my peers

(Asked by: username_0 on 2012-05-04)

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.

**Tags:** network, peers

> **Comments:**
> **username_1**: Instead of hacking the source a simple patch may do. The RPC server is a bit thin after all.  

---

## 2 answers

### Answer by username_2 on 2012-12-13. Score: 5

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


---

### Answer by username_3 on 2012-12-12. Score: 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/"$//'

```


---

