-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe.py~
45 lines (36 loc) · 962 Bytes
/
pipe.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
36
37
38
39
40
41
42
#!/usr/bin/python
from scapy.all import *
from scapy.layers import http
stars = lambda n: "*" * n
q = list()
hostdict = {}
last_referer = "empty string that is not none"
def packethandler(pkt):
global hostdict
global last_referer
host,referer = None,None
for header in str(pkt).splitlines():
if "Host" in header:
host = header[6:]
#print "Host: " + host
if "Referer" in header:
parts = header[9:].split('//', 1)
referer = parts[0]+'//'+parts[1].split('/', 1)[0]
#print "Referer: " + referer
if referer == last_referer:
if host in hostdict:
hostdict[host] += 1
else:
hostdict[host] = 1
if referer != last_referer:
print({"referer":last_referer,"hosts":hostdict})
hostdict = {}
last_referer = referer
def main():
print("sniffing...")
sniff(
iface='eth0',
prn= packethandler,
lfilter=lambda p: "GET" in str(p),
filter="tcp port 80")
main()