1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
| Option Explicit
Dim pathout,pathin
Dim objFso,objShell, objExcel
Dim strcurrent
Dim sCurPath,strCurTab,fTxtin,fTxtout,yxcl
Dim MessageToLog
Dim lentagint,lentagdesc,lentagvlan,lentagmac,lentagtrunk
Dim valtag,temp,tempbis,linecurr,desc
sCurPath = Replace(Wscript.ScriptFullName, Wscript.ScriptName, "")
Public Const tagint = "interface"
Public Const tagdesc = " description"
Public Const tagvlan = " switchport access"
Public Const tagmac = " switchport port-security mac-address sticky"
Public Const tagtrunk =" switchport trunk allowed vlan"
Public Const R_ONLY = 1
Public Const EVENT_SUCCESS = 0
Public Const EVENT_ERROR = 1
Public Const EVENT_WARNING = 2
lentagint = Len(tagint)
lentagdesc = Len(tagdesc)
lentagvlan = Len(tagvlan)
lentagmac = Len(tagmac)
lentagtrunk=Len(tagtrunk)
pathin = sCurPath & "test.xls"
Set objShell = Wscript.CreateObject("Wscript.Shell")
InitPath ()
' -------------------------------------
' Ouverture du Fichier destination
' -------------------------------------
Set objFso = CreateObject ("scripting.filesystemobject")
Set objExcel=CreateObject("Excel.Application")
If Not (objFso.FileExists(pathin)) Then
MessageToLog = "Fichier destination pour copie : " & "Le fichier n'existe pas !"
objShell.LogEvent EVENT_ERROR, MessageToLog
objFso = Nothing
Wscript.Quit
End If
Set fTxtin = objExcel.workbooks.open(pathin)
objExcel.visible=true
msgbox(pathout)
' -------------------------------------
' Ouverture du Fichier source
' -------------------------------------
Set objFso = CreateObject ("scripting.filesystemobject")
If Not (objFso.FileExists(pathout)) Then
MessageToLog = "Fichier source pour copie : " & "Le fichier n'existe pas !"
objShell.LogEvent EVENT_ERROR, MessageToLog
' objFso = Nothing
Wscript.Quit
End If
Set fTxtout = objFso.OpenTextFile(pathout,R_ONLY)
call RecupVal
'################################################
Sub RecupVal
fTxtin.worksheets(1).cells(1,1)=tagint
fTxtin.worksheets(1).cells(1,2)=tagdesc
fTxtin.worksheets(1).cells(1,3)="Vlan"
fTxtin.worksheets(1).cells(1,4)="ADD MAC"
fTxtin.worksheets(1).cells(1,5)="TRUNK"
yxcl=2
While Not fTxtout.AtEndOfStream
if left(strcurrent,lentagint) = tagint then valtag=1
if left(strcurrent,lentagdesc) = tagdesc then valtag=2
if left(strcurrent,lentagvlan) = tagvlan then valtag=3
if left(strcurrent,lentagmac) =tagmac then valtag=4
if left(strcurrent,lentagtrunk)=tagtrunk then
valtag=5
msgbox("valtag=5")
end if
if left(strcurrent,lentagint) <> tagint AND left(strcurrent,lentagdesc) <> tagdesc AND left(strcurrent,lentagvlan) <> tagvlan AND left(strcurrent,lentagmac)<> tagmac AND left(strcurrent,lentagtrunk)<>tagtrunk then valtag=0
Select Case valtag
case 1
Call Copie (yxcl,1,1)
valtag = 0
case 2
Call Copie(yxcl,2,2)
valtag = 0
case 3
Call Copie(yxcl,3,4)
valtag = 0
case 4
Call Copie(yxcl,4,5)
valtag = 0
yxcl=yxcl+1
case 5
msgbox("trunk")
Call Copie(yxcl,5,5)
valtag = 0
yxcl=yxcl+1
case else
strcurrent=fTxtout.ReadLine()
end select
Wend
msgbox("fin")
fTxtin.Close()
fTxtout.Close()
End sub
'################################################
'################################################
Sub InitPath ()
pathout = inputbox ("chemin du fichier voulu","Chemin de conf EAR")
End Sub
'################################################
Sub Copie (yxcl,xcell,nTab)
if fTxtout.Line = 1 then strcurrent = fTxtout.ReadLine()
if nTab = 5 AND valtag =4 then
fTxtin.worksheets(1).Cells(yxcl,xcell)=Right(strcurrent,14)
if fTxtin.worksheets(1).Cells(yxcl - 1,xcell)="address sticky" and tempbis=1 then
fTxtin.worksheets(1).Cells(yxcl-1,xcell)=Right(strcurrent,14)
fTxtin.worksheets(1).Cells(yxcl,xcell)=""
tempbis=0
else tempbis=1
end if
else
strCurTab = Split(strcurrent, " ")
'msgbox("dans le tableau : " & strCurTab(nTab))
fTxtin.worksheets(1).Cells(yxcl,xcell)=strCurTab(nTab)
end if
If nTab= 4 then
if strCurTab(nTab) = "300" then
yxcl = yxcl + 1
dim i
For i = 1 to 5
fTxtout.ReadLine()
Next
end if
end if
If nTab=1 then if left(strCurTab(nTab),8)="Loopback" then yxcl = yxcl + 1
If nTab=1 then
if left(strCurTab(nTab),4)="Vlan" then
temp=1
msgbox("avant temp: " &strcurrent)
msgbox("temp=1")
end if
end if
If temp=1 AND left(strcurrent,lentagdesc)=tagdesc then
yxcl =yxcl + 1
temp = 0
desc=1
msgbox("tag")
msgbox("dans 1ere boucle: "&strcurrent)
End if
If temp=1 AND desc <> 1 AND left(strcurrent,lentagdesc)<>tagdesc then
msgbox("desc")
msgbox("dans 2eme boucle :" & strcurrent)
yxcl = yxcl + 1
temp = 0
desc=0
End if
strcurrent = fTxtout.ReadLine()
End Sub |
Partager