Dynamisk IP (DDNS)
Såfremt du har dynamisk IP og ønsker at benytte GratisDNS til at hoste dit website, FTP eller hvad det nu måtte være, kan du evt. bruge dette script til at vedligeholde din IP hos GratisDNS.
BEMÆRK: Har du ikke allerede gjort det, så skal du oprette et DDNS kodeord, dette gøres på kontrolpanelet under Bruger → Indstillinger → Ændre logindata.
BEMÆRK: Vi yder ingen support på scripts på denne side, da disse scripts ikke er lavet af os.
Hvis du vil kalde vores DDNS service direkte, kan du lave en URL til det her.
Windows
Det du skal gøre er følgende:
- Kopier koden herunder.
- Start Notesblok og indsætte koden.
- Gem Filen som GratisDNS.vbs på C drevet.
- Ændre dine (GratisDNS) bruger informationer i bunden af koden.
- Klik på start→Alle Programmer→Tilbehør→system værktøjer og klikke på Planlagte Opgaver
- Dobbelt klik på Planlæg ny opgave
- klik på Næste
- Klik på Gennemse… og navigere til C:\Windows\System32\cscript.exe og klik Åbn
- Markere Feltet Når min computer starter og klik på Næste
- Udfyld bruger informationer og klik på Næste
- Markere Åben avancerede egenskaber… og klik på Udfør
- Under Fanebladet Job i feltet Kør: skriver du følgende: C:\WINDOWS\system32\cscript.exe C:\GratisDNS.vbs //B
Sådan nu har du oprettet en opgave som kører 1 gang, hver gang computeren starter. Opgaven køre VBS filen som sender din nye IP addresse til GratisDNS.
Du kan selv tilrette hvor ofte opgaven skal køre, f.eks. hver 3. time.
'################################################################################## 'Udviklet af Paw Jershauge for indlæg på div. coding sites... 'Se eventuelt mere på www.XplainVB.dk eller www.XplainASP.dk '################################################################################## '---------------------------------------------------------------------------------- Function binToText(varBinData, intDataSizeInBytes) Const adFldLong = &H80 Const adVarChar = 200 Set objRS = CreateObject("ADODB.Recordset") objRS.Fields.Append "txt", adVarChar, intDataSizeInBytes, adFldLong objRS.Open objRS.AddNew objRS.Fields("txt").AppendChunk varBinData binToText = objRS("txt").value objRS.Close Set objRS = Nothing End Function '---------------------------------------------------------------------------------- Function GetURL(URL,method,ReturnData) on error resume next set xmlhttp = CreateObject(method) if method="MSXML2.ServerXMLHTTP.4.0" and ProxyAddress<>"" then xmlhttp.setProxy 0,ProxyAddress,"" if proxyusername<>"" then xmlhttp.setProxyCredentials proxyusername, proxypassword end if end if xmlhttp.open "GET", URL, false if method="Microsoft.XMLHTTP" then xmlhttp.send else xmlhttp.send() end if ReturnData = binToText(xmlhttp.responseBody, 100000) if err.number <> 0 then GetURL=false response.end else GetURL=true end if set xmlhttp = nothing End Function '----------------------------------------------------------------------------------- Function GetUrlData(Url,ReturnData) Dim methods(3) methods(2)="MSXML2.ServerXMLHTTP.4.0" methods(1)="MSXML2.ServerXMLHTTP.3.0" methods(0)="MSXML2.ServerXMLHTTP" methods(3)="Microsoft.XMLHTTP" success=false Err = 0 for each method in methods if GetURL(Url,method,ReturnData) then If Not 0 = Err Then GetUrlData = False else GetUrlData = True exit for end if end if Err=0 next end function '------------------------------------------------------------------------------------ Function ValidateIp(IPaddress) Dim MyIPArray,i,IpBlockNum if instr(1,IPaddress,".") > 1 then MyIPArray = split(IPaddress,".") if ubound(MyIPArray) = 3 then IpBlockNum = true for i = 0 to 3 if not isnumeric(MyIPArray(i)) then IpBlockNum = false Exit For else if int(MyIPArray(i)) > 255 or int(MyIPArray(i)) < 0 then IpBlockNum = false Exit For end if end if next ValidateIp = IpBlockNum else ValidateIp = false end if else ValidateIp = false end if End Function '------------------------------------------------------------------------------------- Function GetMyIP(MyPublicIp) Dim MyIP if GetUrlData("https://api.ipify.org/",MyIP) then if ValidateIp(MyIP) then MyPublicIp = MyIP GetMyIP = true else MyPublicIp = "" GetMyIP = false end if else GetMyIP = false end if End Function '-------------------------------------------------------------------------------------- if GetMyIP(PubIp) then Dim UserName ,Password ,Host ,Domain 'GratisDNS URL = https://admin.gratisdns.com/ddns.php?u=<username>&p=<kodeord>&d=<domæne>&h=<host>&i=<IP> UserName = "" Password = "" Host = "" Domain = "" if GetUrlData("https://admin.gratisdns.com/ddns.php?u=" & UserName & "&p=" & Password & "&d=" & Domain & "&h=" & Host & "&i=" & PubIp,GratisDnsSvar) then msgbox "Public IP:" & PubIp & vbcrlf & "GratisDNS returnerede dette svar:" & vbcrlf & vbcrlf & GratisDnsSvar,64,"Opdatering af GratisDNS (af Paw Jershauge)" else msgbox "Public IP:" & PubIp & vbcrlf & "GratisDNS blev IKKE opdateret" & vbcrlf & vbcrlf & GratisDnsSvar,16,"Opdatering af GratisDNS (af Paw Jershauge)" end if End if '##################################################################################
Tusinde tak til Paw for hjælpen med VB scriptet.
Linux
#!/bin/bash scriptDir=$( cd "$(dirname "$0")" ; pwd -P ) scriptPath="${scriptDir}/$(basename "$0")" crondPath="/etc/cron.d/1gratisddns" function usage { cat << EndOfUsage Usage: ./gratisddns.sh [OPTIONS..] Required options: -u/--user <user> -p/--password <ddns password> -a/--accountdomain <account domain> -d/--dyndomain <domain name to update> Optional options: -t/--detectip This tells the script to include our external ip as a url parameter. Using this adds a dependency on the 'dig' command from the 'bind-utils' package. You dont seem to need this. -i/--ip <ip address> This tells the script to submit the given ip address as a url parameter. This overrules the -t/--detectip argument -s/--schedule Causes this script to schedule itself for regular runs with the given arguments. -c/--cancel Causes this script to unschedule itself EndOfUsage } # Parse command line arguments while [[ $# > 0 ]]; do key="$1" case $key in -h|--help) usage exit 0 ;; -u|--user) DDNSUSER="$2" shift # past argument ;; -p|--password) PASSWORD="$2" shift # past argument ;; -a|--accountdomain) ACCOUNT_DOMAIN="$2" shift # past argument ;; -d|--dyndomain) DYN_DOMAIN="$2" shift # past argument ;; -t|--detectip) DETECT_IP=YES shift # past argument ;; -i|--ip) EXPLICIT_IP="$2" shift # past argument ;; -s|--schedule) SCHEDULE=YES shift # past argument ;; -c|--cancel) echo "Cancelling gratisddns schedule (if there was one)" sudo rm "$crondPath" exit ;; *) # unknown option echo "Unknown option: $key" >&2 usage >&2 exit 1 ;; esac shift # past argument or value done function validateArg { if [ -z "$1" ]; then echo "Missing argument: $2" >&2 usage >&2 exit 2 fi if [ -z "$3" ]; then echo "$2" = "$1" fi } validateArg "$DDNSUSER" "user" validateArg "$PASSWORD" "password" "dontprint" validateArg "$ACCOUNT_DOMAIN" "accountdomain" validateArg "$DYN_DOMAIN" "dyndomain" # Done parsing/validating arguments if [ -n "$SCHEDULE" ]; then echo "Creating schedule to run this script every three hours and log to /tmp/gratisddns.log" echo "01 0-23/3 * * * $USER $scriptPath -u $DDNSUSER -p $PASSWORD -a $ACCOUNT_DOMAIN -d $DYN_DOMAIN > /tmp/gratisddns.log 2>&1" | sudo tee "$crondPath" >/dev/null exit fi if [ -n "$EXPLICIT_IP" ]; then externalIpArg="&i=${EXPLICIT_IP}" elif [ -n "$DETECT_IP" ]; then # Verify presence of dig command and provide advice if it is missing if ! type "dig" &> /dev/null; then cat << EndOfError >&2 This script requires the command 'dig' when invoked with -t/--detectip. You can probably install it in one of the following ways: sudo yum install bind-utils sudo apt-get install bind-utils EndOfError exit 3 fi echo "Resolving external ip address using opendns.." externalIp="$(dig +short myip.opendns.com @resolver1.opendns.com)" if [ $? -ne 0 ]; then echo "External ip detection failed" >&2 exit 1 fi echo "Got external ip address $externalIp" externalIpArg="&i=${externalIp}" fi # Time to submit the request baseUrl="https://admin.gratisdns.com/ddns.php" gratisdnsUrl="${baseUrl}?u=${DDNSUSER}&p=${PASSWORD}&d=${ACCOUNT_DOMAIN}&h=${DYN_DOMAIN}${externalIpArg}" echo "Initiating request to ${baseUrl}.." curl -sS "$gratisdnsUrl"
Tusinde tak til Lars Ole Simonsen for Linux scriptet.
Ubiquiti
Er kun testet på en EdgeMax router, men virker muligvis også på lignende enheder fra Ubiquiti.
Skal placeres i /etc/dhcp3/dhclient-exit-hooks.d
if [ "$interface" = "eth0" ]; then case "$reason" in BOUND|RENEW|REBIND|REBOOT|TIMEOUT) if [ -n "$new_routers" ]; then curl -sS "https://admin.gratisdns.com/ddns.php?u=USER&p=PASSWORD&d=DOMAIN&h=HOST&i=$new_ip_address" logger "Updated HOST at GratisDNS with new IP = $new_ip_address" echo `date` >> /tmp/GratisDns echo "Updated HOST at GratisDNS with new IP = $new_ip_address" >> /tmp/GratisDns fi ;; esac fi
Tusinde tak til Jakob Jensen Prühs for Ubiquiti scriptet.
Du kan stemme på følgende ide for at nemmere at kunne konfigurere det i deres UniFi interface: https://community.ubnt.com/t5/UniFi-Routing-Switching-Feature/More-DDNS-dynamic-DNS-options-poll-a-custom-URL-with-IP/idi-p/1408422