Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/DNS-query/OCaml/dns-query.ocaml
Normal file
20
Task/DNS-query/OCaml/dns-query.ocaml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
let dns_query ~host ~ai_family =
|
||||
let opts = [
|
||||
Unix.AI_FAMILY ai_family;
|
||||
Unix.AI_SOCKTYPE Unix.SOCK_DGRAM;
|
||||
] in
|
||||
let addr_infos = Unix.getaddrinfo host "" opts in
|
||||
match addr_infos with
|
||||
| [] -> failwith "dns_query"
|
||||
| ai :: _ ->
|
||||
match ai.Unix.ai_addr with
|
||||
| Unix.ADDR_INET (addr, _) -> (Unix.string_of_inet_addr addr)
|
||||
| Unix.ADDR_UNIX addr -> failwith "addr_unix"
|
||||
|
||||
let () =
|
||||
let host = "www.kame.net" in
|
||||
Printf.printf "primary addresses of %s are:\n" host;
|
||||
|
||||
Printf.printf " IPv4 address: %s\n" (dns_query host Unix.PF_INET);
|
||||
Printf.printf " IPv6 address: %s\n" (dns_query host Unix.PF_INET6);
|
||||
;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue