<p>To my knowledge, there is currently no way to do this, so I wrote one.</p>

<p>The details of decoding peers.dat are described in my blog post <a href="https://raghavsood.com/blog//2018/05/20/demystifying-peers-dat" rel="noreferrer">Demystifying Bitcoin's peers.dat</a>.</p>

<p>The result of that is an open source tool written in go that can read all peer info from peers.dat. As always, one should review the code before running this on any machine that hold a wallet. The tool should be able to work with any Bitcoin-based altcoin as well. I have tested it against Bitcoin, Litecoin, and Dogecoin <code>peers.dat</code>s.</p>

<p>Installing <code>bitpeers</code> is quite simple, provided you have go installed, and your <code>GOPATH</code> set up. If not, go has a <a href="https://golang.org/doc/install" rel="noreferrer">handy getting started guide</a> which you can use to fix that.</p>

<p>Once go is set up, simply run</p>

<pre><code>go get -u github.com/RaghavSood/bitpeers/cmd/bitpeers
</code></pre>

<p>If your go environment is set up properly, you should now have a <code>bitpeers</code> command available. If not, try finding your <code>GOBIN</code> (<code>GOPATH/bin</code>) and adding it to your <code>PATH</code>.</p>

<p><code>bitpeers</code> to easily dump <code>peers.dat</code> addresses as either human-readable plaintext or JSON. It accepts three flags:</p>

<pre><code>Usage of bitpeers:
      --addressonly       outputs only addresses if specified
      --filepath string   the path to peers.dat
      --format string     the output format {json|text} (default "json")
</code></pre>

<p>Running <code>bitpeers --filepath /mnt/doge/.dogecoin/peers.dat --addressonly</code> will produce a JSON array of all the IPs and ports in <code>peers.dat</code>. You can also pass the <code>--format text</code> option to produce a list of all IPs and ports, one IP:port per line.</p>

<p>Running without the <code>--addressonly</code> option will produce the full JSON/text output, which contains the following:</p>

<pre><code>$ bitpeers --filepath ./peers.dat --format text
SerializationVersion: 34fc0100
Time: 1526192792
ServiceFlags: 0x000000000000000d
IP: 42.5.143.180:8333
Source: 8.8.8.8
LastSuccess: 1526746622
Attempts: 0
</code></pre>

<p>If you happen to find any inconsistencies or issues with the parser or output, please open an issue on the <a href="https://github.com/RaghavSood/bitpeers" rel="noreferrer">GitHub repo</a>.</p>

CC BY-SA 4.0
2018-05-20T01:55:26.423Z
2018-05-20T01:55:26.423Z
Raghav Sood
<p>Is there a simple solution to dump [<strong>whole</strong>] peers.dat file to a text file?</p>

<p>There are similar questions for example <a href="https://bitcoin.stackexchange.com/questions/19586">How do I read peers.dat file to get a list of all peers seen or that bitcoind has connected to?</a> but I want to insert this code in Bitcoin Core Client (in fact: forked client) and dump the contents of this database on client start.</p>

<p>bitnodes.earn.com is not an answer for me.</p>

<client>
How to dump peers.dat file to a plain text file?
amaclin
# How to dump peers.dat file to a plain text file?

(Asked by: username_0 on 2018-05-19)

Is there a simple solution to dump [**whole**] peers.dat file to a text file?

There are similar questions for example [How do I read peers.dat file to get a list of all peers seen or that bitcoind has connected to?](https://bitcoin.stackexchange.com/questions/19586) but I want to insert this code in Bitcoin Core Client (in fact: forked client) and dump the contents of this database on client start.

bitnodes.earn.com is not an answer for me.

**Tags:** client


---

## 1 answers

### Answer by username_1 on 2018-05-20. Score: 8 | Accepted answer

To my knowledge, there is currently no way to do this, so I wrote one.

The details of decoding peers.dat are described in my blog post [Demystifying Bitcoin's peers.dat](https://username_1.com/blog//2018/05/20/demystifying-peers-dat).

The result of that is an open source tool written in go that can read all peer info from peers.dat. As always, one should review the code before running this on any machine that hold a wallet. The tool should be able to work with any Bitcoin-based altcoin as well. I have tested it against Bitcoin, Litecoin, and Dogecoin `peers.dat`s.

Installing `bitpeers` is quite simple, provided you have go installed, and your `GOPATH` set up. If not, go has a [handy getting started guide](https://golang.org/doc/install) which you can use to fix that.

Once go is set up, simply run

```
go get -u github.com/username_1/bitpeers/cmd/bitpeers

```

If your go environment is set up properly, you should now have a `bitpeers` command available. If not, try finding your `GOBIN` (`GOPATH/bin`) and adding it to your `PATH`.

`bitpeers` to easily dump `peers.dat` addresses as either human-readable plaintext or JSON. It accepts three flags:

```
Usage of bitpeers:
      --addressonly       outputs only addresses if specified
      --filepath string   the path to peers.dat
      --format string     the output format {json|text} (default "json")

```

Running `bitpeers --filepath /mnt/doge/.dogecoin/peers.dat --addressonly` will produce a JSON array of all the IPs and ports in `peers.dat`. You can also pass the `--format text` option to produce a list of all IPs and ports, one IP:port per line.

Running without the `--addressonly` option will produce the full JSON/text output, which contains the following:

```
$ bitpeers --filepath ./peers.dat --format text
SerializationVersion: 34fc0100
Time: 1526192792
ServiceFlags: 0x000000000000000d
IP: 42.5.143.180:8333
Source: 8.8.8.8
LastSuccess: 1526746622
Attempts: 0

```

If you happen to find any inconsistencies or issues with the parser or output, please open an issue on the [GitHub repo](https://github.com/username_1/bitpeers).


---

