<p>The easiest way to get peer information is via the JSON RPC interface has a command getpeerinfo.  Each peer returns a JSON object containing peer IP address info, connection time, version and subversion of the client.  </p>

<p>You would probably be interested in this: <a href="https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list" rel="nofollow">Bitcoind API</a> </p>

<p>Edit: Although this is not a way to read the database I presume that the data feeding the peers.dat file is pulled from both the IRC channels and the DNS seeds.  If you reported data on those nodes, you could use this data in combination with logs from the debug file to perhaps learn how your node discovered its peers.</p>

CC BY-SA 3.0
2013-12-30T03:07:45.457Z
Thanks, but that only lists the 8 peers I'm connected to.  I know that peers.dat contains a lot more data than that because:
1) it's rather large file (almost 1MB)
2) I see messages like the following in the debug.log:
"2013-12-30 03:05:34 Added 1 addresses from xxx.xxx.xxx.xxx: 62 tried, 14738 new"
Konstantin
CC BY-SA 3.0
2013-12-30T03:12:54.423Z
"peers.dat is a flat file with a bitcoin-specific file format, unrelated to any database system." https://bitcointalk.org/index.php?topic=119525.msg1287284#msg1287284 looks like unless there's another implementation of it you would have to attempt to rebuild the code in the language you require.
Mark S.
CC BY-SA 3.0
2013-12-30T04:02:47.747Z
I also found this: [Bitnodes](https://github.com/ayeowch/bitnodes).  I will investigate his code and learn from it.  Thanks!
Konstantin
CC BY-SA 3.0
2013-12-30T03:03:29.683Z
2013-12-30T03:24:24.393Z
2013-12-30T03:24:24.393Z
Mark S.
<p>In version 0.8.6 of Bitcoin, I see that peers.dat file is a custom database format declared in db.h:317 (class CAddrDB) and defined in dh.cpp:485. Any ideas on how I could go about reading the data from peers.dat with PHP or Python? I'd like to keep track of all peers that the bitcoin daemon sees and connects to.  Or is there a better way?</p>

<bitcoind><raw-data><peers>
How do I read peers.dat file to get a list of all peers seen or that bitcoind has connected to?
Konstantin
# How do I read peers.dat file to get a list of all peers seen or that bitcoind has connected to?

(Asked by: username_0 on 2013-12-30)

In version 0.8.6 of Bitcoin, I see that peers.dat file is a custom database format declared in db.h:317 (class CAddrDB) and defined in dh.cpp:485. Any ideas on how I could go about reading the data from peers.dat with PHP or Python? I'd like to keep track of all peers that the bitcoin daemon sees and connects to. Or is there a better way?

**Tags:** bitcoind, raw-data, peers


---

## 1 answers

### Answer by username_1 on 2013-12-30. Score: 3

The easiest way to get peer information is via the JSON RPC interface has a command getpeerinfo. Each peer returns a JSON object containing peer IP address info, connection time, version and subversion of the client.

You would probably be interested in this: [Bitcoind API](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list)

Edit: Although this is not a way to read the database I presume that the data feeding the peers.dat file is pulled from both the IRC channels and the DNS seeds. If you reported data on those nodes, you could use this data in combination with logs from the debug file to perhaps learn how your node discovered its peers.

> **Comments:**
> **username_0**: Thanks, but that only lists the 8 peers I'm connected to.  I know that peers.dat contains a lot more data than that because: 1) it's rather large file (almost 1MB) 2) I see messages like the following in the debug.log: "2013-12-30 03:05:34 Added 1 addresses from xxx.xxx.xxx.xxx: 62 tried, 14738 new"  
> **username_1**: "peers.dat is a flat file with a bitcoin-specific file format, unrelated to any database system." https://bitcointalk.org/index.php?topic=119525.msg1287284#msg1287284 looks like unless there's another implementation of it you would have to attempt to rebuild the code in the language you require.  
> **username_0**: I also found this: [Bitnodes](https://github.com/ayeowch/bitnodes).  I will investigate his code and learn from it.  Thanks!  

---

