forked from adiroata/network_automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip_calc.py
81 lines (64 loc) · 2.69 KB
/
ip_calc.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
import ipaddress
import csv
ipadd = raw_input('Introduceti adresa (A.B.C.D/nm): ')
host = ipaddress.ip_interface(unicode(ipadd))
hostonly=host.ip
net = host.network
print('-------------------------------------------------\n')
print('Adresa de retea este: ' + str(net))
print('-------------------------------------------------\n')
print('Adresa reverse DNS este: ' + str(hostonly.reverse_pointer))
print('-------------------------------------------------\n')
print('Masca de retea este: ' + str(host.netmask))
print('-------------------------------------------------\n')
print('Wildcard mask este: ' + str(host.hostmask))
print('-------------------------------------------------\n')
print('Numarul de hosturi este: ' + str(net.num_addresses))
print('-------------------------------------------------\n')
p=str('p')
ps=str('ps')
s=str('s')
n = ipaddress.ip_network(net)
answer1 = raw_input('List hosts ?\n\nJust print: p\nPrint&Save: ps\nJust save: s\nAbort: a\n\nYour choice: ')
if answer1 == p:
for ip in n.hosts():
print ip
elif answer1 == ps:
print("Lista hosturilor va fi salvata in fisierul hosts.csv")
for ip in n.hosts():
with open("hosts.csv", "a") as output1:
writer1 = csv.writer(output1)
writer1.writerow([ip,str(host.netmask)])
print ip
elif answer1 == s:
print("Lista hosturilor va fi salvata in fisierul hosts.csv")
for ip in n.hosts():
with open("hosts.csv", "a") as output1:
writer1 = csv.writer(output1)
writer1.writerow([ip,str(host.netmask)])
else:
print('OK, moving on.')
print('-------------------------------------------------\n')
answer2 = raw_input('List subnets ?\n\nJust print: p\nPrint&Save: ps\nJust save: s\nAbort: a\n\nYour choice: ')
if answer2 == p:
newcidr = raw_input('introduceti noul CIDR: ')
for nets in n.subnets(new_prefix=int(newcidr)):
print nets
elif answer2 == ps:
newcidr = raw_input('introduceti noul CIDR: ')
print('Lista subneturilor va fi salvata in fisierul subnets.csv')
for nets in n.subnets(new_prefix=int(newcidr)):
with open("subnets.csv", "a") as output2:
writer2 = csv.writer(output2)
writer2.writerow([nets,])
print nets
elif answer2 == s:
newcidr = raw_input('introduceti noul CIDR: ')
print('Lista subneturilor va fi salvata in fisierul subnets.csv')
for nets in n.subnets(new_prefix=int(newcidr)):
with open("subnets.csv", "a") as output2:
writer2 = csv.writer(output2)
writer2.writerow([nets,])
else:
print("That's all for now. Bye!")