Skip to content

Instantly share code, notes, and snippets.

@sochotnicky
Last active September 1, 2021 14:33
Show Gist options
  • Select an option

  • Save sochotnicky/8a0a1a47aaa4489ced77df63f6b554c0 to your computer and use it in GitHub Desktop.

Select an option

Save sochotnicky/8a0a1a47aaa4489ced77df63f6b554c0 to your computer and use it in GitHub Desktop.
test_nft.py
#!/usr/bin/python3
# Needs following to be run first:
# nft -f /usr/share/nftables/ipv4-filter.nft
data = {
"nftables": [
{"metainfo": {"json_schema_version": 1}},
{
"add": {
"rule": {
"family": "ip",
"table": "filter",
"chain": "input",
"expr": [
{
"match": {
"op": "==",
"left": {
"payload": {"protocol": "udp", "field": "dport"}
},
"right": 50000,
}
}
],
}
}
},
]
}
import nftables
n = nftables.Nftables()
n.set_handle_output(True)
n.set_echo_output(True)
print(n.json_cmd(data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment