View Single Post
  #6  
Old 11-04-2013, 04:25 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
Now Working

Hello Todd,

It is working now by replacing
For i to 48

with
For Each strSwitchPort In vSwitchPorts

Funny, the i to 48 has worked for me before. maybe i didn't declare a variable globally...

Here is the working script and hope you have a good day.


Code:
Language="VBScript"
Interface="1.0"

crt.Screen.Synchronous = True

Dim shell
Set shell = CreateObject("WSCript.Shell")

'Declare Global Strings
Dim mySwPort
Dim myphonemac
Dim mySwitchCount
Dim myscreenrow
Dim myPortNum
myPortNum = 1
Dim myphonevlan
Dim vSwitchPorts(48)
vSwitchPorts(0) = "1"
vSwitchPorts(1) = "2"
vSwitchPorts(2) = "3"
vSwitchPorts(3) = "4"
vSwitchPorts(4) = "5"
vSwitchPorts(5) = "6"
vSwitchPorts(6) = "7"
vSwitchPorts(7) = "8"
vSwitchPorts(8) = "9"
vSwitchPorts(9) = "10"
vSwitchPorts(10) = "11"
vSwitchPorts(11) = "12"
vSwitchPorts(12) = "13"
vSwitchPorts(13) = "14"
vSwitchPorts(14) = "15"
vSwitchPorts(15) = "16"
vSwitchPorts(16) = "17"
vSwitchPorts(17) = "18"
vSwitchPorts(18) = "19"
vSwitchPorts(19) = "20"
vSwitchPorts(20) = "21"
vSwitchPorts(21) = "22"
vSwitchPorts(22) = "23"
vSwitchPorts(23) = "24"
vSwitchPorts(24) = "25"
vSwitchPorts(25) = "26"
vSwitchPorts(26) = "27"
vSwitchPorts(27) = "28"
vSwitchPorts(28) = "29"
vSwitchPorts(29) = "30"
vSwitchPorts(30) = "31"
vSwitchPorts(31) = "32"
vSwitchPorts(32) = "33"
vSwitchPorts(33) = "34"
vSwitchPorts(34) = "35"
vSwitchPorts(35) = "36"
vSwitchPorts(36) = "37"
vSwitchPorts(37) = "38"
vSwitchPorts(38) = "39"
vSwitchPorts(39) = "40"
vSwitchPorts(40) = "41"
vSwitchPorts(41) = "42"
vSwitchPorts(42) = "43"
vSwitchPorts(43) = "44"
vSwitchPorts(44) = "45"
vSwitchPorts(45) = "46"
vSwitchPorts(46) = "47"
vSwitchPorts(47) = "48"

Sub Main()
							  
'count the number of switches
crt.Screen.Send "sh int status" & vbCr
crt.Screen.WaitForStrings "4/0/48","3/0/48","2/0/48","1/0/48"
Select Case crt.Screen.MatchIndex
	Case 1
		mySwitchCount = 4
	Case 2
		mySwitchCount = 3
	Case 3
		mySwitchCount = 2
	Case 4
		mySwitchCount = 1
End select

If mySwitchCount = 1 Then 
F1 'f3750x48-1
End If

If mySwitchCount = 2 Then 
	F2
'	f3750x48-1
'	f3750x48-2
End If

If mySwitchCount = 3 Then
	F3
'	f3750x48-1
'	f3750x48-2
'	f3750x48-3
End If

If mySwitchCount = 4 Then
	F4
'	f3750x48-1
'	f3750x48-2
'	f3750x48-3
'	f3750x48-4
End If

If crt.Session.Connected Then
crt.Session.Disconnect
msgbox "Finished Programming"
End If


End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Incrementing Loop for each port of a switch

Sub F1
'Function f3750x48-1
'For i to 48
For Each strSwitchPort In vSwitchPorts
	If strSwitchPort = "" Then Exit For
	crt.Screen.Send "terminal length 0" & vbCr
	crt.Screen.WaitForString "#"
	crt.Screen.Send "sh cdp ne int g1/0/" & strSwitchPort & vbCr
	crt.Screen.WaitForStrings "IP Phone", "VG224", "DMP", "Ieee PD", "AIR-CAP", "#"
	Select Case crt.Screen.MatchIndex
		Case 1
			'Found a phone, secure it
			myscreenrow = crt.Screen.CurrentRow
			myphonemac = crt.Screen.Get(myscreenrow, 3, myscreenrow, 15)
			crt.Screen.Send "config t" & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "int g1/0/" & strSwitchPort & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "switchport port-security max 1 vlan voice" & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "switchport port-security violation shutdown vlan" & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "switchport port-security mac-address " & myphonemac & " vlan voice" & vbCr
			crt.Screen.WaitForString "#"
			crt.screen.send "end" & vbcr
		Case 2
			'Found a VG224, ignore the port
		Case 3
			'Found a DMP, ignore the port
		Case 4
			'don't remember what this means LOOK INTO THIS can be paging zone controller
		Case 5
			'Found an LWAP, ignore the port
		Case 6
			crt.Screen.Send "sh power inline int g1/0/" & strSwitchPort & vbCr
			'Ieee PD is a Paging Zone Controller. skip these ports
			crt.Screen.WaitForStrings "IP Phone", "#", "Ieee PD"
			Select Case crt.Screen.MatchIndex
				Case 1
					'Phone already programmed, skip
				Case 2
					'No Phone, lock the port by removing voice vlan.  first identify the voice vlan
					crt.screen.send "sh run int g1/0/" & strSwitchPort & vbcr
					crt.screen.waitforstring "switchport voice vlan "
					myphonevlan = Trim(crt.Screen.ReadString(vbcr))
					crt.screen.send "config t" & vbcr
					crt.screen.waitforstring "#"
					crt.Screen.Send "int g1/0/" & strSwitchPort & vbCr
					crt.screen.waitforstring "#"
					crt.screen.send "no switchport voice vlan " & myphonevlan & vbcr
					crt.screen.waitforstring "#"
					crt.screen.send "end " & vbcr
					crt.screen.waitforstring "#"
				Case 3
					'Paging Zone Controller, skip the port
			end select
	end select
Next
'End Function
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-2
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-3
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-4
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Last edited by rtb; 11-05-2013 at 07:59 AM.
Reply With Quote