-
Notifications
You must be signed in to change notification settings - Fork 0
/
zora
148 lines (125 loc) · 4.58 KB
/
zora
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python3
# Author: z3r0day :: https://github.com/SxNade
RED = '\033[1;31;48m'
WHITE = "\33[0m"
GREEN = '\033[1;32;48m'
import requests
import sys
import optparse
import os
import ipaddress
import json # to Just parse API data properly , although can be done without this!
import re
def check_file_existence(file_path):
if os.path.exists(file_path) == False:
return False
else:
return True
def write_json_file(IP, content_json):
f = open(f"data/{IP}.json", "w")
f.write(content_json)
f.close()
def get_content(url):
resp = requests.get(url, allow_redirects=True)
webcontent = resp.text
return webcontent
def api_method(hosts):
print(f"[{GREEN}+{WHITE}] Looking for {RED}api.txt{WHITE} in current Directory")
if check_file_existence("api.txt"):
with open("api.txt","r") as file:
one_line = file.readline().strip()
for host in hosts:
try:
if check_file_existence(f'data/{host}.json'):
print(f"\nJSON for {RED}{host}:{WHITE} found!")
f = open(f'data/{host}.json',"r")
data_dict = json.loads(f.read())
data = f'''
Target-IP: {RED}{host}{WHITE}
Country: {GREEN}{data_dict['country_name']}{WHITE}
State: {GREEN}{data_dict['state_prov']}{WHITE}
City: {GREEN}{data_dict['city']}{WHITE}
latitude: {data_dict['latitude']}
longitude: {data_dict['longitude']}
ISP: {GREEN}{data_dict['isp']}{WHITE}
'''
print(data)
else:
print(f"\nLocating {RED}{host}:{WHITE}")
json_content = get_content(f'https://api.ipgeolocation.io/ipgeo?apiKey={one_line}&ip={host}')
json_dict = json.loads(json_content)
data = f'''
Target-IP: {RED}{host}{WHITE}
Country: {GREEN}{json_dict['country_name']}{WHITE}
State: {GREEN}{json_dict['state_prov']}{WHITE}
City: {GREEN}{json_dict['city']}{WHITE}
latitude: {json_dict['latitude']}
longitude: {json_dict['longitude']}
ISP: {GREEN}{json_dict['isp']}{WHITE}
'''
print(data)
write_json_file(host, json_content)
except KeyboardInterrupt:
print(f"{RED}Exiting:{WHITE}")
sys.exit(1)
else:
print(f"\n[{RED}Error:{WHITE}] {GREEN}api.txt{WHITE} not found\n")
sys.exit(1)
def non_api_method(hosts):
print(f"\n[{RED}INFO:{WHITE}] Not using {GREEN}API{WHITE}")
for host in hosts:
try:
print(f"\nLocating {RED}{host}:{WHITE}")
req_resp = get_content(f'https://www.ipligence.com/ip-address?ip={host}')
reverse_dns = re.findall(r"Reverse dns:(.*?)<",req_resp)
country_name = re.findall(r"Country:(.*?)<",req_resp)
Continent = re.findall(r"Continent:(.*?)<",req_resp)
City = re.findall(r"City:(.*?)<",req_resp)
Time_zone = re.findall(r"Time Zone:(.*?)<",req_resp)
data = f'''
Target-IP: {RED}{host}{WHITE}
Reverse-DNS: {reverse_dns[0]}
Country: {GREEN}{country_name[0]}{WHITE}
Continent: {GREEN}{Continent[0]}{WHITE}
City: {GREEN}{City[0]}{WHITE}
Time Zone: {GREEN}{Time_zone[0]}{WHITE}
'''
print(data)
except KeyboardInterrupt:
print(f"{RED}Exiting:{WHITE}")
sys.exit(1)
def subnet_to_hosts(target_subnet,api_value):
print(f"\n[{GREEN}+{WHITE}] Network:{RED}{target_subnet}{WHITE}")
network = ipaddress.ip_network(target_subnet)
hosts = list(network.hosts())
if int(api_value) == 1:
api_method(hosts)
print("===========================================================================")
else:
non_api_method(hosts)
print("===========================================================================")
def read_subnets(file_path):
if check_file_existence(file_path):
print(f"\n[{GREEN}+{WHITE}] Reading subnets from file {file_path}")
subnet_list = []
with open(file_path, 'r') as file:
for line in file.readlines():
target_subnet = line.strip()
subnet_list.append(target_subnet)
return subnet_list
else:
print(f"\n[{RED}Error:{WHITE}] File path {file_path} not found\n")
sys.exit()
parser = optparse.OptionParser("\n./ipgeo [-h or --help] [-f or --file]=<file-path-with-subnets-on-each-line> [-a or --api=0/1]")
parser.add_option("-f", "--file", dest="subnet_file_path", type='string', help="specify the file containing subnets one on each line")
parser.add_option("-a", "--api", dest="api_value", type='int', help="specify 1 for using API {looks for api.txt containing key} else specify 0 to not use API")
(options, args) = parser.parse_args()
if (options.subnet_file_path == None or options.api_value == None):
parser.error(f"\n[{RED}!{WHITE}] Insufficent Arguments supplied\n")
sys.exit(0)
else:
api_value = options.api_value
target_file = options.subnet_file_path
subnet_list = read_subnets(target_file)
for subnet in subnet_list:
subnet_to_hosts(subnet,int(api_value))