Created
May 31, 2018 16:23
-
-
Save J2TEAM/e4e5a69e46b7d2e6a88955177c9f5881 to your computer and use it in GitHub Desktop.
Fast configuration switching between static and dynamic IP address.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoTrayIcon | |
#RequireAdmin | |
#Region AutoIt3Wrapper directives section | |
#AutoIt3Wrapper_Icon=juno_okyo.ico | |
#AutoIt3Wrapper_Compression=4 | |
#AutoIt3Wrapper_UseUpx=Y | |
#AutoIt3Wrapper_Compile_both=Y ;=> Compile both X86 and X64 in one run | |
#AutoIt3Wrapper_Res_Comment=Developed by Juno_okyo | |
#AutoIt3Wrapper_Res_Description=Developed by Juno_okyo | |
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0 | |
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=Y | |
#AutoIt3Wrapper_Res_ProductVersion=1.0.0.0 ;=>Edit | |
#AutoIt3Wrapper_Res_LegalCopyright=(C) 2018 J2TEAM. All rights reserved. | |
#AutoIt3Wrapper_Res_Field=InternalName|%scriptfile%.exe ;=>Edit | |
#AutoIt3Wrapper_Res_Field=OriginalFilename|%scriptfile%.exe ;=>Edit | |
#AutoIt3Wrapper_Res_Field=ProductName|%scriptfile% ;=>Edit | |
#AutoIt3Wrapper_Res_Field=CompanyName|J2TEAM | |
#AutoIt3Wrapper_Res_Field=Website|https://junookyo.blogspot.com/ | |
#EndRegion AutoIt3Wrapper directives section | |
#include <ButtonConstants.au3> | |
#include <GUIConstantsEx.au3> | |
#include <GuiIPAddress.au3> | |
#include <StaticConstants.au3> | |
#include <WindowsConstants.au3> | |
#Region ### START Koda GUI section ### Form= | |
Global $Form1 = GUICreate('Auto IP Config', 458, 448) | |
GUISetFont(12, 400, 0, 'Segoe UI') | |
Global $Group1 = GUICtrlCreateGroup('Use the following IP address', 24, 16, 409, 193) | |
Global $Label1 = GUICtrlCreateLabel('IP address:', 39, 58, 78, 25) | |
Global $IPAddress1 = _GUICtrlIpAddress_Create($Form1, 176, 56, 230, 25) | |
_GUICtrlIpAddress_Set($IPAddress1, '192.168.72.19') | |
Global $Label2 = GUICtrlCreateLabel('Subnet mask:', 39, 108, 97, 25) | |
Global $IPAddress2 = _GUICtrlIpAddress_Create($Form1, 176, 106, 230, 25) | |
_GUICtrlIpAddress_Set($IPAddress2, '255.255.255.0') | |
Global $Label3 = GUICtrlCreateLabel('Default gateway:', 39, 158, 119, 25) | |
Global $IPAddress3 = _GUICtrlIpAddress_Create($Form1, 176, 156, 230, 25) | |
_GUICtrlIpAddress_Set($IPAddress3, '192.168.72.251') | |
GUICtrlCreateGroup('', -99, -99, 1, 1) | |
Global $Group2 = GUICtrlCreateGroup('Use the following DNS server addresses', 24, 232, 409, 145) | |
Global $Label4 = GUICtrlCreateLabel('Preferred DNS server:', 39, 274, 155, 25) | |
Global $IPAddress4 = _GUICtrlIpAddress_Create($Form1, 208, 272, 195, 25) | |
_GUICtrlIpAddress_Set($IPAddress4, '1.1.1.1') | |
Global $Label5 = GUICtrlCreateLabel('Alternate DNS server:', 39, 324, 153, 25) | |
Global $IPAddress5 = _GUICtrlIpAddress_Create($Form1, 208, 322, 195, 25) | |
_GUICtrlIpAddress_Set($IPAddress5, '1.0.0.1') | |
GUICtrlCreateGroup('', -99, -99, 1, 1) | |
Global $Radio1 = GUICtrlCreateRadio('Home', 24, 402, 113, 17) | |
GUICtrlSetCursor(-1, 0) | |
GUICtrlSetState(-1, $GUI_CHECKED) | |
Global $Radio2 = GUICtrlCreateRadio('Company', 144, 402, 113, 17) | |
GUICtrlSetCursor(-1, 0) | |
Global $Button1 = GUICtrlCreateButton('Save Config', 288, 398, 145, 34) | |
GUICtrlSetCursor(-1, 0) | |
GUICtrlSetState(-1, $GUI_DEFBUTTON) | |
GUISetState(@SW_SHOW) | |
#EndRegion ### END Koda GUI section ### | |
While 1 | |
Local $nMsg = GUIGetMsg() | |
Switch $nMsg | |
Case $GUI_EVENT_CLOSE | |
Exit | |
Case $Button1 | |
Local $state = GUICtrlRead($Radio1) | |
Local $ip1 = _GUICtrlIpAddress_Get($IPAddress1) | |
Local $ip2 = _GUICtrlIpAddress_Get($IPAddress2) | |
Local $ip3 = _GUICtrlIpAddress_Get($IPAddress3) | |
Local $ip4 = _GUICtrlIpAddress_Get($IPAddress4) | |
Local $ip5 = _GUICtrlIpAddress_Get($IPAddress5) | |
If $state == 1 Then | |
; Home | |
ShellExecuteWait('netsh', 'interface ipv4 set address name="Ethernet" dhcp', Default, Default, @SW_HIDE) | |
ShellExecuteWait('netsh', 'interface ip add dns name="Ethernet" addr=' & $ip4 & ' index=1', Default, Default, @SW_HIDE) | |
ShellExecuteWait('netsh', 'interface ip add dns name="Ethernet" addr=' & $ip5 & ' index=2', Default, Default, @SW_HIDE) | |
Else | |
; Company | |
ShellExecuteWait('netsh', 'interface ipv4 set address name="Ethernet" static ' & $ip1 & ' ' & $ip2 & ' ' & $ip3, Default, Default, @SW_HIDE) | |
ShellExecuteWait('netsh', 'interface ipv4 set dnsservers "Ethernet" source=dhcp', Default, Default, @SW_HIDE) | |
EndIf | |
MsgBox(64 + 262144, 'Message', 'Done!', 0, $Form1) | |
EndSwitch | |
WEnd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment