In addition to providing a Domain Name Server, domains.google.com provides a Dynamic DNS that allows you to direct your domain or a subdomain to a resource that is behind a gateway with a dynamically assigned IP address. This is documented at https://support.google.com/domains/answer/6147083?hl=en. The API is a simple get or put string of the form
https://username: [email protected]/nic/upda...yourdomain.com&myip=1.2.3.4. If the myip tag is omitted, the system will use the IP of the machine sending the request.
This code sends updates on multiples of hours. You can easily change to code to update on multiples of minutes..
I simply update every 3 hours. It typically responds nochg - no change. You could check to see if your IP has changed before sending an update.
PowerTime is used to go around the clock (i.e. past midnight)..
https://username: [email protected]/nic/upda...yourdomain.com&myip=1.2.3.4. If the myip tag is omitted, the system will use the IP of the machine sending the request.
This code sends updates on multiples of hours. You can easily change to code to update on multiples of minutes..
I simply update every 3 hours. It typically responds nochg - no change. You could check to see if your IP has changed before sending an update.
PowerTime is used to go around the clock (i.e. past midnight)..
Code:
' DDNS updater for domains.google.com ' very simple using google's DDNS API ' ' set to up date every 3 hours ' ' documentation @ https://support.google.com/domains/answer/6147083?hl=en ' expand "Using the API to update your Dynamic DNS record" ' Responses: good = changed and updated, nochg = good inquiry no change, ' plus several responses for bad or malformed inquiries ' ' username and password are provided by domains.google.com #COMPILE EXE #DIM ALL $hostname="mydomainname.com" $Username="myUsername12345" ' get username and password from domains.google.com $Password="myPassword12345" #INCLUDE ONCE "WIN32API.INC" %IDC_LABEL3=1008 %IDC_TEXTBOX1=1009 %IDC_LABEL4=1010 %IDC_FRAME2=1011 %IDC_LABEL5=1012 FUNCTION PBMAIN() ShowDIALOG2 %HWND_DESKTOP END FUNCTION SUB Sleepy(milliseconds AS LONG) 'a better sleep Thanks Mike Doty DIM x AS LONG,Counter AS LONG Counter=(milliseconds\11)+1 'minimum 1 loop (10 milliseconds) FOR x=1 TO Counter DIALOG DOEVENTS SLEEP 10 NEXT END SUB FUNCTION getdata(url AS STRING,uname AS STRING,passw AS STRING) AS STRING LOCAL v1,v2,v3,v4,v5 AS VARIANT LOCAL sTxt AS STRING LOCAL wtxt AS WSTRING DIM objXMLHTTP AS DISPATCH STATIC k AS DWORD INCR k objXMLHTTP=NEWCOM "Msxml2.xmlhttp.3.0" v1="GET" v2=url v3=0 v4=uname v5=passw OBJECT CALL objXMLHTTP.Open(v1,v2,v3,v4,v5) v1="" v2="" v3=EMPTY OBJECT CALL objXMLHTTP.Send OBJECT GET objXMLHTTP.ResponseText TO wTxt sTxt=wTxt ' VARIANT$(v2) FUNCTION=sTxt '-- clean up SET objXMLHTTP=NOTHING v1=EMPTY v2=EMPTY v3=EMPTY v4=EMPTY v5=EMPTY END FUNCTION CALLBACK FUNCTION ShowDIALOG2Proc() SELECT CASE AS LONG CB.MSG CASE %WM_COMMAND SELECT CASE AS LONG CB.CTL CASE %IDC_TEXTBOX1 SLEEPy(50) ' give it time to accept a change END SELECT END SELECT END FUNCTION FUNCTION ShowDIALOG2(BYVAL hParent AS DWORD) AS LONG LOCAL hDlg AS DWORD LOCAL lRslt AS LONG LOCAL hrs AS DWORD LOCAL ix,iy,iloop AS DWORD LOCAL sTxt,sIP,sIPo AS STRING LOCAL t1 AS IPOWERTIME LOCAL t2 AS IPOWERTIME t1=CLASS "POWERTIME" t2=CLASS "POWERTIME" LOCAL lngSign AS LONG LOCAL lngHrs AS LONG LOCAL lngMins AS LONG DIALOG NEW hParent,"Larry's DDNS Client",70,90,199,84,%WS_POPUP OR _ %WS_BORDER OR %WS_DLGFRAME 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_LEFT _ OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR,TO hDlg CONTROL ADD LABEL,hDlg,%IDC_LABEL3,"How often? once every ",10,10,80,10 CONTROL ADD TEXTBOX,hDlg,%IDC_TEXTBOX1,"3",100,10,23,10, _ %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_RIGHT, _ %WS_EX_CLIENTEDGE OR %WS_EX_RIGHT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR CONTROL ADD LABEL,hDlg,%IDC_LABEL4,"hours",130,10,25,10 CONTROL ADD FRAME,hDlg,%IDC_FRAME2,"domains.google.com response",10,25,180,55 CONTROL ADD LABEL,hDlg,%IDC_LABEL5,"",20,40,160,30 CONTROL SET COLOR hDlg,%IDC_LABEL5,%BLACK,%WHITE DIALOG SHOW MODELESS hDlg,CALL ShowDIALOG2Proc TO lRslt iloop=0 sIPo="" DO INCR iloop CONTROL GET TEXT hdlg,%IDC_textbox1 TO sTxt hrs=VAL (sTxt) t1.now ' My IP rarely changes. You might want to use minutes rather than hours t1.Timediff(t2,lngSign,BYVAL 0,lngHrs,lngMins) IF lngHrs=>hrs THEN ' If you want to check for a change before asking google to check, uncomment below. ' sIP=getdata ("https://v4.ident.me/","","") ' your ip as others see you ' IF sIP<>sIPo THEN stxt = $hostname & $TAB & getdata ( "https://domains.google.com/nic/update?hostname=" & $hostname, $Username, $Password) CONTROL SET TEXT hdlg,%IDC_label5,DATE$ & " " & TIME$ & $CRLF & sTxt t2.now ' sIPo=sIP ' END IF END IF sleepy (600) IF iloop>255 THEN SLEEP 0:iloop=0 DIALOG DOEVENTS DIALOG GET SIZE hDlg TO ix,iy LOOP UNTIL ISFALSE (ix*iy) DIALOG END hdlg FUNCTION=lRslt END FUNCTION