Parity:如何查看已連接的 Peers 替代“admin”關鍵字?
正如我們所知,我們不能使用
admin
,可以使用geth
, onParity
。例如,我想檢索
enode-id
每個連接的對等方的 ip 地址、使用的埠等資訊。
parity_netPeers
(https://github.com/paritytech/parity/wiki/JSONRPC-parity-module#parity_netpeers)返回一些沒有換行符的資訊,很難檢測到連接的對等方。
curl --data '{"method":"parity_netPeers","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545
例子:
這裡實際上有 2 個連接的對等點,但它返回更多資訊。
{"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
…`
安裝JQ,一個命令行 JSON 處理器。就像
sed
JSON 一樣。執行這個
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'
在單引號之後和之前添加以逗號開頭的鍵名,
.network
以將其他任何內容添加到輸出中。
您可以在 geth 控制台使用net.peerCount來獲取網路中目前存在的對等點的數量。 admin.peers是另一種獲取網路中對等點詳細資訊的方法。