Click here to Skip to main content
14,268,307 members

Get IP Address from Web host name

Rate this:
2.69 (8 votes)
Please Sign up or sign in to vote.
2.69 (8 votes)
10 Apr 2002
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).

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
memberDavid 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
memberAnonymous17-Mar-05 11:14 

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

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

Posted 10 Apr 2002


33 bookmarked