C# Program to Get the IP Address and Host Name Using Dns Class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

using System.Xml;

using System.Xml.Linq;


namespace ConsoleApp

{

    class Program

    {

        static void Main(string[] args)

        {

            string HostName = Dns.GetHostName();

            Console.WriteLine("Host Name Is :" + HostName);

            IPAddress[] ipaddress = Dns.GetHostAddresses(HostName);

            Console.WriteLine("IP Address is :");

            foreach (IPAddress ip in ipaddress)

            {

                Console.WriteLine(ip.ToString());


            }

            Console.ReadKey();

        }

    }

}


Output:-

Host Name Is :AJAY - 111441

IP Address is :

fe80::1ab1:fd1:dc29:5cd6%19

172.16.81.171

एक टिप्पणी भेजें

0 टिप्पणियाँ