如何获取网站的主机/IP 和端口 IIS 6-7.

本文关键字:IP IIS 主机 何获取 获取 网站 | 更新日期: 2023-09-27 17:56:32

这是我的问题。我希望我能列出本地承载的所有 IIS 网站。对于每个,我想检索站点名称,主机名,例如("本地主机:80")和端口号。我可以检索很多信息,但找不到主机名上的信息在哪里。谢谢。

这是我的代码 [c#] :

DirectoryEntry iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
        iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
        foreach (DirectoryEntry site in iis.Children)
        {
            if (site.SchemaClassName == "IIsWebServer") 
            {
                Console.Out.WriteLine(site.Name);
                //I do not know the name of the property to find the "host"
                Console.Out.WriteLine(site.Host); ???
            }
        }

如何获取网站的主机/IP 和端口 IIS 6-7.

我认为您需要从ServerBindings属性中解析它。格式为 IP:端口:主机名 - 如果是默认网站,主机名应为空或 *。

还有SecureBindings,(因为你想要端口#)你也需要抓住它。