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
| Option Explicit
Dim Titre,fso,ws,objIpDictionnary,NewLogFile,strIpAddress,arrAllIpAddresses,MonTableau,Ligne,i,arrUsedIpAddresses
Titre = "Comparer 2 tableaux"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("Wscript.Shell")
Set objIpDictionnary = CreateObject("Scripting.Dictionary")
'Nom du fichier qui va stocker le résultat de la comparaison
NewLogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, ".")) & "txt"
if fso.FileExists(NewLogFile) Then 'Si le fichier LogFile existe
fso.DeleteFile NewLogFile 'alors on le supprime
end If
Ligne = ""
Set arrAllIpAddresses = ReadFile("AllAvailableip.txt")
For Each strIpAddress In arrAllIpAddresses
MonTableau = split(strIpAddress,VbCrLF)
For i = LBound(MonTableau) To UBound(MonTableau)
Ligne = Ligne & MonTableau(i) & VbCrLF
Next
Next
For Each strIpAddress In arrAllIpAddresses
If NOT objIpDictionnary.Exists(strIpAddress) Then objIpDictionnary.Add strIpAddress, " FREE"
Next
Set arrUsedIpAddresses = Readfile("UsedIp.txt")
For Each strIpAddress In arrUsedIpAddresses
If objIpDictionnary.Exists(strIpAddress) Then objIpDictionnary.Item(strIpAddress) = " RESERVED"
Next
For Each strIpAddress In objIpDictionnary.Keys
MsgBox strIpAddress & " " & objIpDictionnary.Item(strIpAddress),64,Titre
Call WriteNewLogFile(strIpAddress & " " & objIpDictionnary.Item(strIpAddress),NewLogFile)
Next
Ws.Run NewLogFile
'*****************************************************************
'Fonction pour écrire le résultat dans un nouveau fichier texte
Sub WriteNewLogFile(strText,NewLogFile)
Dim fs,ts
Const ForAppending = 8
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(NewLogFile,ForAppending,True)
ts.WriteLine strText
ts.Close
End Sub
'*****************************************************************
Function Readfile(strFile)
dim fs,objTextFile,userArrayList,strNextLine
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile(strFile)
Set userArrayList = CreateObject( "System.Collections.ArrayList" )
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
userArrayList.add strNextLine
Loop
objTextFile.Close
set objTextFile = Nothing
set fs = Nothing
set readfile = userArrayList
End function
'***************************************************************** |