CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    32

    reading ip address

    how can i read the ip addresses where are presently renning in network

  2. #2
    Join Date
    Apr 2005
    Posts
    42

    Re: reading ip address

    using System;
    using System.Net;

    namespace GetIPCS
    {
    /// <summary>
    /// Gets IP addresses of the local machine
    /// </summary>
    class classGetIPCS
    {
    /// <summary>
    /// Gets IP addresses of the local machine
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    // Get host name
    String strHostName = Dns.GetHostName();
    Console.WriteLine("Host Name: " + strHostName);

    // Find host by name
    IPHostEntry iphostentry = Dns.GetHostByName(strHostName);

    // Enumerate IP addresses
    int nIP = 0;
    foreach(IPAddress ipaddress in iphostentry.AddressList)
    {
    Console.WriteLine("IP #" + ++nIP + ": " +
    ipaddress.ToString());
    }
    }
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured