-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_handler
More file actions
75 lines (56 loc) · 2.54 KB
/
file_handler
File metadata and controls
75 lines (56 loc) · 2.54 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
#!/usr/bin/python
"""" This is the file handler of the IP Resolver software , which resolves the ip addresses to their respective ISP's based on the
network ips allocated for each of the ip addresses.
"""
#begin code
import sys
import resolver
def main():
print("IP Resolver | A tool to define the ISP of a given IP")
print("____________________________________________________")
print("####################################################")
print('# #')
print('# Limitation! #')
print('# Unresolvable IPs are defined under #')
print('# the category Undefined! #')
print('# #')
print('# #')
print("####################################################")
if sys.version_info < (3,0):
text_name = raw_input("Please enter the list of IP addresses as a Text file:- ")
file_to_write = raw_input("Please enter the filename into which you want to write the data into:- ")
else:
text_name = input("Please enter the list of IP addresses as a Text file:- ")
file_to_write = input("Please enter the filename into which you want to write the data into:- ")
print("Reading the file - " + text_name)
a = open(file_to_write, "w+")
with open('ISPs.txt') as f:
content_isp = f.readlines()
with open(text_name) as f:
content_data = f.readlines()
a.write("The result of the IP Resolver for file %s \n" % text_name)
a.write("----------------------------------------------------------\n")
for j in range(0, len(content_data)):
global isp
isp = ""
for i in range(0, len(content_isp)):
x = content_isp[i].split(None, 2)[0] # Network IP
y = content_isp[i].split(None, 2)[1] # Subnet bits
z = content_isp[i].split(None, 2)[2] # ISP details
ip = content_data[j]
if resolver.resolve_values(ip, x, y):
isp = z
break
else:
isp = "Undefined\n"
a.write(isp)
a.close()
main()
# end code
__author__ = "GWP Chamiekara"
__copyright__ = "Copyright 2017 , Sri Lanka CERT | CC Project"
__credits__ = ["Sri Lanka CERT | CC"]
__version__ = "1.0.1"
__maintainer__ = "Sri Lanka CERT | CC"
__email__ = "pasan@cert.gov.lk "
__status__ = "Production"