Skip to content

Instantly share code, notes, and snippets.

@netmanchris
Created December 11, 2015 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netmanchris/bd73f18cbcd44cf56213 to your computer and use it in GitHub Desktop.
Save netmanchris/bd73f18cbcd44cf56213 to your computer and use it in GitHub Desktop.
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),
cmdgen.UdpTransportTarget((ip_address, 161)),
(ifAlias, rfc1902.OctetString(description)))
def set_interface_description(ipaddress, ifIndex, descr):
"""
Issues SNMP SET Command to change the description on a interface of device
:param ifIndex: type int
:param descr: type string
:return: None
"""
ip_address = ipaddress
community_string = 'private'
snmp_port = 161
ifIndex = str(ifIndex)
descr = descr
ifAlias = str("1.3.6.1.2.1.31.1.1.1.18." + ifIndex)
set_snmp_single(community_string, ip_address, ifAlias, descr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment