-
Notifications
You must be signed in to change notification settings - Fork 3
/
receive.py
35 lines (28 loc) · 946 Bytes
/
receive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import print_function
from scapy.all import *
import os
import sys
# Destination IP Counter
counter = 0
if(os.path.isfile("cpu.log")):
os.remove("cpu.log")
def getSrcIP(packet):
global counter
counter += 1
fileLog = open("cpu.log", "a")
fileLog.write('[{}]: SrcAddr: {}\n'.format(counter, packet[0][1].src))
return hexdump(packet)
def main():
if len(sys.argv) != 2:
print("ERROR: Invalid number of arguments")
print("USAGE: sudo python receive.py vethX")
print("INFO: Set the desired value to X's place.")
exit(1)
else:
sniff_port = sys.argv[1]
print("The sniffing port is set to: [{}]".format(sniff_port))
# To write source IP addresses to a file change the line below to be a code line
#sniff(iface = str(sys.argv[1]), prn=getSrcIP, filter="ip")
# To write source IP addresses to a file change the line below to be a comment line
sniff(iface = str(sys.argv[1]), prn = lambda x: hexdump(x))
main()