Created
June 18, 2018 01:16
-
-
Save jonmarty/ce6aa674e57a50e0b403100fa610398d to your computer and use it in GitHub Desktop.
Code to continuously monitor the network for new IPs using PyShark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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