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.
2 Answers
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.
-
2plz add this reference to your answer: github.com/ethereum/go-ethereum/wiki/Management-APIs Jul 18, 2016 at 17:28
Paste this line of code into the geth console to get a more concise version:
admin.peers.forEach(function(value){console.log(value.network.remoteAddress+"\t"+value.name)})
This will display something similar to this:
200.54.168.131:51340 Geth/v1.4.18-stable/linux/go1.6.2
85.145.173.31:42486 Geth/v1.5.4-stable/linux/go1.7.3
99.103.160.189:51995 Parity/v1.4.4-beta-a68d52c-20161118/x86_64-windows-msvc/rustc1.13.0
52.220.98.16:45621 Geth/v1.5.3-stable-978737f5/linux/go1.7
54.179.154.142:42875 Geth/v1.5.3-stable-978737f5/linux/go1.7
178.238.229.211:30303 Parity/v1.4.5-beta-a028d04-20161126/x86_64-linux-gnu/rustc1.13.0
79.207.229.221:60004 Geth/v1.5.3-stable-978737f5/windows/go1.7.3
139.59.245.223:33950 Parity/v1.5.0-unstable-0f76533-20161206/x86_64-linux-gnu/rustc1.12.0
50.50.229.47:50888 Geth/v1.5.4-stable-b70acf3c/linux/go1.7.3
50.171.254.76:13264 Parity/v1.4.4-beta-a68d52c-20161118/x86_64-windows-msvc/rustc1.13.0
88.7.47.217:59666 Geth/v1.5.3-stable-978737f5/linux/go1.7
13.79.154.168:23849 Ethereum(J)/v1.3.9/Linux/Release/Java/Dev
164.132.43.132:30303 Geth/v1.5.3-stable-978737f5/linux/go1.7.3
-
1