mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Merge 1298970849
into f0ea440d41
This commit is contained in:
commit
656e985a5b
34
traffic_sniffer/traffic_sniffer.py
Normal file
34
traffic_sniffer/traffic_sniffer.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import pyshark
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def sniff(interface, n_packet, filename):
|
||||
capture = pyshark.LiveCapture(interface=interface)
|
||||
capture.sniff(packet_count=n_packet)
|
||||
|
||||
with open(filename + '.txt', 'a+') as file:
|
||||
for n, pkt in enumerate(capture):
|
||||
file.write("Packet #" + str(n + 1) + ':\n')
|
||||
file.write(str(pkt) + '\n')
|
||||
capture.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
programDescription = '''
|
||||
Command Line Tool: python sniffer using pyshark; Need to run with `sudo`
|
||||
'''
|
||||
|
||||
parser = argparse.ArgumentParser(description=programDescription)
|
||||
parser.add_argument("--interface", "-i", help="interface")
|
||||
parser.add_argument("--number", "-n", help="number of packets")
|
||||
parser.add_argument("--filename", "-f", help="filename to save")
|
||||
args = parser.parse_args()
|
||||
|
||||
interface = args.interface if args.interface else 'en0'
|
||||
number = abs(int(args.number)) if args.number else 50
|
||||
filename = args.filename if args.filename else "result"
|
||||
|
||||
sniff(interface, number, filename)
|
||||
|
||||
print('Sniffing is completed at %s' % datetime.now())
|
Loading…
Reference in New Issue
Block a user