Skip to content

Instantly share code, notes, and snippets.

@netmanchris
netmanchris / set_interface_description.py
Created December 11, 2015 03:50
Python code using pysnmp library to set interface description on a network device
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),
@netmanchris
netmanchris / gen_dhcp_scope.j2
Last active July 24, 2016 16:30
Jinja2 template to generate Powershell script which will create multiple DHCP scopes on a single Microsoft Windows 2012R2 DHCP server
#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 }}
@netmanchris
netmanchris / dhcp_scopes.yaml
Created July 24, 2016 16:47
YAML file which contains the desired DHCP Scope Definitions
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,
@netmanchris
netmanchris / gen_scopes_posh.py
Created July 24, 2016 16:52
Python script to generate Powershell script from add_dhcp_ps.j2 template
'''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
@netmanchris
netmanchris / add_client_reservations_ps.j2
Created July 24, 2016 17:01
Jinja2 template to automate creation of powershell script to add DHCP client reservations
#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 %}
@netmanchris
netmanchris / reservations.csv
Created July 24, 2016 17:04
CSV File Containing DHCP client reservations for home lab network
IPAddress Name ClientId Description InitialConfigFile DHCPServer ScopeId
10.11.0.10 5400R 64-51-06-79-0c-00 Rserved for 5400R Mobile1st Branch AdpInitialConfig5400R.cfg 10.101.0.20 10.11.0.0
10.11.0.11 2920stack 74-46-a0-ff-78-e3 Reserved for 2920 Stack AdpInitialConfig2920.cfg 10.101.0.20 10.11.0.0
@netmanchris
netmanchris / gen_reservations_posh.py
Created July 24, 2016 17:06
python script to generate powershell file from Jinja2 template
'''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
@netmanchris
netmanchris / vlan_json_output.py
Last active May 16, 2017 19:50
sample vlan json output
vlan_good = json.loads('''{
"uri": "/vlans/1",
"vlan_id": 1,
"name": "DEFAULT_VLAN",
"status": "VS_PORT_BASED",
"type": "VT_STATIC",
"is_voice_enabled": false,
"is_jumbo_enabled": false,
"is_dsnoop_enabled": false,
"is_dhcp_server_enabled": false
@netmanchris
netmanchris / vlan_json.schema.py
Last active May 16, 2017 19:43
VLAN JSON Schema Definition
schema = json.loads('''{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "VLAN configuration data.",
"title": "Vlan",
"type": "object",
"sql.max_rows": 4094,
"properties": {
"uri": {
"description": "The URI of the configuration entity",
"type": "string",