This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#File to use powershell to automatically build all required DHCP reservations for lab environment | |
{% for client in reservations %} | |
Add-DhcpServerv4Reservation -ScopeId {{ client.ScopeId }} -IPAddress {{ client.IPAddress }} -ClientId "{{ client.ClientId }}" -Description "{{ client.Description }}" | |
Set-DhcpServerv4OptionValue -ComputerName {{ client.DHCPServer }} -ReservedIP {{ client.IPAddress }} -OptionId 67 -Value {{ client.InitialConfigFile }} | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Copyright 2015 Christopher Young (@netmanchris) | |
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the | |
License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required''' | |
from jinja2 import Environment, FileSystemLoader, Template | |
import yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lab_globals: | |
{tftp: 10.101.0.203, | |
DNS: 10.101.0.20, | |
Domain: lab.local, | |
CCM: 10.101.0.1, | |
Server: 10.101.0.20} | |
dhcpscopes: | |
- {Server: 10.101.0.20, | |
ScopeID: 10.11.0.0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#File to use powershell to automatically build all required DHCP scopes for lab environment | |
Add-DhcpServerv4OptionDefinition -Name tftp -OptionId 150 -Type IPv4Address | |
{% for scope in dhcpscopes.dhcpscopes %} | |
Add-DHCPServerv4Scope -EndRange {{ scope.EndRange }} -Name {{ scope.Name }} -StartRange {{ scope.StartRange }} -SubnetMask {{ scope.SubnetMask }} -State Active | |
Set-DHCPServerv4OptionValue -ComputerName {{ dhcpscopes.lab_globals.Server }} -ScopeId {{ scope.ScopeID }} -DnsServer {{ dhcpscopes.lab_globals.DNS }} -DnsDomain {{ dhcpscopes.lab_globals.Domain }} -Router {{ scope.Gateway }} | |
Set-DhcpServerv4OptionValue -ComputerName {{ scope.Server }} -ScopeId {{ scope.ScopeID }} -OptionId 66 -Value {{ dhcpscopes.lab_globals.tftp }} | |
Set-DhcpServerv4OptionValue -ComputerName {{ scope.Server }} -ScopeId {{ scope.ScopeID }} -OptionId 67 -Value {{ scope.InitialConfig }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pysnmp | |
def set_snmp_single(rwstring, ip_address, ifAlias, description): | |
from pysnmp.entity.rfc3413.oneliner import cmdgen | |
from pysnmp.proto import rfc1902 | |
cmdGen = cmdgen.CommandGenerator() | |
cmdGen.setCmd( | |
cmdgen.CommunityData(rwstring), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ipaddress | |
def ip_in_network(startIp, endIp): | |
mask = 32 | |
startIp = ipaddress.ip_address(startIp) | |
endIp = ipaddress.ip_address(endIp) | |
netrange = ipaddress.ip_network(str(startIp)+'/'+str(mask), strict=False) | |
while ((endIp in netrange) == False): | |
mask -= 1 | |
netrange = ipaddress.ip_network(str(startIp)+'/'+str(mask), strict=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> y = xmltodict.parse(x) | |
>>> y | |
OrderedDict([('device', OrderedDict([('id', '116'), ('label', 'Cisco2811.haw.int'), ('ip', '10.101.0.1'), ('mask', '255.255.255.0'), ('status', '1'), ('statusDesc', 'Normal'), ('sysName', 'Cisco2811.haw.int'), ('contact', 'changed this too'), ('location', 'changed this too'), ('sysOid', '1.3.6.1.4.1.9.1.576'), ('sysDescription', None), ('devCategoryImgSrc', 'router'), ('topoIconName', 'iconroute'), ('categoryId', '0'), ('symbolId', '1147'), ('symbolName', 'Cisco2811.haw.int'), ('symbolType', '3'), ('symbolDesc', None), ('symbolLevel', '2'), ('parentId', '1'), ('typeName', 'Cisco 2811'), ('mac', '00:1b:d4:47:1e:68'), ('link', OrderedDict([('@op', 'GET'), ('@rel', 'self'), ('@href', 'http://10.3.10.220:8080/imcrs/plat/res/device/116')]))]))]) | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> print (yaml.dump(y, default_flow_style = False)) | |
!!python/object/apply:collections.OrderedDict | |
dictitems: | |
device: !!python/object/apply:collections.OrderedDict | |
dictitems: | |
categoryId: '0' | |
contact: changed this too | |
devCategoryImgSrc: router | |
id: '116' | |
ip: 10.101.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> print (json.dumps(y, indent = 4)) | |
{ | |
"device": { | |
"id": "116", | |
"label": "Cisco2811.haw.int", | |
"ip": "10.101.0.1", | |
"mask": "255.255.255.0", | |
"status": "1", | |
"statusDesc": "Normal", | |
"sysName": "Cisco2811.haw.int", |