8个版本
0.3.0 | 2022年6月12日 |
---|---|
0.2.0 | 2020年7月7日 |
0.1.5 | 2019年7月30日 |
0.1.4 | 2018年11月15日 |
0.1.2 | 2016年8月31日 |
#1729 在 网络编程
在 alookup 中使用
48KB
1K SLoC
Resolv
通过glibc进行DNS解析。
注意:如果您只查找DNS名称的IP地址且不需要其他记录(MX、TXT等),请考虑其他更便携的rust库,如dns-lookup
。
此库使用libresolv.so
,通常通过/etc/resolv.conf
配置来执行DNS解析。它允许您查找任何类型的DNS资源记录(例如A、AAAA、MX、TXT等),使用递归(如果您的系统DNS解析器允许),并执行DNS搜索算法以完成不完整的名称并使用您的/etc/hosts
文件。
示例
extern crate resolv;
use resolv::{Resolver, Class, RecordType};
use resolv::record::MX;
fn main() {
// You must create a mutable resolver object to hold the context.
let mut resolver = Resolver::new().unwrap();
// .query() and .search() are the main interfaces to the resolver.
let mut response = resolver.query(b"gmail.com", Class::IN,
RecordType::MX).unwrap();
// You can iterate through answers as follows. You must specify the
// type of record. A run-time error will occur if the records
// decoded are of the wrong type.
for answer in response.answers::<MX>() {
println!("{:?}", answer);
}
}
局限性
您无法指定与编辑/etc/resolv.conf
不同的DNS服务器来为整个系统指定。
尚未支持所有NS记录类型。
使用线程安全接口,这可能在较旧的系统上不可用。
根据系统上安装的glibc版本,将选择多个适配器模块之一。很可能某些系统将需要从现有模块中创建新的适配器模块。这些在libresolv-sys/lib.d中。欢迎提交包含额外适配器的拉取请求。
许可证
许可方式为以下两种之一
- Apache许可证2.0版本(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证(LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确声明,否则您有意提交以包含在作品中的任何贡献,根据Apache-2.0许可证的定义,应作为上述双重许可,不得附加任何额外条款或条件。
依赖项
~165KB