forked from averagesecurityguy/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetintel_nmap.py
More file actions
executable file
·106 lines (80 loc) · 2.77 KB
/
netintel_nmap.py
File metadata and controls
executable file
·106 lines (80 loc) · 2.77 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
import requests
import sys
import time
import json
import argparse
API_KEY = ""
def get_records(url):
resp = ''
status = 0
while status != 200:
resp = requests.get(url)
status = resp.status_code
time.sleep(2)
return resp.json()
def get_ipv6s():
if data.get('ipv6s') is not None:
records = get_records(data['ipv6s'])
return '\n'.join(set([ipv6['address'] for ipv6 in records['addresses']]))
else:
print('IPv6 address data set not found.')
sys.exit(1)
def get_externals():
if data.get('externals') is not None:
records = get_records(data['externals'])
return '\n'.join(set([addr['address'] for addr in records['addresses']]))
else:
print('External address data set not found.')
sys.exit(1)
def get_blocks():
if data.get('blocks') is not None:
records = get_records(data['blocks'])
return '\n'.join(set([block['block'] for block in records['blocks']]))
else:
print('Network blocks data set not found.')
sys.exit(1)
#-----------------------------------------------------------------------------
# Main Program
#-----------------------------------------------------------------------------
parser = argparse.ArgumentParser()
parser.add_argument("address_type", help="Must be one of all, ipv6, external, or block.")
parser.add_argument("query_type", help="Must be either domain or report.")
parser.add_argument("query_value", help="Should be a domain name or a report name.")
args = parser.parse_args()
if args.address_type.lower() not in ['all', 'ipv6', 'external', 'block']:
print(parser.usage)
sys.exit(1)
if args.query_type.lower() not in ['domain', 'report']:
print(parser.usage)
sys.exit(1)
data = {}
if args.query_type == 'domain':
domain = args.query_value
url = 'https://pro.netintel.net/lookup.php'
resp = requests.post(url, data={'domain': domain, 'apikey': API_KEY})
data = resp.json()
report_name = data.get('report')[33:-12]
print('Use this report name for future queries: {0}.'.format(report_name))
if 'error' in data:
print('Could not query domain: {0}'.format(data['error']))
sys.exit(1)
else:
report = args.query_value
url = 'https://pro.netintel.net/reports/{0}/report.json'.format(report)
resp = requests.get(url)
if resp.status_code == 200:
data = resp.json()
else:
print('Could not find report: {0}'.format(report))
sys.exit(1)
if args.address_type.lower() == 'ipv6':
print(get_ipv6s())
elif args.address_type.lower() == 'external':
print(get_externals())
elif args.address_type.lower() == 'block':
print(get_blocks())
else:
print(get_ipv6s())
print(get_externals())
print(get_blocks())