strato DDNS VBS Client

看了几款网上的DDNS Client。有些是Shareware要付费的,有些功能不符合。最后还是写了个VBS的DDNS Client。大家可以把他添加到Windows Task Scheduler里面,让它定时通过DDNS更新external的IP。

以下是给德国Strato公司配置的(其它DDNS可见最后的Comment),在使用前按需要先修改host,pass等variables:


' === settings ===
host = "<HOST>"
pass = "<PASSWORD>"
url = "https://dyndns.strato.com/nic/update?hostname=" & host & "&system=dyndns&wildcard=OFF&backmx=NO&offline=NO"
pth = "D:\ddns-client.log"

' === ddns client ===
Dim oQuery: Set oQuery = CreateObject("MSXML2.XMLHTTP.3.0")
Dim oLogger: Set oLogger = CreateObject("Scripting.FileSystemObject")

Sub Debug (pth, str)
	msg = date & " " & time & ": " & str
	Set oLogFile = oLogger.OpenTextFile(pth, 8, True, 0)
	oLogFile.Write msg	
	oLogFile.Close
End Sub

Function ResolveIP(host)
    oQuery.Open "GET", "http://ip-lookup.net/domain.php?domain=" & host, False
    oQuery.Send
    If oQuery.Status = 200 Then
        Set RegEx = New RegExp
        RegEx.Global = True
        RegEx.Pattern = "http://ip-lookup.net\?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
        Set matches = RegEx.Execute(oQuery.responseText)
          If matches.Count > 0 Then
            ResolveIP = matches(0).SubMatches(0)
          End If
    End If
End Function Function GetMyIP()
    oQuery.Open "GET", "https://ip.appspot.com/", False
    oQuery.Send
    If oQuery.Status = 200 Then
        GetMyIP = Replace(Replace(oQuery.responseText, vbLf, ""), vbCr, "")
    End If
End Function Function Query(url, host, pass, ip) If ip "" Then url = url & "&myip=" & ip End If oQuery.Open "GET", url, False, host, pass oQuery.Send If oQuery.Status = 200 And (InStr(oQuery.responseText, "good") Or InStr(oQuery.responseText, "nochg")) Then Query = "ok, " & oQuery.Status & ", " & oQuery.responseText Else Query = "failed, " & oQuery.Status End If End Function ' === main === externalIp = GetMyIP() currentIp = ResolveIP(host) Debug pth, host & ": current ip=" & currentIp & ", external ip=" & externalIp If externalIp <> currentIp Then rsp = Query(url, host, pass, ip) Debug pth, rsp Else Debug pth, "ok" End If ' === list of response codes === ' good - Update successfully. ' nochg - Update successfully but the IP address have not changed. ' nohost - The hostname specified does not exist in this user account. ' abuse - The hostname specified is blocked for update abuse. ' notfqdn - The hostname specified is not a fully-qualified domain name. ' badauth - Authenticate failed. ' 911 - There is a problem or scheduled maintenance on provider side ' badagent - The user agent sent bad request(like HTTP method/parameters is not permitted) ' badresolv - Failed to connect to because failed to resolve provider address. ' badconn - Failed to connect to provider because connection timeout. ' === list of ddns providers === 'DYNDNS.org 'http://members.dyndns.org/nic/update?hostname=[HOST]&myip=[IP]&system=dyndns&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG 'TwoDNS.de 'http://update.twodns.de/update.php?hostname=[HOST]&myip=[IP] 'NoIP.com 'http://dynupdate.no-ip.com/nic/update?hostname=[HOST]&myip=[IP] 'able.or.kr 'http://able.or.kr/ddns/src/update.php?hostname=[HOST]&myip=[IP]&ddnsuser=[USER]&pwd=[PASS] '3322.org 'http://www.3322.org/dyndns/update?hostname=[HOST]&system=dyndns 'selfHOST.de 'http://carol.selfhost.de/nic/update?hostname=[HOST]&myip=[IP] 'Dynamic DO!.jp 'http://free.ddo.jp/dnsupdate.php?dn=[HOST]&pw=[PASS]&ip=[IP] 'ChangeIP.com 'http://nic.ChangeIP.com/nic/update?hostname=[HOST]&myip=[IP]&system=dyndns 'DNSPod.com 'http://dnsapi.cn/Record.Modify?login_email=[USER]&login_password=[PASS]&format=xml&domain_id=[DOMAIN_ID]&record_id=[RECORD_ID]&sub_domain=[SUBDOMAIN]&record_type=A&record_line=[RECORDLINE]&value=[IP]&mx=[MX]&ttl=[TTL] 'Zoneedit.com 'http://dynamic.zoneedit.com/auth/dynamic.html?host=[HOST]&dnsto=[IP] 'Freedns.org 'http://freedns.afraid.org/dynamic/update.php?user=[FREE_DNS_SHA1]&host=[HOST]& address=[IP] 'STRATO 'http://[USER]:[PASS]@dyndns.strato.com/nic/update?hostname=[HOST]&myip=[IP]&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG