Torset is an application I wrote 5 years ago in C++.
It parses a tor microdescriptor file, extracting ip adresses and ports to generate an ipset or an nftables variable allowing you to filter traffic based on whether it goes to/comes from a tor node or not.
I use it to make firewall rules assuring that programs on my system that I want to proxy through tor cannot leak anything to other networks.
It also allows conditional redirection to tor to make a transparent proxy, avoiding double torifying for applications that already use tor.
Torset is a native application so you don’t have to install stem (python) on small routers for limiting dependencies and improving performance.
It can be found at: https://github.com/najamelan/torset