实现windows下的动态域名解析服务

MrLee2016-4-20 2095

准备着手这个功能的开发,先纪录下来!
此文仅供参考
动态域名解析系统将用户的动态IP地址映射到一个固定的域名解析服务上(DDNS).动态域名解析系统一般由两部分构成。
第一部分是服务器端程序,位于服务商的主机上。另一部分是客户端程序,就运行在广大用户的主机上。在每次连接网络的时候,客户端程序就会通过信息传递,把该主机的动态IP地址传送给位于服务商主机上的服务器程序,服务器程序负责提供DNS服务并实现动态域名解析服务,再收到客户端通知后服务器端程序立即更新数据,将新的IP地址和原有的固定域名绑定,这样就完成了动态域名解析的服务。别人也就可以通过域名访问你的服务器了。
动态域名服务的功能,就是实现固定域名到动态IP地址之间的解析。用户每次上网得到新的IP地址之后,都要向DNS申请更新该域名解析数据库;在用户在线期间,Internet上的其他人要访问这个域名的时候,动态域名解析服务器就会返回正确的IP地址。当用户下线时,DNS要停用该域名的服务,以免因为同一个IP地址重复利用引起混乱。
 
以下详细讲述动态域名解析服务的具体实现细节。
一 dns服务器安装
采用win2000 server操作系统(winxp和win2000专业版本没有dns服务安装选项)。
安装DNS的步骤如下:(1)选“开始→设置→控制面板”,打开“添加/删除程序”。(2)单击“添加/删除Windows组件”,等待Windows组件向导启动。(3)单击[下一步]按钮弹出Windows组件清单。(4)单击[网络服务],然后再单击[详细情况]按钮。(5)单击“DNS(域名系统)”旁的复选框。(6)单击[确定]按钮返回“Windows组件”对话框。(7)单击[下一步]安装相应的服务,然后逐一单击[完成]和[关闭]按钮即可完成。不需要重新启动计算机,单击“开始→程序→管理工具→DNS”。
创建区域(1)用鼠标单击主机旁边的“+”号,然后用鼠标右键单击选“新建区域”以进入新建区域向导中。(2)当向导提示到要让选择“区域类型”时,此处应该选“标准主要区域”,而在“正向或反向搜索区域中”应选“正向搜索区域”,单击“正向搜索区域”旁边的“+”号,用鼠标右键单击“正向搜索区域”,单击[下一步]按钮。(3)屏幕出现询问“区域名”,则在“名称”后的文字框中输入“sample.net”(以区域sample.net为例子),接着向导进入到“区域文件”提示窗口中,默认的,系统会自动选中“创建新文件,文件名为”一项,并在其后的文字框中自动填有“sample.net.dns”的名字单击[下一步]按钮,然后单击[完成]即可完成区域创建,此时在DNS管理器的左边的“正向搜索区域”里可以看到“sample.net”区域,如下图所示

