-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpypull.py
51 lines (43 loc) · 1.6 KB
/
pypull.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
43
44
45
46
47
48
49
50
51
import sys
import ipinfo
from scapy.all import *
seen = set()
try:
#ipinfo token goes below here in the quotes
urtoken = ''
#filter file supplied in terminal
urfile = os.path.join(sys.path[0], 'filters/', sys.argv[1])
f = open(urfile, 'r')
if os.stat(urfile).st_size == 0:
filters = ""
else:
filters = "" + f.read()
except:
filter_path = sys.path[0] + '/filters'
urfilters = os.listdir(filter_path)
print('Error, Usage: pull [filter.txt]\n')
print('Available Filters Located in [pypyull/filters] are:\n')
#listing the files within pypull/filters
for f in urfilters:
print(f'[{f}]', end=' ')
print('\n')
else:
def print_summary(pkt):
if IP in pkt:
host_src = pkt[IP].src
if host_src not in seen:
seen.add(host_src)
access_token = urtoken
handler = ipinfo.getHandler(access_token)
match = handler.getDetails(host_src)
city = match.details.get('city')
region = match.details.get('region')
if TCP in pkt or UDP in pkt:
host_sport = pkt[IP].sport
strang = ('IP ' + str(host_src) + ' ' + str(host_sport) + ' (' + str(city) + ', ' + str(region) + ')')
print(strang)
else:
strang = ('IP ' + str(host_src) + ' (' + str(city) + ', ' + str(region) + ')')
print(strang)
print('Started Listening!')
sniff(filter=filters, prn=print_summary)