Created
January 7, 2024 12:58
-
-
Save tindzk/499bab63bc4a402c75774c24d202a56e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tokio::net::UdpSocket; | |
use std::net::{Ipv4Addr, SocketAddrV4}; | |
pub async fn send_udp_message() { | |
let google_dns = Ipv4Addr::new(8, 8, 8, 8); | |
let buffer = &[ | |
32, 189, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 4, 101, 54, 55, 51, 5, 100, 115, 99, 101, 57, 10, 97, | |
107, 97, 109, 97, 105, 101, 100, 103, 101, 3, 110, 101, 116, 0, 0, 65, 0, 1, | |
]; | |
let socket = UdpSocket::bind((Ipv4Addr::new(0, 0, 0, 0), 0)) | |
.await | |
.unwrap(); | |
socket | |
.connect(SocketAddrV4::new(google_dns, 53)) | |
.await | |
.unwrap(); | |
socket.send(buffer).await.unwrap(); | |
let mut response_bytes = [0; 4096]; | |
let response_length = socket.recv(&mut response_bytes).await.unwrap(); | |
let response = &response_bytes[0..response_length]; | |
println!("{:?}", response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment