Sunday, August 24, 2008

动态域名无法解析的解决方案

笔者通过dyndns.com注册了一个域名,并通过路由器通知域名服务商真实的IP地址。 今日我的合作伙伴需要从国内连接这个域名,却发现DNS无法解析。 这个问题在国内比较普遍,我的处理方案是通过添加一个国外的DNS服务器,从而实现解析。

以下是用来解决此问题的vbs script脚本代码,它通过快速添加DNS 150.203.x.xx,达到实现解析的目的。其实在TCP/IP属性里也可以手动添加,但过程麻烦,直接运行脚本自动添加减少了手动添加造成的不便。




On Error Resume Next

strComputer = "."
strNewDNSServer = "150.203.x.xx"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")


For Each objNicConfig In colNicConfigs
intNewArraySize = 0
arrDNSServerSearchOrder = objNicConfig.DNSServerSearchOrder
If Not IsNull(arrDNSServerSearchOrder) Then
For Each strDNSServer In arrDNSServerSearchOrder
Next
End If
intNewArraySize = UBound(arrDNSServerSearchOrder) + 1
ReDim Preserve arrDNSServerSearchOrder(intNewArraySize)
arrDNSServerSearchOrder(intNewArraySize) = strNewDNSServer
intSetDNS = _
objNicConfig.SetDNSServerSearchOrder(arrDNSServerSearchOrder)
If intSetDNS = 0 Then
Else
End If
Next


Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For Each objNicConfig In colNicConfigs
If Not IsNull(objNicConfig.DNSServerSearchOrder) Then
For Each strDNSServer In objNicConfig.DNSServerSearchOrder
Next
End If
Next


No comments: