-
Notifications
You must be signed in to change notification settings - Fork 0
/
BulkWhoIs.py
executable file
·63 lines (50 loc) · 1.51 KB
/
BulkWhoIs.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
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
##
import os
import re
import sys
import pickle
#import socket
#import tempfile
#import argparse
from ipwhois.experimental import get_bulk_asn_whois
from ipwhois.experimental import bulk_lookup_rdap
from pprint import pprint
#IPsort = lambda a1, a2: cmp(socket.inet_aton(a1), socket.inet_aton(a2))
#IPlist = []
def Remember(It, As):
"""Make findings reuseable"""
storage = os.path.join(tempfile.gettempdir(), As)
with open(storage, 'wb') as f:
pickle.dump(It, f)
def Recall(tale):
"""Recall findings"""
It = []
storage = os.path.join(tempfile.gettempdir(), tale)
with open(storage, 'rb') as f:
It = pickle.load(f)
return It
def MyWhoIs(IPlist):
"""Reformat whois_list"""
results = get_bulk_asn_whois(addresses=IPlist)
#pprint(results.split('\n'))
Grumble = results.split('\n')
return Grumble
# pprint(Grumble)
if __name__ == "__main__":
import argparse
import IPsort
parser = argparse.ArgumentParser(description="Grok file....")
parser.add_argument('file', help='File do do magic on')
parser.add_argument('-s', '--separator', type=str, help='Seperator', default=';')
args = parser.parse_args()
file = args.file
sep = args.separator
list = IPsort.do_magic(file, sep)
result = MyWhoIs(list)
pprint(result)
#Filename = "%s.json" % key
#with open(Filename, 'w') as outfile:
# json.dump(result, outfile, sort_keys=True, indent=4)
#for item in result:
#print "%s" % (item)