#include <GuiConstants.au3>
#include <GuiIPAddress.au3>
#include <Misc.au3>
Global $i
$GUI_SET = GUICreate("Set IP address", 500, 270, -1, -1)
; --- Group -----
$Group1 = GUICtrlCreateGroup("LAN", 10, 10, 230, 190)
$Group2 = GUICtrlCreateGroup("Wi-Fi", 260, 10, 230, 190)
; --- Labals ----
$Label_3 = GUICtrlCreateLabel("Now is :", 20, 40, 40, 20)
$Label_19 = GUICtrlCreateLabel("Now is :", 270, 40, 60, 20)
$Label_13 = GUICtrlCreateLabel("IP", 20, 100, 60, 20)
$Label_14 = GUICtrlCreateLabel("Subnet", 20, 130, 60, 20)
$Label_15 = GUICtrlCreateLabel("Gateway", 20, 160, 60, 20)
$Label_23 = GUICtrlCreateLabel("IP", 270, 100, 60, 20)
$Label_24 = GUICtrlCreateLabel("Subnet", 270, 130, 70, 20)
$Label_25 = GUICtrlCreateLabel("Gateway", 270, 160, 60, 20)
; --- Radios ----
$DhcpLan = GUICtrlCreateRadio("DHCP", 130, 70, 70, 20)
$SetLan = GUICtrlCreateRadio("Set manually", 20, 70, 80, 20)
$DhcpWan = GUICtrlCreateRadio("DHCP", 380, 70, 70, 20)
$SetWan = GUICtrlCreateRadio("Set manually", 270, 70, 80, 20)
; --- Actual IP ----
$IpLanIs = _GUICtrlIpAddress_Create($GUI_SET, 70, 40, 140, 20)
_GUICtrlIpAddress_Set($IpLanIs, @IPAddress1)
$IpWanIs = _GUICtrlIpAddress_Create($GUI_SET, 320, 40, 140, 20)
_GUICtrlIpAddress_Set($IpWanIs, @IPAddress2)
; --- Settings IP ----
$IpLanSet = _GUICtrlIpAddress_Create($GUI_SET, 70, 100, 140, 20)
$SubLan = _GUICtrlIpAddress_Create($GUI_SET, 70, 130, 140, 20)
$GatLan = _GUICtrlIpAddress_Create($GUI_SET, 70, 160, 140, 20)
$IpWanSet = _GUICtrlIpAddress_Create($GUI_SET, 320, 100, 140, 20)
$SubWan = _GUICtrlIpAddress_Create($GUI_SET, 320, 130, 140, 20)
$GatWan = _GUICtrlIpAddress_Create($GUI_SET, 320, 160, 140, 20)
; --- buttons ----
$Set_IP = GUICtrlCreateButton("Set IP", 200, 220, 100, 30)
$Refresh = GUICtrlCreateButton("Refresh", 50, 220, 100, 30)
$Exit = GUICtrlCreateButton("Exit", 350, 220, 100, 30)
;
$StoredIpWanSet = "" ; a record of the last ip value read from the $IpWanSet
$StoredIpLanSet = "" ; a record of the last ip value read from the $IpLanSet
GUISetState()
While 1
Sleep(20)
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg = $Exit Or _IsPressed("1B")
ExitLoop
Case $nMsg = $Refresh
_Refresh()
Case GUICtrlRead($SetLan) = 1 And $Set_IP = $nMsg
$IpLanSeti = _GUICtrlIpAddress_Get($IpLanSet)
$SubLani = _GUICtrlIpAddress_Get($SubLan)
$GatLani = _GUICtrlIpAddress_Get($GatLan)
RunWait(@ComSpec & " /c netsh interface ip set address " & Chr(34) & _Lanlang(1) & Chr(34) & " static " & $IpLanSeti & " " & $SubLani & " " & $GatLani & " 0", "", @SW_HIDE)
MsgBox(32, "Done", "Your LAN is now Set !")
_Refresh()
Case GUICtrlRead($DhcpLan) = 1 And $Set_IP = $nMsg
RunWait(@ComSpec & " /c netsh interface ip set address " & Chr(34) & _Lanlang(1) & Chr(34) & " dhcp", "", @SW_HIDE)
MsgBox(32, "Done", "Your LAN is now in DHCP !")
_Refresh()
Case GUICtrlRead($SetWan) = 1 And $Set_IP = $nMsg
$IpWanSeti = _GUICtrlIpAddress_Get($IpWanSet)
$SubWani = _GUICtrlIpAddress_Get($SubWan)
$GatWani = _GUICtrlIpAddress_Get($GatWan)
RunWait(@ComSpec & " /c netsh interface ip set address " & Chr(34) & _Lanlang(0) & Chr(34) & " static " & $IpWanSeti & " " & $SubWani & " " & $GatWani & " 0", "", @SW_HIDE)
MsgBox(32, "Done", "Your Wi-Fi is now Set !")
_Refresh()
Case GUICtrlRead($DhcpWan) = 1 And $Set_IP = $nMsg
RunWait(@ComSpec & " /c netsh interface ip set address " & Chr(34) & _Lanlang(0) & Chr(34) & " dhcp", "", @SW_HIDE)
MsgBox(32, "Done", "Your Wi-Fi is now in DHCP !")
_Refresh()
Case Not _GUICtrlIpAddress_IsBlank($IpWanSet)
If GUICtrlRead($SetWan, $GUI_UNCHECKED) And $i = 0 Then
$i = 1
GUICtrlSetState($SetWan, $GUI_CHECKED)
EndIf
_GUICtrlIpAddress_Set($SubWan, "255.255.255.0")
$lastIpWanSet = _GUICtrlIpAddress_Get($IpWanSet)
If $lastIpWanSet <> $StoredIpWanSet Then
_GUICtrlIpAddress_Set($GatWan, $lastIpWanSet)
$StoredIpWanSet = $lastIpWanSet
EndIf
Case Not _GUICtrlIpAddress_IsBlank($IpLanSet)
If GUICtrlRead($SetLan, $GUI_UNCHECKED) And $i = 0 Then
$i = 1
GUICtrlSetState($SetLan, $GUI_CHECKED)
EndIf
_GUICtrlIpAddress_Set($SubLan, "255.255.255.0")
$lastIpLanSet = _GUICtrlIpAddress_Get($IpLanSet)
If $lastIpLanSet <> $StoredIpLanSet Then
_GUICtrlIpAddress_Set($GatLan, $lastIpLanSet)
$StoredIpLanSet = $lastIpLanSet
EndIf
EndSelect
WEnd
Exit
;MsgBox(0, "Your OS Language:", _Lanlang())
Func _Lanlang($LAN)
Select
Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang);english
If $LAN = 0 Then
Return "Wireless Network Connection"
Else
Return "Local Area Connection"
EndIf
Case StringInStr("040c,080c,0c0c,100c,140c,180c", @OSLang); frensh
If $LAN = 0 Then
Return "Connexion rйseau sans fil"
Else
Return "Connexion au rйseau local"
EndIf
Case Else
Return "Other (can't determine with @OSLang directly)"
EndSelect
EndFunc
Func _Refresh()
$i = 0
GUICtrlSetState($DhcpLan, $GUI_UNCHECKED)
GUICtrlSetState($SetLan, $GUI_UNCHECKED)
GUICtrlSetState($DhcpWan, $GUI_UNCHECKED)
GUICtrlSetState($SetWan, $GUI_UNCHECKED)
_GUICtrlIpAddress_Set($IpLanIs, @IPAddress1)
_GUICtrlIpAddress_Set($IpWanIs, @IPAddress2)
_GUICtrlIpAddress_ClearAddress($IpLanSet)
_GUICtrlIpAddress_ClearAddress($SubLan)
_GUICtrlIpAddress_ClearAddress($GatLan)
_GUICtrlIpAddress_ClearAddress($IpWanSet)
_GUICtrlIpAddress_ClearAddress($SubWan)
_GUICtrlIpAddress_ClearAddress($GatWan)
EndFunc