How to parse the node information in the geth/nodes directory by leveldb?

485 views Asked by At

I want to get all the node IP addresses of ETH, so I need to parse the geth/nodes directory, but I can't find the specific data format and cannot parse it.

I found a same problem, but there is no solution: https://ethereum.stackexchange.com/questions/5999/format-of-leveldb-files-in-nodes-directory-trouble-pulling-contents-with-python

My code:

import leveldb
import rlp

db = leveldb.LevelDB("../nodes")
for k in db.RangeIter():
    print(k)
    print(rlp.decode(k[0]))
    break

Result:

(bytearray(b'local:\xc6\x83\x00\xb8LX\xcc+\xcd\x98CDd\x96\x89R\x92\x1a\xaeV\xe1\x93\xfeV\x95)\t~$e\xfa|:seq'), bytearray(b'\x97\x08'))
Traceback (most recent call last):
  File "temp.py", line 7, in <module>
    print(rlp.decode(k[0]))
  File "PATH/.local/lib/python3.6/site-packages/rlp/codec.py", line 235, in decode
    raise DecodingError(msg, rlp)
rlp.exceptions.DecodingError: RLP string ends with 41 superfluous bytes

I searched a lot of information and found that rlp.sedes needs to be specified when decoding. I can't determine which kind of sedes it is. I am a newcomer to ETH and I need help. Examples of parsing in other programming languages are also available.

Thank you.

0

There are 0 answers