2
votes

I'm looking for a way to get all DNS records by web address.
Is there a way to do this with C#, without any library?

1
@Paweł Łukasik I don't want to use any libary.Luuk Verhagen
the second answer doesn't use anyPaweł Łukasik

1 Answers

8
votes

It is not really easy without any library.

You can use native code though, DnsQueryEx is a good starting point... You'll need tons of code to get it working in C# though.

Why not just use an existing library?

I just wrote one for donet core /xplat support for example: https://github.com/MichaCo/DnsClient.NET

which is really straight forward to use

var lookup = new LookupClient();
var result = await lookup.QueryAsync("google.com", QueryType.ANY);

var record = result.Answers.ARecords().FirstOrDefault();
var address = record?.Address;

See also http://dnsclient.michaco.net for more details/docs