pyroute2
pyroute2 copied to clipboard
Parse conntrack updates to structure NFCTAttrTuple or dicrinary
Is there any way to parse conntrack netlink updates to the NFCTAttrTuple, JSON or dictionary?
#!/usr/bin/env python3
from pyroute2.netlink import nfnetlink
from pyroute2 import conntrack
ct = conntrack.Conntrack()
ct.bind()
ct.add_membership(nfnetlink.NFNLGRP_CONNTRACK_NEW)
while True:
data = ct.recv(4096)
if data:
print(data)
We get:
# ./tmp3.py
b'\xa4\x00\x00\x00\x00\x01\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00<\x00\x01\x80\x14\x00\x01\x80\x08\x00\x01\x00d@\x00\x01\x08\x00\x02\x00\x01\x01\x01\x01$\x00\x02\x80\x05\x00\x01\x00\x01\x00\x00\x00\x06\x00\x04\x00\x1cn\x00\x00\x05\x00\x05\x00\x08\x00\x00\x00\x05\x00\x06\x00\x00\x00\x00\x00<\x00\x02\x80\x14\x00\x01\x80\x08\x00\x01\x00\x01\x01\x01\x01\x08\x00\x02\x00\xc0\xa8z\xde$\x00\x02\x80\x05\x00\x01\x00\x01\x00\x00\x00\x06\x00\x04\x00\x0f0\x00\x00\x05\x00\x05\x00\x00\x00\x00\x00\x05\x00\x06\x00\x00\x00\x00\x00\x08\x00\x0c\x00\xfa\xdb!\x83\x08\x00\x03\x00\x00\x00\x01\x98\x08\x00\x07\x00\x00\x00\x00\x1e'
Is there any native tool to parse/extract this data from the hex? To get the Source Address, Destination Address, sport, dport, translation address/port, protocol