|
建议用 1.1.1.1 而不是用阿里云的 223.5.5.5
因为1.1.1.1的回应 对于测试来说 是比较友好的
很多时候 你发给阿里云的 也许连回应都收不到
尤其是一些比较奇怪的包 不合法的包等等
rust可以用simple-dns这个crate包用于测试dns协议的解析和封装
- use std::net::UdpSocket;
- use simple_dns::*;
- use simple_dns::rdata::*;
- fn main() {
- let mut packet = Packet::new_query(1);
- let question = Question::new(Name::new_unchecked("_srv._udp.local"), TYPE::TXT.into(), CLASS::IN.into(), false);
- packet.questions.push(question);
- let resource = ResourceRecord::new(Name::new_unchecked("_srv._udp.local"), CLASS::IN, 10, RData::A(A { address: 10 }));
- packet.additional_records.push(resource);
- // Write the packet in the provided buffer;
- let mut bytes = [0u8; 200];
- assert!(packet.write_to(&mut &mut bytes[..]).is_ok());
- let socket = UdpSocket::bind("0.0.0.0:0").expect("couldn't bind to address");
-
-
- match socket.connect("1.1.1.1:53") {
- Ok(r) => println!("{:?}",r),
- Err(e) => println!("{:?}",e),
- }
- socket.send(&bytes).expect("couldn't send message");
- let mut buf = [0; 1024];
- match socket.recv(&mut buf) {
- Ok(received) => println!("received {received} bytes {:?}", &buf[..received]),
- Err(e) => println!("recv function failed: {e:?}"),
- }
-
-
- }
复制代码
simple-dns = "0.7.0"
|
|