nim ndns
v0.1.3
使用 dnsprotocol 实现的纯 Nim 域名系统 (DNS) 客户端。
此实现具有同步和异步 (async) 过程 (procs),用于使用 UDP 和 TCP 协议通过互联网传输数据。
nimble install ndns
或者
nimble install https://github.com/rockcavera/nim-ndns.git
解析 nim-lang.org 的 IPv4 地址(不是 async ):
import ndns
let client = initDnsClient ()
echo resolveIpv4 (client, " nim-lang.org " )
解析 nim-lang.org 的 IPv4 地址(异步):
import asyncdispatch, ndns
let client = initDnsClient ()
echo waitFor asyncResolveIpv4 (client, " nim-lang.org " )
有关“现实生活”异步示例,请参阅resolver.nim。在这个例子中,我做了尽可能多的评论,即使它们看起来很愚蠢。我认为这可能会对某人有所帮助,就像我私下为 Nim 的新人提供的一个类似例子一样。它还可以使用-d:showLoopLog
进行编译以显示异步工作流程。
使用QType.A
查询域名 nim-lang.org 创建Message
对象,传输Message
并接收响应(非异步):
import ndns
let header = initHeader ( randId (), rd = true )
let question = initQuestion ( " nim-lang.org " , QType .A, QClass . IN )
# If the last character of "nim-lang.org" is not a '.', the initializer will
# add, as it is called the DNS root.
let msg = initMessage (header, @ [question])
# The initializer automatically changes `header.qdcount` to `1'u16`
let client = initDnsClient ()
var rmsg = dnsQuery (client, msg)
echo repr (rmsg)
使用QType.A
查询域名 nim-lang.org 创建Message
对象,传输Message
并接收响应(异步):
import asyncdispatch, ndns
let header = initHeader ( randId (), rd = true )
let question = initQuestion ( " nim-lang.org " , QType .A, QClass . IN )
# If the last character of "nim-lang.org" is not a '.', the initializer will
# add, as it is called the DNS root.
let msg = initMessage (header, @ [question])
# The initializer automatically changes `header.qdcount` to `1'u16`
let client = initDnsClient ()
var rmsg = waitFor dnsAsyncQuery (client, msg)
echo repr (rmsg)
您可以使用系统使用的 DNS 解析服务器来初始化 DNS 客户端。为此,请使用initSystemDnsClient
启动客户端。
import ndns
let client = initSystemDnsClient ()
echo resolveIpv4 (client, " nim-lang.org " )
https://rockcavera.github.io/nim-ndns/ndns.html