[Ethereum] Get a peer list for the geth node

go-ethereumnodesweb3js

How can I use Geth (or any other client) to get a list of my peer nodes on the Ethereum network. I see there's a function to get the number of nodes using the web3 api, but I need a list of node IDs or IPs.

Best Answer

Use admin.peers to get a list of the currently connected peers:

> admin.peers
[{
    caps: ["eth/61", "eth/62", "eth/63"],
    id: "3f8f61999252251808972871bc810505d5b33f7de761c98810584279dce9ecabb0b7da0836978e6074f48e2b787048739c9dc1f734403c8adafc0716d16f4dcd",
    name: "Geth/v1.3.5-34b622a2/linux/go1.6",
    network: {
      localAddress: "192.168.0.105:49356",
      remoteAddress: "73.217.192.86:30303"
    },
    protocols: {
      eth: {
        difficulty: 10197633442299193000,
        head: "8f2c1a08cfc80eff8e2aa601254d6f094e0e801b2e4f0bf2aefffaead93daa41",
        version: 63
      }
    }
}, {
    caps: ["eth/61", "eth/62", "eth/63"],
    id: "cae433c8f8890998f9a8694fae57e480ae1b65b40de1d0f6e823941c9d7ce1adae10c00772358e543487bf3b77a4ef9a34dd352b5ab085629df898071f42b8c6",
    name: "Geth/v1.4.0-unstable/linux/go1.5.1",
    network: {
      localAddress: "192.168.0.105:49340",
      remoteAddress: "122.114.96.120:30303"
    },
    protocols: {
      eth: {
        difficulty: 10197633442299193000,
        head: "4269eb623e002975e9b097c936d004cdbb6fc4c0527c3ff824d257fc2c472b64",
        version: 63
      }
    }
}]

This admin.peers property and other management APIs are documented on the go-ethereum wiki.

Related Topic