add lookup domain

This commit is contained in:
Mylloon 2023-06-19 23:23:13 +02:00
parent 07afc0afa5
commit f66b956cc4
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 10 additions and 1 deletions

View file

@ -4,5 +4,8 @@ let () =
let response = Network.send_request "8.8.8.8" "www.example.com" in let response = Network.send_request "8.8.8.8" "www.example.com" in
print_endline (Utils.get_bytecode response); print_endline (Utils.get_bytecode response);
let dns_packet = Response.parse_dns_packet response in 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")
;; ;;

View file

@ -11,3 +11,9 @@ let send_request dns url =
let len, _ = recvfrom sock response 0 buffer_size [] in let len, _ = recvfrom sock response 0 buffer_size [] in
Bytes.sub response 0 len 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
;;