top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Get the IP address in Winforms/Console Application using C#?

+1 vote
601 views
How to Get the IP address in Winforms/Console Application using C#?
posted May 20, 2016 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes
using System;

using System.Collections.Generic;

using System.Data;

using System.DirectoryServices.AccountManagement;

using System.IO;

using System.Linq;

using System.Net;

using System.Net.Sockets;

namespace AbundantCode

{

internal class Program

{

// How to Validate a user in Active Directory using C# ?

private static void Main(string[] args)

{

IPHostEntry SystemAC = Dns.GetHostEntry(Dns.GetHostName());

string IPAddress = string.Empty;

foreach (var address in SystemAC.AddressList)

{

if (address.AddressFamily == AddressFamily.InterNetwork)

{

IPAddress = address.ToString();

}

}

Console.WriteLine(IPAddress);

Console.ReadKey();

}

}

}
answer May 20, 2016 by Shivaranjini
0 votes

using System;
using System.Net;

namespace ConsoleTest
{
class Program
{
static void Main()
{
String strHostName = string.Empty;
// Getting Ip address of local machine...
// First get the host name of local machine.
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
// Then using host name, get the IP address list..
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;

        for (int i = 0; i < addr.Length; i++)
        {
            Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
        }
        Console.ReadLine();
    }
}

}

answer May 20, 2016 by Rupali Dadhe
...