tags:

views:

337

answers:

1

Hi all,

I'm writing a utility console application which I would like to be able to give me a list of IIS website IPs so I can compare them to the list of IPs of the server. We have close to 40 server IPs and about 25 websites and when we add new sites I have to spend like 10 minutes figuring out what are our available IPs. So I just want to make my life easier.

I've already got the code that loops through the IIS DirectoryEntry using DirectoryServices, but the information exposed so far has not helped me see what the IPs are...

Thanks in advance for any info!

+1  A: 

I think this might work:

string name = Dns.GetHostName();
IPAddress[] addresses = Dns.GetHostAddresses(name);

foreach (IPAddress address in addresses)
{
    IPHostEntry entry = Dns.GetHostEntry(address);
    if (String.CompareOrdinal(entry.HostName, address.ToString()) == 0)
    {
        Console.WriteLine(entry.HostName + " is available.");
    }
}
David Silva Smith