Ross
Ross

Reputation: 191

How to determine if a server is only accessible using IPv6

Using Delphi 7 with Indy10, I need to create an IPv6 to IPv4 proxy for a service that doesn't support IPv6. I can manage that fine. The only issue I'm facing is, if they enter a domain name rather than an IP address, how can I determine if the destination server is only accessible via IPv6 and not IPv4? If IPv4 is available, I would prefer to send the request directly rather than going through the proxy.

Is using TIdDNSResolver the only solution?

I found code for with 2 functions for using it, one returning an IPv4 and the other an IPv6 address. Presumably the IPv4 function will return nothing if there is only IPv6 available.

But the functions both require a DNS server to be specified. How am I to find one? Is there some way to use the default DNS server to find the IP addresses, perhaps using a Windows API and not Indy?

Upvotes: 0

Views: 672

Answers (1)

fpiette
fpiette

Reputation: 12322

You actually have several questions in your question. I will answer this one: "How do I find a DNS server address?".

One answer is: call GetAdaptersAddresses in the IpHelper API. This call will return many addresses including the DNS address. In the documentation there is a C++ example you can translate to Delphi.

Another answer is to use command line IPCONFIG /ALL. In the output, you'll find the DNS address.

A third answer is to use a WMI query. See this question.

Upvotes: 1

Related Questions