Scripting

  • 1.  Script to detect Vendor Mac Address and put into appropriate vlan

    Posted 01-07-2014 21:50
    Create Date: Mar 20 2013 3:39AM

    Can anyone help me with a script to detect a vendors mac address and put that device in a specific VLAN? (from Forrest_Darst)


  • 2.  RE: Script to detect Vendor Mac Address and put into appropriate vlan

    Posted 01-07-2014 21:50
    Create Date: Mar 20 2013 2:17PM

    Hey Forrest

    See if the attached does what you want. If not it should give you a good starting point. This script will create the necessary UPM profiles so you can change the variables and load the script on the switch and it should create everything you need. Sorry the upload is not working so I just copied and pasted it in the post.

    The entire file below the dotted line can be saved as a *.xsf file and transfered to a switch
    via tftp. Using the "load script *.xsf" command will cause this script to:
    1. Create the MAC-Detect UPM profile
    2. Create the MAC-Delete UPM profile
    3. Configure two log filters and two log targets
    4. Associated the Log targets to the UPM profiles
    --------------------------------------------------------------------------------

    #Create the MAC-Detect UPM Profile
    create upm profile MAC-Detect
    #@MetaDataStart
    #@DetailDescriptionStart
    #############################################################################
    #
    # Script : MAC OUI VLAN Provisioning
    # Revision : 1.0
    # EXOS Version(s) : 12.4.x and Newer
    # Last Updated : 15 May, 2010
    #
    # Purpose:
    # This script will assign a VLAN to a port based upon the device MAC OUI.
    #
    # Using the "vlan.msgs.portLinkStateUp" log message as a trigger, this script
    # will parse the appropriate FDB entry and the assign a predefined vlan to a port.
    #
    # Author : Paul Hutchison
    # Contact : info@extremenetworks.com
    # Contact : www.ethernation.net (ExtremeXOS Forums)
    ###############################################################################
    # Change Log
    #
    # 15 May 2010: Script Created
    ###############################################################################
    #@DetailDescriptionEnd
    ###############################################################################
    #MAC OUI VLANs
    #@VariableFieldLabel "MAC OUI Number 1 (xx:xx:xx:)"
    set var MAC1 00:14:22:
    #@VariableFieldLabel "VLAN for MAC OUI Number 1"
    set var VLAN1 DELLVLAN
    #@VariableFieldLabel "Vendor Name for MAC OUI Number 1"
    set var VENDOR1 Dell
    #@SeparatorLine
    #@VariableFieldLabel "MAC OUI Number 2 (xx:xx:xx:)"
    set var MAC2 00:01:e9:
    #@VariableFieldLabel "VLAN for MAC OUI Number 2"
    set var VLAN2 HPVLAN
    #@VariableFieldLabel "Vendor Name for MAC OUI Number 2"
    set var VENDOR2 HP
    #@SeparatorLine
    #@VariableFieldLabel "MAC OUI Number 3 (xx:xx:xx:)"
    set var MAC3 00:03:93:
    #@VariableFieldLabel "VLAN for MAC OUI Number 3"
    set var VLAN3 APPLEVLAN
    #@VariableFieldLabel "Vendor Name for MAC OUI Number 3"
    set var VENDOR3 Apple
    #@SeparatorLine
    #@MetaDataEnd
    ###############################################################################
    #Create the predefined VLANs - additional VLAN parameters can be added (TAG etc)
    create vlan $VLAN1
    create vlan $VLAN2
    create vlan $VLAN3
    ###############################################################################
    #Wait timer is to allow sufficient time for MAC to be learnt
    set var myWaitVar $TCL(after [expr 1000 * 6])
    #Initialize the CLI.OUT variable to purge any data
    set var CLI.OUT " "
    show fdb ports $EVENT.LOG_PARAM_0
    set var list1 $TCL(split ${CLI.OUT} "\n")
    set var list2 $TCL(lindex $(list1) 2)
    set var list3 $TCL(string replace $(list2) 9 54 {})
    #Match the data in variable "list3" with the user defined MAC OUI variables
    if (!$match($list3, $MAC1)) then
    configure vlan default del port $EVENT.LOG_PARAM_0
    configure vlan $VLAN1 add port $EVENT.LOG_PARAM_0
    create log entry "($VENDOR1)_device_connected_on_port_($EVENT.LOG_PARAM_0)"
    else
    if (!$match($list3, $MAC2)) then
    configure vlan default del port $EVENT.LOG_PARAM_0
    configure vlan $VLAN2 add port $EVENT.LOG_PARAM_0
    create log entry "($VENDOR2)_device_connected_on_port_($EVENT.LOG_PARAM_0)"
    else
    if (!$match($list3, $MAC3)) then
    configure vlan default del port $EVENT.LOG_PARAM_0
    configure vlan $VLAN3 add port $EVENT.LOG_PARAM_0
    create log entry "($VENDOR3)_device_connected_on_port_($EVENT.LOG_PARAM_0)"
    else
    create log entry "Unknown_device_connected_on_port_($EVENT.LOG_PARAM_0)"
    endif
    .
    #Period used to end block-mode

    #Create the MAC-Delete Profile
    create upm profile MAC-Delete
    ###############################################################################
    #@MetaDataStart
    #@DetailDescriptionStart
    #############################################################################
    #
    # Script : MAC OUI VLAN Provisioning- DELETION
    # Revision : 1.0
    # EXOS Version(s) : 12.4.x and Newer
    # Last Updated : 15 May, 2010
    #
    # Purpose:
    # This script will remove a VLAN configured on a port based upon a log event.
    #
    # Using the "vlan.msgs.portLinkStateDown" log message as a trigger, this script
    # will parse the appropriate VLAN data and remove if from it's current VLAN and
    # place the port in the "Default" VLAN.
    #
    # Author : Paul Hutchison
    # Contact : info@extremenetworks.com
    # Contact : www.ethernation.net (ExtremeXOS Forums)
    ###############################################################################
    # Change Log
    #
    # 15 May 2010: Script Created
    ###############################################################################
    #@DetailDescriptionEnd
    ###############################################################################
    #@ScriptDescription "This script will remove a port from a configured VLAN and place it in the default VLAN"
    #@MetaDataEnd
    ###############################################################################
    disable clipaging
    set var CLI.OUT " "
    show ports $EVENT.LOG_PARAM_0 information detail
    set var list1 $TCL(split ${CLI.OUT} "\n")
    set var list2 $TCL(lindex $(list1) 10)
    set var list3 $TCL(lindex $(list2) 1)
    set var vlan $TCL(string range $(list3) 0 end-1)
    configure vlan $vlan delete port $EVENT.LOG_PARAM_0
    configure vlan default add port $EVENT.LOG_PARAM_0
    create log entry Device_removed_on_Port_$EVENT.LOG_PARAM_0
    create log entry Vlan_Default_configured_on_port_$EVENT.LOG_PARAM_0
    .
    #Period used to end block-mode

    ###############################################################################
    #Configure the Log Filter Trigger Parameters
    create log filter Log_PortUp
    create log filter Log_PortDown
    configure log filter Log_PortUp add events vlan.msgs.portLinkStateUp
    configure log filter Log_PortDown add events vlan.msgs.portLinkStateDown
    create log target upm MAC-Detect
    enable log target upm MAC-Detect
    configure log target upm MAC-Detect filter Log_PortUp severity Info only
    configure log target upm MAC-Detect match Any
    create log target upm MAC-Delete
    enable log target upm MAC-Delete
    configure log target upm MAC-Delete filter Log_PortDown severity Info only
    configure log target upm MAC-Delete match Any

    Good Luck

    P (from Paul_Russo)


  • 3.  RE: Script to detect Vendor Mac Address and put into appropriate vlan

    Posted 01-07-2014 21:50
    Create Date: Mar 20 2013 9:39PM

    Thank you very much! This will definitely get me going. (from Forrest_Darst)