[Ethereum] Parity: How to view connected Peers alternative to ‘admin’ keyword

parity

As we know we cannot use admin, which works on geth, on Parity.

For example I want to retrieve information such as enode-id, ip-address, used port of each connected peer.

parity_netPeers (https://github.com/paritytech/parity/wiki/JSONRPC-parity-module#parity_netpeers) returns some information without newline, it become difficult see detect the peers connected.

curl --data '{"method":"parity_netPeers","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545

Example:

Here there is actually 2 connected peers but it returns many more information.

{"jsonrpc":"2.0","result":{"active":2,"connected":2,"max":25,"peers":[{"caps":[],"id":"575bbc154d3c37c35d5f91a42813641fef4389bc288c0e50cf2ab1cbbde014287b93d3748336ff02c99a11e7d58ab54868933c7a9804c36a071078cb9a586ca8","name":"","network":{"localAddress":"77.23.7.15:39741","remoteAddress":"Handshake"},"protocols":{"eth":null,"les":null}},{"caps":["eth/63","eth/62"],"id":"4d331051d8fb471c87a9351b36ffb72bf445a9337727d229e03c668f99897264bf11e1b897b1561f5889825e2211b06858139fa469fdf73c64d43a567ea72479","name":"Geth/v1.5.9-stable-a07539fb/linux/go1.7.1","network":{"localAddress":"77.13.17.145:35507","remoteAddress":"13.40.17.95:3000"},"protocols":{"eth":{"difficulty":null,"head":"3060e08b5cd0b90adb3c464342f6df13482361e8ef09724d7525cae48abbaf59","version":63},"les":null}},{"caps":[],"id":"13d6cc66f445072d2e389c5d47d1557543ec9f96237576a38072a5b76b67ba445050641219e1f42c1443a7287fab6cb3f4c078fa886520cbf3577ac23f5e0cad","name":"","network":{"localAddress":"77.13.17.15:44079","remoteAddress":"Handshake"},"protocols":{"eth":null,"les":null}},{"caps":[],"id":null,"name":"","network":{"lo
…`

Best Answer

Install JQ, a command-line JSON processor. It's like sed for JSON.

Run this

curl -s --data '{"method":"parity_netPeers","params":[],"id":1,"jsonrpc":"2.0"}' \
-H "Content-Type: application/json" -X POST localhost:8545 \
| jq '.result.peers[] | .id, .network'

Add the name of the key preceded by a comma after .network and before the single quote to add anything else to the output.

Related Topic