From f66b956cc4b6110b723a6c68e31017844dc34431 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 19 Jun 2023 23:23:13 +0200 Subject: [PATCH] add lookup domain --- bin/main.ml | 5 ++++- lib/network.ml | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/main.ml b/bin/main.ml index 1eb1326..f69033c 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -4,5 +4,8 @@ let () = let response = Network.send_request "8.8.8.8" "www.example.com" in print_endline (Utils.get_bytecode response); let dns_packet = Response.parse_dns_packet response in - print_endline (Debug.dns_packet dns_packet) + print_endline (Debug.dns_packet dns_packet); + print_endline (Network.lookup_domain "example.com"); + print_endline (Network.lookup_domain "recurse.com"); + print_endline (Network.lookup_domain "www.metafilter.com") ;; diff --git a/lib/network.ml b/lib/network.ml index 9c2a125..a0ab612 100644 --- a/lib/network.ml +++ b/lib/network.ml @@ -11,3 +11,9 @@ let send_request dns url = let len, _ = recvfrom sock response 0 buffer_size [] in Bytes.sub response 0 len ;; + +let lookup_domain domain = + let response = send_request "8.8.8.8" domain in + let dns_packet = Response.parse_dns_packet response in + Utils.get_ip (List.nth (List.rev dns_packet.answers) 0).data +;;