El ejemplo que les voy a mostrar permite obtener esa información de un servidor IIS local. Fue bastante util para mi en un proyecto.
Aquí les va:
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
namespace EnumSites
{
class Program
{
static void Main(string[] args)
{
DirectoryEntry entry = new DirectoryEntry("IIS://localhost/w3svc/1");
PropertyValueCollection pvc = entry.Properties["ServerBindings"];
foreach (object value in pvc)
{
// Format is IPAddress:Port:HostHeader
string[] Bits = value.ToString().Split(':');
string IPAddress = Bits[0];
string TCPIPPort = Bits[1];
string HostHeader = Bits[2];
Console.WriteLine("IP = {0}, Port = {1}, Header = {2}",
(IPAddress.Length == 0) ? "(All Unassigned)" : IPAddress,
TCPIPPort,
(HostHeader.Length == 0) ? "(No Host Header)" : HostHeader);
}
Console.Read();
}
}
}
Como pueden ver, se obtiene un DirectoryEntry con el site localhost. De aquí se obtiene la variable ServerSettings, y de aquí obtener el valor que nos brinda. Estos valores vienen separados por dos puntos (":"). El primer valor nos indica la IP, la segunda el puerto y el tercero el header.
Espero que esto les sea útil algún día.
Saludos
Espero que esto les sea útil algún día.
Saludos
No hay comentarios:
Publicar un comentario