alext234 / rpc-sniffer

Capture and decode (Ethereum) JSON RPC traffic
MIT License
6 stars 0 forks source link
blockchain ethereum jsonrpc network python sniffing

Build Status

rpc-sniffer

This tool captures network traffic and decode them if they contain (Ethereum) JSON RPC. This might be useful in the following scenarios:

Installation

The following assumes you already have Python virtualenv activated. If not you may need to add sudo in front of the setup.py command.

(activate python virtualenv)
git clone https://github.com/alext234/rpc-sniffer
cd rpc-sniffer
python setup.py install

Usage

A pcap file can be given as the parameter:

> rpc-sniffer.py  tests/data/web3_clientVersion.pcap 
INFO:root:Sniff network packets and decode JSONRPC on HTTP
id        method                        params                                  result                                  
1         web3_clientVersion            []                                      
1                                                                               Geth/v1.8.2-stable/linux-amd64/go1.9.2  

Or a network interface can be given, for example with the local loopback interface lo (superuser is needed):

> sudo su

> (activate python virtualenv)

> rpc-sniffer.py lo

You will able to see the decoded traffic when you interact with a local RPC node via web3, for example.

id        method                        params                                  result                                  
1         eth_accounts                  []                                      
1         eth_getTransactionCount       ['0x70974f6673fa922eac3c2cd433d762e93db9399e', 'latest']
1                                                                               0x30                                    
1         net_version                   []                                      
1                                                                               99                                      
1         eth_gasPrice                  []                                      
1                                                                               0x430e23400                             

Limitations