Comments: https://forum.powerbasic.com/forum/u...address-helper
A new gigabit service allows home servers for business, but does not provide static ip addresses.
This gets around infrequent checks by a provided dns checker's software from a third-party ddns service.
This polls your choice of server page and shells if page not found to the dns checker to update your public ip address then kills the checker.
It can also automatically start a web server if needed.
A new gigabit service allows home servers for business, but does not provide static ip addresses.
This gets around infrequent checks by a provided dns checker's software from a third-party ddns service.
This polls your choice of server page and shells if page not found to the dns checker to update your public ip address then kills the checker.
It can also automatically start a web server if needed.
Code:
'Better duration control updating a dynamic ddns service to update public ip address. 'DDNS provider may not allow their $DNSCheckerProgram to check very often. 'With this method you poll your own server to see if it is available. 'The DDNS providers $DNSCheckerProgram is started, given a second to update then killed. 'The program will also restart your server if it isn't running. 'A small toolwindow and close [X] is displayed 'Comment and suggestions https://forum.powerbasic.com/forum/user-to-user-discussions/programming/826437-comments-set-public-ip-address-helper ' 'Logic: 'DO ' IF $WebPageToFind not found (on your server) THEN ' pid=shell($DNSCheckerProgram) and give it a few seconds to UPDATE PUBLIC IP ' pid=shell(taskkill $DNSCheckerProgram) ' pid=shell($WebServer) ' SLEEP %RecheckInMilliseconds ' END IF 'LOOP UNTIL DoneHavingFun #PBFORMS CREATED V2.01 #COMPILE EXE 'Jose Roca includes 9/8/23 by Mike Doty #DIM ALL #INCLUDE "\roca\MSXML.INC" 'where you keep them $WebPageToFind = "https://" 'change this $DNSCheckerProgram = "C:\Program Files (x86)\No-IP\DUC40.exe" 'change this $WebServer = "C:\abyss\abyssws.exe" 'optional change this %RecheckInMilliseconds = 60000 'change this %BeepBeforeEveryCheck = 1 'change to 0 when done testing GLOBAL ghDlg,gEndFlag AS DWORD #PBFORMS BEGIN INCLUDES #PBFORMS END INCLUDES #PBFORMS BEGIN CONSTANTS %IDD_DIALOG1 = 101 #PBFORMS END CONSTANTS DECLARE CALLBACK FUNCTION ShowDIALOG1Proc() DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG #PBFORMS DECLARATIONS FUNCTION PBMAIN() ShowDIALOG1 %HWND_DESKTOP END FUNCTION '===================================================================== CALLBACK FUNCTION ShowDIALOG1Proc() SELECT CASE AS LONG CB.MSG CASE %WM_INITDIALOG LOCAL hThread AS LONG ghDlg = CB.HNDL screensettings 0 THREAD CREATE Checker(0) TO hThread THREAD CLOSE hThread TO hThread CASE %WM_COMMAND SELECT CASE AS LONG CB.CTL END SELECT CASE %WM_SYSCOMMAND screensettings 1 'save screen settings gEndFlag = 1 postquitmessage 0 'use with Jose Roca includes END SELECT END FUNCTION '===================================================================== FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG #PBFORMS BEGIN DIALOG %IDD_DIALOG1->-> LOCAL hDlg AS DWORD DIALOG NEW hParent, "", 50, 50, 70, 0, %WS_POPUP OR %WS_BORDER OR _ %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _ %WS_EX_TOOLWINDOW OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg #PBFORMS END DIALOG 'DIALOG SHOW STATE hDlg, %SW_MINIMIZE 'optional start minimized DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt FUNCTION = lRslt END FUNCTION '===================================================================== THREAD FUNCTION Checker(BYVAL NotUsed AS DWORD) AS LONG LOCAL wsFind,wsResult AS WSTRING, s AS STRING LOCAL pid AS DWORD, x AS LONG DO DIALOG SET TEXT ghDlg,"Ck IP " + TIME$:SLEEP 250 IF %BeepBeforeEveryCheck THEN BEEP:SLEEP 1000 wsFind = $WebPageToFind wsResult= GetRemoteData(wsFind) IF LEN(wsResult) = 0 THEN 'Site not found so update dynamic dns server pid = SHELL($DNSCheckerProgram) 'must be asynchronous! s = STR$(pid) 'give dynamic dns server some time to update address(es) then kill it SLEEP 5000 pid = SHELL(ENVIRON$("COMSPEC") + " /C taskkill.exe /f /pid " + s,0) 'asynchronous! IF LEN($WebServer) THEN pid = SHELL($WebServer,0) 'optional must be asynchronous! END IF SLEEP %RecheckInMilliseconds 'recheck if remote file is found LOOP UNTIL gEndFlag FOR x = 1 TO 3:BEEP:SLEEP 1000:NEXT 'optional get rid of it 'Dialog End ghDlg 'cant be used in another thread DIALOG SEND ghDlg, %WM_SYSCOMMAND, %SC_CLOSE, 0 END FUNCTION '===================================================================== FUNCTION GetRemoteData(wsUrl AS WSTRING) AS WSTRING DIM sMethod AS WSTRING DIM oXml AS IServerXMLHTTPRequest2 SET oXml = NEWCOM "MsXml2.ServerXMLHTTP.6.0" sMethod = "GET" IF ISTRUE(ISOBJECT(oXml)) THEN oXml.Open(sMethod, wsURL, %FALSE) oXml.Send() DO WHILE oXml.ReadyState<>4 SLEEP 0 EXIT FUNCTION LOOP FUNCTION= oXml.ResponseText ELSE ? "Unable to get oXml version",%MB_SYSTEMMODAL,FUNCNAME$ END IF END FUNCTION '===================================================================== FUNCTION ScreenSettings(Read0_Write1 AS LONG) AS LONG 'Call ScreenSettings 0 in %WM_INITDIALOG (read settings) 'Call ScreenSettings 1 in %WM_SYSCOMMAND (save settings) LOCAL x,y,nWide,nHigh,ShowState, h AS LONG, sFileName AS STRING sFileName = EXE.FULL$ + "." + LCASE$(ComputerName2) + ".txt" 'READ SETTINGS PUT IN WM_INITDIALOG IF Read0_Write1 = 0 THEN 'read from disk IF ISFILE(sFileName) THEN 'file found h = FREEFILE 'get handle OPEN sFileName FOR INPUT SHARED AS #h 'open for input INPUT #h, x,y,nWide,nHigh 'read location/size CLOSE #h 'close parameter file DIALOG SET LOC ghDlg, x,y 'locate dialog 'mike august 2019 DIALOG SET SIZE ghDlg,nWide,nHigh 'size dialog 'mike august 2019 END IF EXIT FUNCTION END IF 'SAVE SETTINGS 'IF ISFALSE(IsIconic(ghDlg) OR IsZoomed(ghDlg)) THEN '------- Save location, size and other parameters -------- DIALOG GET SIZE ghDlg TO nWide, nHigh 'get last size DIALOG GET LOC ghDlg TO x&, y& 'get last location h = FREEFILE 'get file handle OPEN sFileName FOR OUTPUT AS #h 'open parameter file WRITE #h, x,y,nWide,nHigh 'write location/size CLOSE #h 'close file END FUNCTION '===================================================================== FUNCTION ComputerName2 AS STRING LOCAL zBuffer AS ASCIIZ * 16 GetComputerNameA zBuffer,%MAX_COMPUTERNAME_LENGTH FUNCTION = zBuffer END FUNCTION
Comment