DNS_QUERY_MULTICAST_VERIFY Directs a test using the local machine hostname to verify name uniqueness on the same Local Link. Collects all responses even if normal LLMNR Sender behaviour is not enabled..Note   This option is available only when using Windows Server "Longhorn" or Windows Vista.
DNS_QUERY_MULTICAST_WAIT Waits for a full timeout to collect all the responses from the Local Link. If not set, the default behaviour is to return with the first response.Note   This option is available only when using Windows Server "Longhorn" or Windows Vista.pExtra[in, out, optional] This parameter is reserved for future use and must be set to NULL.ppQueryResultsSet[in, out] Optional. A pointer to a pointer that points to the list of RRs that comprise the response. For more information, see the Remarks section.pReserved[in, out] This parameter is reserved for future use and must be set to NULL.Return ValueReturns success confirmation upon successful completion. Otherwise, returns the appropriate DNS-specific error code as defined in Winerror.h.RemarksApplications that call the DnsQuery function build a query using a fully-qualified DNS name and Resource Record (RR) type, and set query options depending on the type of service desired. When the DNS_QUERY_STANDARD option is set, DNS uses the resolver cache, queries first with UDP, then retries with TCP if the response is truncated, and requests that the server to perform recursive resolution on behalf of the client to resolve the query.
Callers must free returned RR sets with the DnsRecordListFree function.
Note  When calling one of the DnsQuery function types, be aware that a DNS server may return multiple records in response to a query. A computer that is multihomed, for example, will receive multiple A records for the same IP address. The caller must use as many of the returned records as necessary.
Consider the following scenario, in which multiple returned records require additional activity on behalf of the application: A DnsQuery_A function call is made for a multihomed computer and the application finds that the address associated with the first A record is not responding. The application should then attempt to use other IP addresses specified in the (additional) A records returned from the DnsQuery_A function call.
If the ppQueryResultsSet and pReserved parameters are set to NULL, the DnsQuery function fails with the error INVALID_PARAMETER.
RequirementsClient Requires Windows Vista, Windows XP, or Windows 2000 Professional.Server Requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.Header Declared in Windns.h.
Library Use Dnsapi.lib.
DLL Requires Dnsapi.dll.
2.DnsRecordListFree
The DnsRecordListFree function frees memory allocated for DNS records obtained using the DnsQuery function.void WINAPI DnsRecordListFree(PDNS_RECORD pRecordList,DNS_FREE_TYPE FreeType);
ParameterspRecordList[in, out] A pointer to the list of DNS records to be freed.FreeType[in] A specifier of how the record list should be freed. The only type currently supported is a deep freeing of the entire record list. For more information and a list of values, see the DNS_FREE_TYPE enumeration.Return ValueThis function does not return a value.RemarksThe DnsRecordListFree function can be used to free memory allocated from query results obtained using a DnsQuery function call; it cannot free memory allocated for DNS record lists created manually.
RequirementsClient Requires Windows Vista, Windows XP, or Windows 2000 Professional.Server Requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.Header Declared in Windns.h.
Library Use Dnsapi.lib.
DLL Requires Dnsapi.dll.
3.DnsRecordCopyEx
The DnsRecordCopyEx function creates a copy of a specified RR. The DnsRecordCopyEx function is also capable of converting the character encoding during the copy operation.PDNS_RECORD WINAPI DnsRecordCopyEx(PDNS_RECORD pRecord,DNS_CHARSET CharSetIn,DNS_CHARSET CharSetOut);
ParameterspRecord[in] Pointer to the RR to be copied.CharSetIn[in] Character encoding of the source RR.CharSetOut[in] Character encoding required of the destination record.Return ValueSuccessful execution returns a pointer to the (newly created) destination record. Otherwise, returns null.
RemarksThe CharSetIn parameter is used only if the character encoding of the source RR is not specified in pRecord.
RequirementsClient Requires Windows Vista, Windows XP, or Windows 2000 Professional.Server Requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.Header Declared in Windns.h.
Library Use Dnsapi.lib.
DLL Requires Dnsapi.dll.
4.DnsModifyRecordsInSet
The DnsModifyRecordsInSetfunction adds, modifies or removes a Resource Record (RR) set that may have been previously registered with DNS servers.
Like many DNS functions, the DnsModifyRecordsInSet function type is implemented in multiple forms to facilitate different character encoding.
Based on the character encoding involved, use one of the following functions:
DnsModifyRecordsInSet_A (_A for ANSI encoding)DnsModifyRecordsInSet_W (_W for Unicode encoding)DnsModifyRecordsInSet_UTF8 (_UTF8 for UTF 8 encoding)If the DnsModifyRecordsInSet function type is called without its suffix (_A, _W, or _UTF8), a compiler error will occur.DNS_STATUS WINAPI DnsModifyRecordsInSet(PDNS_RECORD pAddRecords,PDNS_RECORD pDeleteRecords,DWORD Options,HANDLE hContext,PVOID pExtraList,PVOID pReserved);
ParameterspAddRecords[in] A pointer to the DNS_RECORD structure that contains the RRs to be added to the RR set.pDeleteRecords[in] A pointer to the DNS_RECORD structure that contains the RRs to be deleted from the RR set.Options[in] Options to apply to the operation. Options consist of the following, and may be combined.Option MeaningDNS_UPDATE_SECURITY_USE_DEFAULT Uses the default behavior, which is specified in the registry, for secure dynamic DNS updates.DNS_UPDATE_SECURITY_OFF Does not attempt secure dynamic updates.DNS_UPDATE_SECURITY_ON Attempts nonsecure dynamic update; if refused, attempts secure dynamic update.DNS_UPDATE_SECURITY_ONLY Attempts secure dynamic updates only.DNS_UPDATE_CACHE_SECURITY_CONTEXT Caches the security context for use in future transactions.DNS_UPDATE_TEST_USE_LOCAL_SYS_ACCT Uses credentials of the local computer account.DNS_UPDATE_FORCE_SECURITY_NEGO Does not use cached security context.DNS_UPDATE_RESERVED Reserved for future use.
hContext[in] A handle to the credentials of a specific account. Used when secure dynamic update is required. This parameter is optional.pExtraList[in, out, optional] This parameter is reserved for future use and must be set to NULL.pReservedThis parameter is reserved for future use and must be set to NULL.Return ValueReturns success confirmation upon successful completion. Otherwise, it returns the appropriate DNS-specific error code as defined in Winerror.h.
RemarksThe DnsModifyRecordsInSet function type executes in the following steps.Records specified in pDeleteRecords are deleted. If pDeleteRecords is empty or does not contain records that exist in the current set, the DnsModifyRecordInSet function goes to the next step.Records specified in pAddRecords are added. If pAddRecords is empty, the operation completes without adding any records.To add a new record, provide no records in pDeleteRecords, and provide the record to be added in pAddRecords. To modify a record, specify the record being modified in pDeleteRecords, then add the modified version of that record by placing it in pAddRecords. To delete records, specify only records to be deleted. Multiple records can be added or deleted in a single call to DnsModifyRecordInSet. If a record specified in pAddRecords is already present, no change occurs.
If no server list is specified, the default name server is queried.
RequirementsClient Requires Windows Vista, Windows XP, or Windows 2000 Professional.Server Requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.Header Declared in Windns.h.
Library Use Dnsapi.lib.
DLL Requires Dnsapi.dll.
 

本文链接:https://www.it72.com/9280.htm

推荐阅读
最新回复 (0)
    返回