Dragonlair Posted July 11, 2011 Posted July 11, 2011 hello to everyone in this wonderful forum, this is my first program written in AutoIt and my first post. its function is to update the IP address in DNS DYNDNS is that there is another dyndns updater forum but mine uses a different process to make the update. I think the code may still be a bit messy or inefficient but still performs well with the target. thank everyone for their criticisms or suggestions will be greatly appreciated. bye sorry for my English. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=icon.ico #AutoIt3Wrapper_Res_Comment=DynDns (TM) Updater #AutoIt3Wrapper_Res_Description=Updates your Dynamic IP on the DYNDNS(R) server automatically. Warning, this software is not an official product of DYNDNS(R). #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Dragonlair 2011 - 2012 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <inet.au3> #Include <string.au3> #include <Constants.au3> If WinExists("Dyndns Auto-Updater") Then Exit EndIf Global $User, $Pass, $Domain, $TimeInput, $EditTime $DefaultTimer = 300 Opt("GUIEventOptions",1) Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) Opt("GUIOnEventMode", 1) TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent") $Form1 = GUICreate("Dyndns Auto-Updater", 276, 182, 0, 0) GUISetOnEvent($GUI_EVENT_CLOSE, "Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize") GUICtrlCreateLabel("UserName", 8, 5, 54, 17) $Input1 = GUICtrlCreateInput("", 8, 20, 257, 21) GUICtrlCreateLabel("Password", 8, 48, 50, 17) $Input2 = GUICtrlCreateInput("", 8, 65, 257, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) GUICtrlCreateLabel("DomainName", 8, 96, 68, 17) $Input3 = GUICtrlCreateInput("", 8, 114, 257, 21) GUICtrlCreateLabel("Time to update", 8, 144, 75, 17) $Label5 = GUICtrlCreateLabel("", 88, 144, 31, 17) GUICtrlSetTip($Label5, "Number in seconds to check for an IP change, click me to change my value") GUICtrlSetOnEvent($Label5, "EditTime") GUICtrlCreateLabel("Seconds.", 120, 144, 49, 17) $Button1 = GUICtrlCreateButton("Update Now", 184, 136, 75, 25) GUICtrlSetOnEvent($Button1, "DNSUpdate") GUICtrlCreateLabel("Status;", 8, 160, 37, 17) $Label8 = GUICtrlCreateLabel("Undefined", 56, 160, 190, 17) $Checkbox1 = GUICtrlCreateCheckbox("Run on startup", 176, 0, 97, 17) GUICtrlSetOnEvent($Checkbox1, "StartupCheckBox") GUISetState(@SW_SHOW) If RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","DynDnsUpdater") Then GUICtrlSetState($Checkbox1, $GUI_CHECKED) If RegRead("HKLM\SOFTWARE\DynDnsUpdater", "TimerSet") Then $DefaultTimer = RegRead("HKLM\SOFTWARE\DynDnsUpdater", "TimerSet") If $CmdLine[0] Then If $CmdLine[1] = "-HIDE" Then Minimize() EndIf If RegRead("HKLM\SOFTWARE\DynDnsUpdater", "UserName") Then $User = RegRead("HKLM\SOFTWARE\DynDnsUpdater", "UserName") $Pass = _StringEncrypt(0,RegRead("HKLM\SOFTWARE\DynDnsUpdater", "Pass"),"7EF12",1) $Domain = RegRead("HKLM\SOFTWARE\DynDnsUpdater", "Domain") GUICtrlSetData($Input1,$User) GUICtrlSetData($Input2,$Pass) GUICtrlSetData($Input3,$Domain) Call ("DNSUpdate") EndIf $i = $DefaultTimer AdlibRegister("Timer",1000) While 1 Sleep(100) WEnd Func EditTime() $EditTime = GUICreate("Input time value", 220, 95, 30, 30) GUICtrlCreateLabel("Please Input the time in seconds to check for an IP change", 8, 8, 204, 25) $TimeInput = GUICtrlCreateInput("12345", 91, 39, 41, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER)) $OK = GUICtrlCreateButton("OK", 72, 64, 75, 25) GUICtrlSetOnEvent($OK, "EditOK") GUISetState(@SW_SHOW) GUICtrlSetData($TimeInput,$DefaultTimer) EndFunc Func EditOK() $DefaultTimer = GUICtrlRead($TimeInput) If $DefaultTimer < 60 then MsgBox(64,"Error","Incorrect number" & @LF & "wrote a number preferably 60 - 3600") Else $i = $DefaultTimer RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "TimerSet", "REG_SZ", $DefaultTimer) GUIDelete($EditTime) EndIf EndFunc Func StartupCheckBox() If GUICtrlRead($Checkbox1) = 1 Then RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "DynDnsUpdater", "REG_SZ", @ScriptDir & "\DynDnsUpdater.exe -HIDE") Else RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","DynDnsUpdater") EndIf EndFunc Func Close() Exit EndFunc Func DNSUpdate() GUICtrlSetState($Button1, $GUI_DISABLE) If $User <> GUICtrlRead($Input1) Or $Pass <> GUICtrlRead($Input2) Or $Domain <> GUICtrlRead($Input3) Then $User = GUICtrlRead($Input1) RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "UserName", "REG_SZ", $User) $Pass = GUICtrlRead($Input2) RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "Pass", "REG_SZ", _StringEncrypt(1,$Pass,"7EF12",1)) $Domain = GUICtrlRead($Input3) RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "Domain", "REG_SZ", $Domain) DYNDNSUpdate() Else CheckIP() EndIf GUICtrlSetState($Button1, $GUI_ENABLE) EndFunc Func CheckIP() GUICtrlSetData($Label8,"Checking IP") GUICtrlSetColor($Label8, 0x0000FF) Sleep(3000) If RegRead("HKLM\SOFTWARE\DynDnsUpdater", "LastIP") <> _GetIP() Then RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "LastIP", "REG_SZ", _GetIP()) DYNDNSUpdate() Else GUICtrlSetData($Label8,"Same IP, no need to update the DNS") GUICtrlSetColor($Label8, 0x008000) $i = $DefaultTimer EndIf EndFunc Func DYNDNSUpdate() GUICtrlSetData($Label8,"Requesting Update :" & _GetIP()) GUICtrlSetColor($Label8, 0x0000FF) $DnsStatement = _InetGetSource("http://" & $User & ":" & $Pass & "@members.dyndns.org/nic/update?hostname=" & $Domain & "&myip=" & _GetIP() & "&wildcard=NOCHG&backmx=NOCHG&mx=NOCHG&system=dyndns") If $DnsStatement = "nochg " & _GetIP() Then GUICtrlSetData($Label8,"DNS update requested successful") GUICtrlSetColor($Label8, 0x008000) EndIf If $DnsStatement = "good " & _GetIP() Then GUICtrlSetData($Label8,"DNS update requested successful") GUICtrlSetColor($Label8, 0x008000) EndIf If $DnsStatement = "nohost" Then GUICtrlSetData($Label8,"Specified hostname does not exist") GUICtrlSetColor($Label8, 0xFF0000) EndIf If $DnsStatement = "badauth" Then GUICtrlSetData($Label8,"Invalid user/password") GUICtrlSetColor($Label8, 0xFF0000) EndIf If $DnsStatement = "abuse" Then GUICtrlSetData($Label8,"Please wait 5 min to next update") GUICtrlSetColor($Label8, 0xFF0000) EndIf If $DnsStatement = "" Then GUICtrlSetData($Label8,"Fill the fields of domain and user password") GUICtrlSetColor($Label8, 0xFF0000) EndIf $i = $DefaultTimer RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "LastIP", "REG_SZ", _GetIP()) EndFunc Func Timer() $i = $i -1 GUICtrlSetData($Label5,$i) If $i = 0 Then Call ("DNSUpdate") $i = $DefaultTimer EndIf EndFunc Func Minimize() GuiSetState(@SW_MINIMIZE) GuiSetState(@SW_HIDE) TraySetState(1) TraySetToolTip ("DynDns Updater - Click here to restore window") Traytip ("DynDns Updater", "Click here to restore window", 5) EndFunc Func SpecialEvent() GuiSetState(@SW_RESTORE) GuiSetState(@SW_Show) TraySetState(2) ; hide EndFunc
Dragonlair Posted July 11, 2011 Author Posted July 11, 2011 also here is the compiled EXE and the source code file http://www.box.net/shared/i5737i19r2sq8m8qmqzkam sorry but I didn't find how to edit the main post
water Posted July 11, 2011 Posted July 11, 2011 You need a post count of at least 5 to change one of your own posts. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Â
Dragonlair Posted November 12, 2011 Author Posted November 12, 2011 I improved a litle bit the code ,some of the improvements are the following.Improved detection of the software is already running using the function <Singleton>IP now is detected based on the domain name and not saving the last value in the registrynow download the tarball with the source code and compiled executableexpandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=icon.ico #AutoIt3Wrapper_Res_Comment=DynDns (TM) Updater #AutoIt3Wrapper_Res_Description=Updates your Dynamic IP on the DYNDNS(R) server automatically. Warning, this software is not an official product of DYNDNS(R). #AutoIt3Wrapper_Res_Fileversion=2.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Dragonlair 2011 - 2012 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <inet.au3> #Include <string.au3> #include <Constants.au3> #Include <Misc.au3> If _Singleton("DYNDNS", 1) = 0 Then Exit EndIf Global $User, $Pass, $Domain, $TimeInput, $EditTime $DefaultTimer = 300 Opt("GUIEventOptions",1) Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) Opt("GUIOnEventMode", 1) TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent") $Form1 = GUICreate("Dyndns Auto-Updater", 276, 182, 0, 0) GUISetOnEvent($GUI_EVENT_CLOSE, "Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize") GUICtrlCreateLabel("UserName", 8, 5, 54, 17) $Input1 = GUICtrlCreateInput("", 8, 20, 257, 21) GUICtrlCreateLabel("Password", 8, 48, 50, 17) $Input2 = GUICtrlCreateInput("", 8, 65, 257, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) GUICtrlCreateLabel("DomainName", 8, 96, 68, 17) $Input3 = GUICtrlCreateInput("", 8, 114, 257, 21) GUICtrlCreateLabel("Time to update", 8, 144, 75, 17) $Label5 = GUICtrlCreateLabel("", 88, 144, 31, 17) GUICtrlSetTip($Label5, "Number in seconds to check for an IP change, click me to change my value") GUICtrlSetOnEvent($Label5, "EditTime") GUICtrlCreateLabel("Seconds.", 120, 144, 49, 17) $Button1 = GUICtrlCreateButton("Update Now", 184, 136, 75, 25) GUICtrlSetOnEvent($Button1, "DNSUpdate") GUICtrlCreateLabel("Status;", 8, 160, 37, 17) $Label8 = GUICtrlCreateLabel("Undefined", 56, 160, 190, 17) $Checkbox1 = GUICtrlCreateCheckbox("Run on startup", 176, 0, 97, 17) GUICtrlSetOnEvent($Checkbox1, "StartupCheckBox") GUISetState(@SW_SHOW) If RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","DynDnsUpdater") Then GUICtrlSetState($Checkbox1, $GUI_CHECKED) If RegRead("HKLM\SOFTWARE\DynDnsUpdater", "TimerSet") Then $DefaultTimer = RegRead("HKLM\SOFTWARE\DynDnsUpdater", "TimerSet") If $CmdLine[0] Then If $CmdLine[1] = "-HIDE" Then Minimize() EndIf If RegRead("HKLM\SOFTWARE\DynDnsUpdater", "UserName") Then $User = RegRead("HKLM\SOFTWARE\DynDnsUpdater", "UserName") $Pass = _StringEncrypt(0,RegRead("HKLM\SOFTWARE\DynDnsUpdater", "Pass"),"7EF12",1) $Domain = RegRead("HKLM\SOFTWARE\DynDnsUpdater", "Domain") GUICtrlSetData($Input1,$User) GUICtrlSetData($Input2,$Pass) GUICtrlSetData($Input3,$Domain) Call ("DNSUpdate") EndIf $i = $DefaultTimer AdlibRegister("Timer",1000) While 1 Sleep(100) WEnd Func EditTime() $EditTime = GUICreate("Input time value", 220, 95, 30, 30) GUICtrlCreateLabel("Please Input the time in seconds to check for an IP change", 8, 8, 204, 25) $TimeInput = GUICtrlCreateInput("12345", 91, 39, 41, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER)) $OK = GUICtrlCreateButton("OK", 72, 64, 75, 25) GUICtrlSetOnEvent($OK, "EditOK") GUISetState(@SW_SHOW) GUICtrlSetData($TimeInput,$DefaultTimer) EndFunc Func EditOK() $DefaultTimer = GUICtrlRead($TimeInput) If $DefaultTimer < 60 then MsgBox(64,"Error","Incorrect number" & @LF & "wrote a number preferably 60 - 3600") Else $i = $DefaultTimer RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "TimerSet", "REG_SZ", $DefaultTimer) GUIDelete($EditTime) EndIf EndFunc Func StartupCheckBox() If GUICtrlRead($Checkbox1) = 1 Then RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "DynDnsUpdater", "REG_SZ", @ScriptDir & "\DynDnsUpdater.exe -HIDE") Else RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","DynDnsUpdater") EndIf EndFunc Func Close() Exit EndFunc Func DNSUpdate() GUICtrlSetState($Button1, $GUI_DISABLE) If $User <> GUICtrlRead($Input1) Or $Pass <> GUICtrlRead($Input2) Or $Domain <> GUICtrlRead($Input3) Then $User = GUICtrlRead($Input1) RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "UserName", "REG_SZ", $User) $Pass = GUICtrlRead($Input2) RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "Pass", "REG_SZ", _StringEncrypt(1,$Pass,"7EF12",1)) $Domain = GUICtrlRead($Input3) RegWrite("HKLM\SOFTWARE\DynDnsUpdater", "Domain", "REG_SZ", $Domain) DYNDNSUpdate() Else CheckIP() EndIf GUICtrlSetState($Button1, $GUI_ENABLE) EndFunc Func CheckIP() GUICtrlSetData($Label8,"Checking IP") GUICtrlSetColor($Label8, 0x0000FF) Sleep(3000) TCPStartup() If TCPNameToIP($Domain) <> _GetIP() Then DYNDNSUpdate() Else GUICtrlSetData($Label8,"Same IP, no need to update the DNS") GUICtrlSetColor($Label8, 0x008000) $i = $DefaultTimer EndIf EndFunc Func DYNDNSUpdate() GUICtrlSetData($Label8,"Requesting Update :" & _GetIP()) GUICtrlSetColor($Label8, 0x0000FF) $DnsStatement = _InetGetSource("http://" & $User & ":" & $Pass & "@members.dyndns.org/nic/update?hostname=" & $Domain & "&myip=" & _GetIP() & "&wildcard=NOCHG&backmx=NOCHG&mx=NOCHG&system=dyndns") Switch $DnsStatement Case "nochg " & _GetIP() GUICtrlSetData($Label8,"DNS update requested successful") GUICtrlSetColor($Label8, 0x008000) Case "good " & _GetIP() GUICtrlSetData($Label8,"DNS update requested successful") GUICtrlSetColor($Label8, 0x008000) Case "nohost" GUICtrlSetData($Label8,"Specified hostname does not exist") GUICtrlSetColor($Label8, 0xFF0000) Case "badauth" GUICtrlSetData($Label8,"Invalid user/password") GUICtrlSetColor($Label8, 0xFF0000) Case "abuse" GUICtrlSetData($Label8,"Please wait 5 min to next update") GUICtrlSetColor($Label8, 0xFF0000) Case Else GUICtrlSetData($Label8,"Fill the fields of domain and user password") GUICtrlSetColor($Label8, 0xFF0000) EndSwitch $i = $DefaultTimer EndFunc Func Timer() $i = $i -1 GUICtrlSetData($Label5,$i) If $i = 0 Then Call ("DNSUpdate") $i = $DefaultTimer EndIf EndFunc Func Minimize() GuiSetState(@SW_MINIMIZE) GuiSetState(@SW_HIDE) TraySetState(1) TraySetToolTip ("DynDns Updater - Click here to restore window") Traytip ("DynDns Updater", "Click here to restore window", 5) EndFunc Func SpecialEvent() GuiSetState(@SW_RESTORE) GuiSetState(@SW_Show) TraySetState(2) ; hide EndFunc
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now