Wiki
Clone wikiaiengine / TorNetworkPython
IP activity
On this example we will see how IPSets and IPBloomSets works, we will try to detect Tor activity on the network by providing a list of IP addresses to the engine.
import pyaiengine
def callback(flow): print("Detecting ToR on ", str(flow))
def loadTorIPs(): ipset_mng = pyaiengine.IPSetManager()
ipset = pyaiengine.IPSet() ipset.callback = callback
""" Take a big list of IP address that belongs to ToR """ req = urllib2.Request("https://www.dan.me.uk/torlist/") try: response = urllib2.urlopen(req) for line in response.readlines(): ip = line.strip() try: socket.inet_aton(ip) except: continue ipset.add_ip_address(ip) except urllib2.URLError as e: print("Error:",e)
ipset_mng.add_ip_set(ipset) return ipset_mng
if __name__ == '__main__': st = pyaiengine.StackLan()
st.tcp_flows = 1638400
st.tcp_ip_set_manager = loadTorIPs()
with pyaiengine.PacketDispatcher("re0") as pd: pd.stack = st pd.run()
Updated