I was exploring how to query DNS and do some probing on various types of information like MX and TXT records.
Here is the simple API
Step:1 inet_res:nslookup("domain.com", 1, txt).
It is always advisable to use another function, to convert it from internal record type to list,
Step:2 inet_dns:msg(Return_from_Step1)
Step:3 inet_dns:rr( Return_from_Step2)
Step:2 always return list or tuple of error message. So return value from the Step:2 should be processed.
Here is the complete code which returns "TXT" rr record, you can substitute mx for "MX" records,
More here http://www.erlang.org/doc/man/inet_res.html
Here is the simple API
Step:1 inet_res:nslookup("domain.com", 1, txt).
It is always advisable to use another function, to convert it from internal record type to list,
Step:2 inet_dns:msg(Return_from_Step1)
Step:3 inet_dns:rr( Return_from_Step2)
Step:2 always return list or tuple of error message. So return value from the Step:2 should be processed.
Here is the complete code which returns "TXT" rr record, you can substitute mx for "MX" records,
Pass the domain name to the lookup, you will get the list of records.lookup(Domain, VerifyingText) ->
case inet_res:nslookup(Domain, 1, txt) of
{ok, Record} ->
DnsRr = case inet_dns:msg(Record, anlist) of
DnsRrList when is_list(DnsRrList) -> hd(DnsRrList);
_ -> []
end,
io:format("IS of type ~p ~n", [is_list(DnsRr)]),
inet_dns:rr(DnsRr, data);
_-> false
end.
More here http://www.erlang.org/doc/man/inet_res.html
No comments:
Post a Comment
Thanks for reading and welcome for commenting...