Here a GUI to enter the needed IP information.
;fast hack by UEZ 2013
#include <Array.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
Global Const $oMyError = ObjEvent("AutoIt.Error", "oMyError") ; Install a custom error handler
$hGUI = GUICreate("IP Test", 423, 123)
GUISetFont(9, 400, 0, "Arial")
TrayTip("Information", "Reading network setting. Please wait...", 10, 1)
$aNetworkAdapters = _WMI_GetNetworkAdapterNames()
TrayTip("", "",0)
$iComboBox = GUICtrlCreateCombo("", 220, 15, 180, 20, $CBS_DROPDOWN + $CBS_AUTOHSCROLL)
Global $sNetworkAdapters, $z
For $z = 0 To UBound($aNetworkAdapters) - 1
$sNetworkAdapters &= $aNetworkAdapters[$z][0] & "|"
Next
GUICtrlSetData($iComboBox, StringTrimRight($sNetworkAdapters, 1), $aNetworkAdapters[0][0])
$sCurrentIP = GUICtrlCreateLabel("Current IP:", 16, 18, 62, 19, $SS_RIGHT)
$hCurrenIP = _GUICtrlIpAddress_Create($hGUI, 84, 16, 130, 21)
_GUICtrlIpAddress_Set($hCurrenIP, $aNetworkAdapters[0][1])
$sNewIP = GUICtrlCreateLabel("New IP:", 16, 53, 62, 19, $SS_RIGHT)
$hNewIP = _GUICtrlIpAddress_Create($hGUI, 84, 51, 130, 21)
_GUICtrlIpAddress_Set($hNewIP, "0.0.0.0")
$sDefaultGateway = GUICtrlCreateLabel("Gateway:", 16, 85, 62, 19, $SS_RIGHT)
$hDefaultGateway = _GUICtrlIpAddress_Create($hGUI, 84, 83, 130, 21)
_GUICtrlIpAddress_Set($hDefaultGateway, "0.0.0.254")
$iBtnOK = GUICtrlCreateButton("OK", 232, 80, 75, 25)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUIRegisterMsg($WM_NOTIFY, "")
GUIDelete()
Exit
Case $iBtnOK
MsgBox(0, "Test", "Interface Name: " & $aNetworkAdapters[_ArraySearch($aNetworkAdapters, GUICtrlRead($iComboBox))][0] & @CRLF & _
"New IP: " & _GUICtrlIpAddress_Get($hNewIP) & @CRLF & _
"Default Gateway: " & _GUICtrlIpAddress_Get($hDefaultGateway))
Case $iComboBox
_GUICtrlIpAddress_Set($hCurrenIP, $aNetworkAdapters[_ArraySearch($aNetworkAdapters, GUICtrlRead($iComboBox))][1])
EndSwitch
WEnd
Func _WMI_GetNetworkAdapterNames($sHost = ".")
If $sHost = "." Then $sHost = @ComputerName
Local $objWMI= ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sHost & "\root\cimv2")
Local $oItems1 = $objWMI.InstancesOf("Win32_NetworkAdapter WHERE NetEnabled=TRUE")
Local $oItems2, $oTokens1, $oTokens2, $aIP, $sIPAddresses, $aResult[100][2], $i = 0
For $oTokens1 In $oItems1
$aResult[$i][0] = $oTokens1.NetConnectionID
$oItems2 = $objWMI.InstancesOf('Win32_NetworkAdapterConfiguration WHERE Description="' & $oTokens1.Name & '"')
For $oTokens2 In $oItems2
$aIP = $oTokens2.IPAddress
For $j = 0 To UBound($aIP) - 1
If StringRegExp($aIP[$j], "(\d+\.\d+\.\d+\.\d+)", 0) Then $aResult[$i][1] = $aIP[$j]
Next
$i += 1
Next
Next
If $i > 0 Then
ReDim $aResult[$i][2]
Return $aResult
EndIf
Return SetError(1, 0, 0)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR
Local $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hNewIP
Switch $iCode
Case $IPN_FIELDCHANGED
Local $aIP = _GUICtrlIpAddress_GetArray($hNewIP)
$aIP[3] = "254"
_GUICtrlIpAddress_SetArray($hDefaultGateway, $aIP)
EndSwitch
Case $hDefaultGateway
Switch $iCode
Case $IPN_FIELDCHANGED
Local $aIP = _GUICtrlIpAddress_GetArray($hDefaultGateway)
$aIP[3] = "254"
_GUICtrlIpAddress_SetArray($hDefaultGateway, $aIP)
EndSwitch
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_NOTIFY
Func oMyError()
ConsoleWrite( @CRLF & @CRLF & _
"We intercepted a COM Error !" & @CRLF & @CRLF & _
"err.description is: " & @TAB & $oMyError.Description & @CRLF & _
"err.windescription:" & @TAB & $oMyError.WinDescription & @CRLF & _
"err.number is: " & @TAB & Hex($oMyError.Number, 8) & @CRLF & _
"err.lastdllerror is: " & @TAB & $oMyError.LastDllError & @CRLF & _
"err.scriptline is: " & @TAB & $oMyError.Scriptline & @CRLF & _
"err.source is: " & @TAB & $oMyError.Source & @CRLF & _
"err.helpfile is: " & @TAB & $oMyError.Helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oMyError.HelpContext & @CRLF & @CRLF)
EndFunc
To do: apply settings / save it to a ini file.
Br,
UEZ