A little console application in C# to show you the IP address of your computer or the IP address of any website you like.
Find IP address
Lusiphur commented: Useful tips from ddanbe as always :twisted: +1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace IPAddressApplication
{
class Program
{
static void Main(string[] args)
{
//Get IP info about this computer
//
Console.WriteLine("Local host:");
Console.WriteLine();
string Name = Dns.GetHostName();
Console.WriteLine("\tHost Name: " + Name);
Line();
DisplayHostInfo(Name);
Line();
//Get IP info of an internet address
//
DisplayHostInfo("www.amazon.com");
Line();
Console.ReadKey();
}
static void Line()
{
Console.WriteLine("\t============================================");
}
static void DisplayHostInfo(string Host)
{
IPHostEntry hostStuff;
hostStuff = Dns.GetHostEntry(Host);
// Start displaying info
// DNS name of the host
Console.WriteLine("\tPrimary host name: " + hostStuff.HostName);
// Alias names associated with the host
Console.Write("\tAliases: ");
foreach (string alias in hostStuff.Aliases)
{
Console.WriteLine("\t\t" + alias);
}
Console.WriteLine();
// List of IP addresses associated with the host
// May be IPv4 or IPv6 forms
Console.WriteLine("\tIP Addresses: ");
foreach (IPAddress ip in hostStuff.AddressList)
{
Console.WriteLine("\t\t" + ip.ToString());
}
Console.WriteLine();
}
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.