Click here to Skip to main content
Licence 
First Posted 10 Apr 2002
Views 77,364
Bookmarked 33 times

Get IP Address from Web host name

By | 10 Apr 2002 | Article
Using network classes.

Sample Image - GTestDNS.jpg

Introduction

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...

Implementation

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
            Console.WriteLine(address[i]);
    }
}

Reference

  • MSDN library.

License

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

nhgiang

Web Developer

Vietnam Vietnam

Member

Nguyen Ha Giang,BS(computer science).

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalping -a to get the hostname from an ipaddress. Pinmembervij_guy9:34 11 Jun '08  
QuestionCan I help you! Pinmembernguyenquanglamcnttk277:18 18 Apr '07  
I need to get Host name, IP address, MAC, Directory on the disk and information PC in the LAN. Thank u!

 
QuangLam

GeneralGet host name from IP address PinmemberAbdulghani Sabbagh21:36 18 Apr '06  
GeneralThanks a lot Pinmembermansir 12319:50 30 Mar '06  
GeneralThank you Nguyen! PinsussDavid Roh7:31 17 Aug '05  
GeneralCool PinmemberDaniel Carvalho Liedke2:16 20 May '05  
GeneralPlease don't post something like this! PinsussAnonymous11:14 17 Mar '05  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 11 Apr 2002
Article Copyright 2002 by nhgiang
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid