Click here to Skip to main content
11,806,575 members (67,224 online)
Click here to Skip to main content

Get IP Address from Web host name

, 10 Apr 2002 85.4K 33
Rate this:
Please Sign up or sign in to vote.
Using network classes.

Sample Image - GTestDNS.jpg


If our computer is on a LAN and has a DNS server, we can use the code below to get its IP address from the Web host. This code is very simple. We use the Dns class to connect to the DNS server on our Local Area Network. Then it returns a IPHostEntry object as IPHost. IPHost contains properties including the IP Address...


using System;
using System.Net;
using System.Net.Sockets;
class GTest
    public static void Main()
        string strHost;
        Console.Write("Input host : "); //Iput web host name as string
        strHost = Console.ReadLine();
        IPHostEntry IPHost = Dns.Resolve(strHost); // though Dns to get IP host
        Console.WriteLine(IPHost.HostName); // Output name of web host
        IPAddress [] address = IPHost.AddressList; // get list of IP address
        Console.WriteLine("List IP {0} :",IPHost.HostName); 
        for(int i = 0;i< address.Length; i++) // output list of IP address


  • MSDN library.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Vietnam Vietnam
Nguyen Ha Giang,BS(computer science).

You may also be interested in...

Comments and Discussions

Generalping -a to get the hostname from an ipaddress. Pin
vij_guy11-Jun-08 9:34
membervij_guy11-Jun-08 9:34 
QuestionCan I help you! Pin
nguyenquanglamcnttk2718-Apr-07 7:18
membernguyenquanglamcnttk2718-Apr-07 7:18 
GeneralGet host name from IP address Pin
Abdulghani Sabbagh18-Apr-06 21:36
memberAbdulghani Sabbagh18-Apr-06 21:36 
GeneralThanks a lot Pin
mansir 12330-Mar-06 19:50
membermansir 12330-Mar-06 19:50 
GeneralThank you Nguyen! Pin
David Roh17-Aug-05 7:31
sussDavid Roh17-Aug-05 7:31 
GeneralCool Pin
Daniel Carvalho Liedke20-May-05 2:16
memberDaniel Carvalho Liedke20-May-05 2:16 
GeneralPlease don't post something like this! Pin
Anonymous17-Mar-05 11:14
sussAnonymous17-Mar-05 11:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151002.1 | Last Updated 11 Apr 2002
Article Copyright 2002 by nhgiang
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid