64 lines
2.6 KiB
AutoIt
64 lines
2.6 KiB
AutoIt
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
|
|
#AutoIt3Wrapper_UseUpx=n
|
|
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
|
|
Global $lokaleIP
|
|
Global $NeuerDNS1 = "192.168.1.15"
|
|
Global $NeuerDNS2 = "192.168.1.16"
|
|
|
|
$lokaleIP = @IPAddress1
|
|
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '@IPAddress1' & @lf & @lf & 'Return:' & @lf & @IPAddress1) ;### Debug MSGBOX
|
|
|
|
If @IPAddress1 <> "0.0.0.0" Then
|
|
_Set_DNS(@IPAddress1, $NeuerDNS1, $NeuerDNS2)
|
|
MsgBox(0,"","Fehlercode: " & @error)
|
|
EndIf
|
|
If @IPAddress2 <> "0.0.0.0" Then
|
|
_Set_DNS(@IPAddress2, $NeuerDNS1, $NeuerDNS2)
|
|
EndIf
|
|
If @IPAddress2 <> "0.0.0.0" Then
|
|
_Set_DNS(@IPAddress2, $NeuerDNS1, $NeuerDNS2)
|
|
EndIf
|
|
If @IPAddress2 <> "0.0.0.0" Then
|
|
_Set_DNS(@IPAddress2, $NeuerDNS1, $NeuerDNS2)
|
|
EndIf
|
|
|
|
Exit 0
|
|
|
|
|
|
;===============================================================================
|
|
; Function Name: _Set_DNS($Card_IP, $DNS_1=-1, $DNS_2=-1, $strComputer = ".")
|
|
; Description:: Eine od. beide DNS-Adressen für Netzwerkadapter mit übergebener IP setzen
|
|
; Parameter(s): $Card_IP IP des Netzwerkadapters
|
|
; $DNS_1 IP für DNS1 (-1 Adresse wird nicht gesetzt)
|
|
; $DNS_2 IP für DNS2 (-1 Adresse wird nicht gesetzt)
|
|
; $strComputer "." - der lokale PC
|
|
; Return Value(s): Erfolg Array mit [DNS1,DNS2]
|
|
; Fehler 0 @error 1 - keine DNS_IP übergeben
|
|
; @error 2 - Adapter_IP existiert nicht
|
|
; Author(s): BugFix (bugfix@autoit.de)
|
|
;===============================================================================
|
|
Func _Set_DNS($Card_IP, $DNS_1=-1, $DNS_2=-1, $strComputer = ".")
|
|
If ($DNS_1 = -1) And ($DNS_2 = -1) Then Return SetError(1,0,0)
|
|
Local $objWMIService = ObjGet("winmgmts:" _
|
|
& "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
|
|
Local $colNetCards = $objWMIService.ExecQuery _
|
|
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
|
|
For $objNetCard In $colNetCards
|
|
|
|
MsgBox(0,"","hier: " & $objNetCard.IPAddress(0))
|
|
|
|
|
|
If $objNetCard.IPAddress(0) = $Card_IP Then
|
|
;MsgBox(0,"","dns")
|
|
If $DNS_1 <> -1 Then
|
|
$objNetCard.DNSServerSearchOrder(0) = $DNS_1
|
|
EndIf
|
|
If $DNS_2 <> -1 Then
|
|
$objNetCard.DNSServerSearchOrder(1) = $DNS_2
|
|
EndIf
|
|
Local $aReturn[2] = [$objNetCard.DNSServerSearchOrder(0), $objNetCard.DNSServerSearchOrder(1)]
|
|
Return $aReturn
|
|
EndIf
|
|
Next
|
|
Return SetError(2,0,0)
|
|
EndFunc ;==>_Set_DNS |