-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImportDHCP.au3
More file actions
67 lines (51 loc) · 1.91 KB
/
ImportDHCP.au3
File metadata and controls
67 lines (51 loc) · 1.91 KB
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
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=_Icon.ico
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <FileConstants.au3>
#include <Process.au3>
#include "CommonFunctions.au3"
Global $LogToFile = True
$Title = "Import reservations to DHCP server"
_ConsoleWrite("Start - " & $Title)
$File = FileOpenDialog ($Title, "", "Typical (*.txt;*.csv)|All (*.*)", $FD_FILEMUSTEXIST)
If @error Then Exit
$aLines = FileReadToArray ($File)
If @error Then Exit
For $i = 0 To UBound($aLines)-1 ; Loop lines read from file
If $aLines[$i] = "" Or StringLeft($aLines[$i],1) = "#" Then ContinueLoop
$aSplitLine = _StringSplitQ($aLines[$i])
If UBound($aSplitLine) <> 12 Then
Msgbox(0, $Title, "Error in file on line "&$i)
_ArrayDisplay($aSplitLine)
Exit
EndIf
Next
_ConsoleWrite("Record Count: " & UBound($aLines))
If MsgBox(1, $Title, UBound($aLines)&" lines in file, all with correct value count, continue?") <> 1 Then Exit
For $i = 0 To UBound($aLines)-1
If $aLines[$i] = "" Or StringLeft($aLines[$i],1) = "#" Then ContinueLoop
$aSplitLine = _StringSplitQ($aLines[$i])
$Server = $aSplitLine[4]
$Scope = $aSplitLine[2]
$IP = $aSplitLine[3]
$MAC = $aSplitLine[4]
$Name = $aSplitLine[5]
$Description = $aSplitLine[6]
$IP = $aSplitLine[3]
$MAC = StringReplace($MAC, "-", "")
$MAC = StringReplace($MAC, ":", "")
$RunLine = "netsh dhcp server "&$Server&" scope "&$Scope&" add reservedip "&$IP&" "&$MAC&" """&$Name&""" """&$Description&""" ""BOTH"""
_ConsoleWrite($RunLine)
_RunDos ($RunLine)
Next
Msgbox(0, $Title, "Done.")
Func _StringSplitQ($String)
$Split = StringRegExp($String, '["].*?["]|[^ ]+', $STR_REGEXPARRAYGLOBALMATCH)
For $i = 0 To UBound($Split)-1
If StringLeft($Split[$i], 1) = """" AND StringRight($Split[$i], 1) = """" Then
$Split[$i] = StringTrimLeft(StringTrimRight($Split[$i], 1), 1)
EndIf
Next
Return $Split
EndFunc