Skip to content

Commit

Permalink
Improve the program's roustness and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Aug 11, 2023
1 parent 4541f29 commit 7d2d475
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A Rust program to resolve IP lists to their DNS PTR

It uses the `1.1.1.1:53` DNS server.
It uses the `1.1.1.1:53` DNS server. And 50 threads.

## Example input

Expand Down
29 changes: 24 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,32 @@ fn get_ptr(conn: UdpClientConnection, addr: IpAddr) {

fn resolve_file(filename: &str, dns_server: &str) {
let mut ips = vec![];
for line in read_to_string(filename).unwrap().lines() {
ips.push(IpAddr::from_str(line).unwrap());
match read_to_string(filename) {
Ok(file) => {
for line in file.lines() {
match IpAddr::from_str(line) {
Ok(addr) => ips.push(addr),
Err(err) => {
eprintln!("Something went wrong while parsing the IP ({}): {}", line, err);
process::exit(1);
}
}
}
}
Err(err) => {
eprintln!("Something went wrong while reading the file: {}", err);
process::exit(1);
}
}

rayon::ThreadPoolBuilder::new().num_threads(50).build_global().unwrap();
let address = dns_server.parse().unwrap();
let conn = UdpClientConnection::new(address).unwrap();
let conn = match UdpClientConnection::new(address) {
Ok(conn) => conn,
Err(err) => {
eprintln!("Something went wrong with the UDP client connection: {}", err);
process::exit(1);
}
};

ips.into_par_iter()
.enumerate()
Expand Down Expand Up @@ -67,6 +86,6 @@ mod test {

#[test]
fn test_resolve_file() {
resolve_file("./example/ips-resolved.txt", "1.1.1.1:53");
resolve_file("./example/ips-to-resolve.txt", "1.1.1.1:53");
}
}

0 comments on commit 7d2d475

Please sign in to comment.