Scripts for generating subnets and devices.
This commit is contained in:
45
devices.py
Executable file
45
devices.py
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from netaddr import IPNetwork
|
||||||
|
import csv
|
||||||
|
import sys
|
||||||
|
|
||||||
|
Section = "CDRN / TRN WAN"
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
'Section',
|
||||||
|
'IP address',
|
||||||
|
'Description',
|
||||||
|
'Subnet',
|
||||||
|
'Hostname'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
inFilePath = sys.argv[1]
|
||||||
|
|
||||||
|
if len(sys.argv) == 3:
|
||||||
|
outFile = open(sys.argv[2], 'w')
|
||||||
|
else:
|
||||||
|
outFile = sys.stdout
|
||||||
|
|
||||||
|
csvWriter = csv.DictWriter(outFile, fieldnames=fields,
|
||||||
|
delimiter=',', quotechar='"',
|
||||||
|
quoting=csv.QUOTE_MINIMAL)
|
||||||
|
|
||||||
|
csvWriter.writeheader()
|
||||||
|
|
||||||
|
with open(inFilePath, 'r', newline='') as inFile:
|
||||||
|
csvReader = csv.DictReader(inFile)
|
||||||
|
outRow = {}
|
||||||
|
|
||||||
|
for inRow in csvReader:
|
||||||
|
outRow['Section'] = Section
|
||||||
|
outRow['IP address'] = inRow['IP-Address']
|
||||||
|
outRow['Description'] = inRow['Site-Name']
|
||||||
|
outRow['Subnet'] = str(IPNetwork(inRow['IP-Address'] + '/' + inRow['Subnet-Mask']).cidr)
|
||||||
|
outRow['Hostname'] = inRow['Site-Name'].split()[0] + '-SC200'
|
||||||
|
|
||||||
|
csvWriter.writerow(outRow)
|
||||||
|
inFile.close()
|
||||||
|
|
||||||
|
outFile.close()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
#from netaddr import IPAddress
|
from ipaddress import IPv4Address
|
||||||
from xmlrpc.client import ServerProxy
|
from xmlrpc.client import ServerProxy
|
||||||
#import sqlite3
|
#import sqlite3
|
||||||
import socket
|
import socket
|
||||||
@@ -59,6 +59,9 @@ Settings = [
|
|||||||
'Site-Address',
|
'Site-Address',
|
||||||
'System-Location',
|
'System-Location',
|
||||||
'Site-Notes',
|
'Site-Notes',
|
||||||
|
'IP-Address',
|
||||||
|
'Subnet-Mask',
|
||||||
|
'Gateway-Address',
|
||||||
'Float-Voltage',
|
'Float-Voltage',
|
||||||
'Battery-Capacity',
|
'Battery-Capacity',
|
||||||
'AC-Rectifier-Current-Limit',
|
'AC-Rectifier-Current-Limit',
|
||||||
@@ -92,6 +95,11 @@ Settings = [
|
|||||||
['Alarm-Severity'] + \
|
['Alarm-Severity'] + \
|
||||||
['Alarm-Severity:' + repr(x) for x in range(1, 59)]
|
['Alarm-Severity:' + repr(x) for x in range(1, 59)]
|
||||||
|
|
||||||
|
NetworkSettings = [
|
||||||
|
'IP-Address',
|
||||||
|
'Subnet-Mask',
|
||||||
|
'Gateway-Address'
|
||||||
|
]
|
||||||
|
|
||||||
def GetStatusCode(host, path="/"):
|
def GetStatusCode(host, path="/"):
|
||||||
try:
|
try:
|
||||||
@@ -135,6 +143,11 @@ class Worker(threading.Thread):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if len(Values) > 0:
|
if len(Values) > 0:
|
||||||
|
for idx, setting in enumerate(Settings):
|
||||||
|
if setting in NetworkSettings:
|
||||||
|
print(Values[idx])
|
||||||
|
Values[idx] = str(IPv4Address(Values[idx]))
|
||||||
|
|
||||||
Values.insert(0, str(IP))
|
Values.insert(0, str(IP))
|
||||||
self.__Results.put(Values)
|
self.__Results.put(Values)
|
||||||
else:
|
else:
|
||||||
|
|||||||
53
subnets.py
Executable file
53
subnets.py
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from netaddr import IPNetwork
|
||||||
|
import csv
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
|
Section = "CDRN / TRN WAN"
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
'Section',
|
||||||
|
'Subnet',
|
||||||
|
'Mask',
|
||||||
|
'Description',
|
||||||
|
]
|
||||||
|
|
||||||
|
subnets = []
|
||||||
|
|
||||||
|
inFilePath = sys.argv[1]
|
||||||
|
|
||||||
|
if len(sys.argv) == 3:
|
||||||
|
outFile = open(sys.argv[2], 'w')
|
||||||
|
else:
|
||||||
|
outFile = sys.stdout
|
||||||
|
|
||||||
|
csvWriter = csv.DictWriter(outFile, fieldnames=fields,
|
||||||
|
delimiter=',', quotechar='"',
|
||||||
|
quoting=csv.QUOTE_MINIMAL)
|
||||||
|
|
||||||
|
csvWriter.writeheader()
|
||||||
|
|
||||||
|
with open(inFilePath, 'r', newline='') as inFile:
|
||||||
|
csvReader = csv.DictReader(inFile)
|
||||||
|
outRow = {}
|
||||||
|
|
||||||
|
for inRow in csvReader:
|
||||||
|
outRow['Section'] = Section
|
||||||
|
subnet = IPNetwork(inRow['IP-Address'] + '/' + inRow['Subnet-Mask']).cidr
|
||||||
|
if subnet in subnets:
|
||||||
|
continue
|
||||||
|
subnets.append(subnet)
|
||||||
|
outRow['Subnet'] = str(subnet)
|
||||||
|
outRow['Mask'] = inRow['Subnet-Mask']
|
||||||
|
try:
|
||||||
|
outRow['Description'] = re.search(r"(([a-zA-Z]+S\d)|(C[a-zA-Z]+\d+)|(T[a-zA-Z]+)|([a-zA-Z]+(-Core)?))([\- ]+\d )?.*", inRow['Site-Name']).group(1) + '-SC200'
|
||||||
|
except AttributeError:
|
||||||
|
print(inRow['Site-Name'])
|
||||||
|
outRow['Description'] = inRow['Site-Name']
|
||||||
|
|
||||||
|
csvWriter.writerow(outRow)
|
||||||
|
inFile.close()
|
||||||
|
|
||||||
|
outFile.close()
|
||||||
Reference in New Issue
Block a user