How do you resolve a domain name to an IP address with .NET/C#?
DNS keeps the record of all domain names and the associated IP addresses. When you type in a URL in your browser, DNS resolves the domain name into an IP address. In other words, DNS is a service that maps domain names to corresponding IP addresses.
To point your domain name to your dedicated server's public IP address, you need to create an address record for the domain — an A record. An A record is part of the DNS system and it simply maps a domain name to an IP address. An A record is stored as a DNS entry on the domain's name servers.
Resolving host names with a hosts file Domain names or IP addresses on a local computer can be resolved by adding entries in the local hosts file on a computer. Entries in the local hosts file have the added advantage that the system can run the application server, even when disconnected from the network.
using System.Net; foreach (IPAddress address in Dns.GetHostAddresses("www.google.com")) { Console.WriteLine(address.ToString()); }
Try using the System.Net.Dns class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With