Subscribe to How-To Geek

Get IP Address from DNS Hostname in C#

A frequent task when designing applications that work with TCP/IP and the internet is to lookup an IP address from a hostname. It’s much easier for users to deal with the hostname than having to type in an IP address.

First you’ll add the System.Net namespace to your using section:

using System.Net;

Example of code to get address from hostname:

string howtogeek = "www.howtogeek.com";
IPAddress[] addresslist = Dns.GetHostAddresses(howtogeek);

foreach (IPAddress theaddress in addresslist)
{
   Console.WriteLine(theaddress.ToString());
}

This was tested in C# 2.0.

| More
This article was originally written on 11/25/06 Tagged with: Programming

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:

Comments (5)

  1. Robert

    How might I go about getting other DNS records, such as NS records, or MX records in C#?

  2. Ba Than Tin

    How can I know which ip address for which network interface? And if I want IPV4 address only how can I do?

  3. vinh

    thanks for your info.

  4. biosys

    thanks for info :) works perfect!

  5. Narendra

    how can i print all the systems address connected in a network through window application in c# vs 2008


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Our Friends
Getting Started


About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
conhost.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.