Skip to content

Instantly share code, notes, and snippets.

@jonmarty
Created June 18, 2018 01:16
Show Gist options
  • Save jonmarty/ce6aa674e57a50e0b403100fa610398d to your computer and use it in GitHub Desktop.
Save jonmarty/ce6aa674e57a50e0b403100fa610398d to your computer and use it in GitHub Desktop.
Code to continuously monitor the network for new IPs using PyShark
import pyshark
import threading
IPLIST = list()
def main():
cap = pyshark.LiveCapture(interface="en0")
threading.Thread(target=cap.sniff_continuously())
cap.apply_on_packets(callback=callback)
def callback(pkt):
try:
if pkt.ip.src not in IPLIST:
IPLIST.append(pkt.ip.src)
print(pkt.ip.src)
except:
pass
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment