2011-12-19 59 views
2

我的目标是从远程服务器获取网站名称列表。但我得到的例外:DirectoryEntry使用哪个端口?

RPC服务器不可用。

下面是代码:

public List<string> GetWebSites(string serverIP) 
    { 
     List<string> names = new List<string>(); 
     DirectoryEntry Services = new DirectoryEntry(string.Format("IIS://{0}/W3SVC", serverIP)); 
     Services.Username = "user name"; 
     Services.Password = "password"; 
     IEnumerator ie = Services.Children.GetEnumerator(); 
     DirectoryEntry Server = null; 

     while (ie.MoveNext()) 
     { 
      Server = (DirectoryEntry)ie.Current; 
      if (Server.SchemaClassName == "IIsWebServer") 
      { 
       names.Add(Server.Properties["ServerComment"][0].ToString()); 
      } 
     } 

     return names; 
    } 

这工作得很好,当防火墙被关闭机器。

我需要知道的是,DirectoryEntry使用哪个端口? 还是有没有其他方式来获取网站名称,而不关闭防火墙?

+2

它将使用(广泛)端口范围。如果您需要将其强制到特定端口或更小范围,请查看[这里](http://support.microsoft.com/kb/154596)。如果我没有弄错,你还需要UDP 389。 – vcsjones 2011-12-19 15:29:52

回答

2

我相信LDAP协议使用TCP否?对于非ssl应该是389端口,对于SSL应该是386端口