Skip to content

Instantly share code, notes, and snippets.

@stevewasiura
Created January 20, 2021 20:54
Show Gist options
  • Select an option

  • Save stevewasiura/21b35f4ed3bb32bdbf940d1bb807b8ae to your computer and use it in GitHub Desktop.

Select an option

Save stevewasiura/21b35f4ed3bb32bdbf940d1bb807b8ae to your computer and use it in GitHub Desktop.
google-domains-dynamic-dns-update.vbs on Microsoft Windows
' This script updates a synthetic DNS record at Google Domains
' Google Dynamic DNS: https://support.google.com/domains/answer/6147083
' Synthetic Records: https://support.google.com/domains/answer/6069273
' set these values
' as displayed in the google domain control panel
' in the synthetic records section
' by clicking the triangle for the Dynamic DNS entry to reveal the UN & PWD
Dim USERNAME : USERNAME="my_googledomains_syntheticrecords_username_credentials"
DIM PASSWORD : PASSWORD="my_googledomains_syntheticrecords_password_credentials"
' Set this to the value of your entry in Google Domains Synthetic records section
DIM HOSTNAME : HOSTNAME="mydyndns.google.com"
' THIS VAR WILL HOLD THE WAN (PUBLIC) IP ADDRESS OF THE COMPUTER RUNING THIS SCRIPT
DIM IPADDRESS : IPADDRESS="0.0.0.0"
' Object to open connection to URL
dim xmlhttp: Set xmlhttp = createobject("MSXML2.XMLHTTP.6.0")
if err.number <> 0 then
wscript.echo "Microsoft.XMLHTTP not installed. Operation aborted."
error_msgs = error_msgs & "Microsoft.XMLHTTP not installed. Operation aborted."
wscript.quit(1)
end if
' config settings to sent to google to get your WAN (Public) IP Address
GoogleWanIPurl = "https://domains.google.com/checkip"
' set URI
xmlhttp.Open "GET", GoogleWanIPurl, False
' send request
xmlhttp.Send
' get result
IPADDRESS = xmlhttp.responseText
' MsgBox("Your WAN (Public) IP Address is " & IPADDRESS)
' config settings to send your WAN (Public) IP Address to Google Dynamic DNS update
GoogleDynIPurl = "https://domains.google.com/nic/update?hostname=" & HOSTNAME & "&myip=" & IPADDRESS
' set URI
xmlhttp.Open "GET", GoogleDynIPurl, False
' set authentication basic
xmlhttp.setRequestHeader "Authorization", "Basic " + Base64Encode(USERNAME + ":" + PASSWORD)
' sent request
xmlhttp.Send
' get result
' MsgBox(xmlhttp.responseText)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' HELPER FUNCTIONS
Function Base64Encode(inData)
'rfc1521
'2001 Antonin Foller, Motobit Software, http://Motobit.cz
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim cOut, sOut, I
'For each group of 3 bytes
For I = 1 To Len(inData) Step 3
Dim nGroup, pOut, sGroup
'Create one long from this 3 bytes.
nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
&H100 * MyASC(Mid(inData, I + 1, 1)) + MyASC(Mid(inData, I + 2, 1))
'Oct splits the long To 8 groups with 3 bits
nGroup = Oct(nGroup)
'Add leading zeros
nGroup = String(8 - Len(nGroup), "0") & nGroup
'Convert To base64
pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)
'Add the part To OutPut string
sOut = sOut + pOut
'Add a new line For Each 76 chars In dest (76*3/4 = 57)
'If (I + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf
Next
Select Case Len(inData) Mod 3
Case 1: '8 bit final
sOut = Left(sOut, Len(sOut) - 2) + "=="
Case 2: '16 bit final
sOut = Left(sOut, Len(sOut) - 1) + "="
End Select
Base64Encode = sOut
End Function
Function MyASC(OneChar)
If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment