尝试使用以下代码从远程计算机获取证书哈希时收到错误消息:
private string getCertHash(string Hostname) { string result = ""; using (ServerManager serverManager = ServerManager.OpenRemote(Hostname)) { sitecollection sitecollection = serverManager.Sites; foreach (Site site in sitecollection) { foreach (Binding binding in site.Bindings) { if (binding.Protocol == "https") { // Error here foreach (Byte certhashbyte in binding.CertificateHash) result += certhashbyte.ToString(); } } } } return result; }
我收到的错误更详细:
'binding.certhashbyte'抛出了一个'System.Runtime.InteropServices.COMException'types的exception,
应用程序没有调用WSAStartup,或者WSAStartup失败。 (从HRESulTexception:0x8007276D)
DataGrIDVIEw性能 – 它取决于vIDeo卡?
Ruby可以导入一个.NET DLL吗?
如何检测两个文件是否在相同的“音量”?
.NET中奇怪的数组内存pipe理
使用多个对象遍历foreach循环
如果我replace下面的行:
using (ServerManager serverManager = ServerManager.OpenRemote(Hostname))
同
using (ServerManager serverManager = new ServerManager)
使用本地服务器,它工作正常。
请注意,使用ServerManager.OpenRemote(主机名)一般工作(我得到所有其他信息,只是CertHash信息结果在一个错误,我有pipe理员权限在两台机器上(本地和远程)系统是windows 2008 R2使用IIS 7.5 。
请告诉我我做错了什么/缺less什么/为什么发生错误。
将数字11格式化为00000011
为什么通过WMI只应用一次静态IP地址?
windows服务挂起在启动过程中启动
如何获得在windows中的Z顺序?
如何手动删除MSI安装?
出于某种原因,上面的代码现在工作正常。 我找不到为什么它不起作用,但我找到了一些我想分享的选择:
使用这个代码 ,这里是一个示例用法:
CertStoreReader certStoreReader = new CertStoreReader(); foreach (X509Certificate2 x509 in certStoreReader.GetCertificates(credentials.Hostname)) { certHash = x509.GetCertHashString(); }
首先使用serverManager(在问题中)
using (serverManager serverManager = serverManager.OpenRemote(server)) { Site site = serverManager.Sites.Where(s => s.name == websitename).Single(); foreach (Binding binding in site.Bindings) { certHash += BitConverter.ToString(binding.CertificateHash).Replace("-",string.Empty); } }
使用DirectoryEntry
DirectoryEntry dir = new DirectoryEntry(@"IIS://" + server + @"/W3SVC/" + siteID); PropertyValueCollection vals = dir.PropertIEs["SSLCertHash"]; foreach (string entry in vals) { certHash += entry; }
使用WMI。 我在Webadministration命名空间中使用了这个查询:
"SELECT CertificateHash FROM SSLBinding WHERE IPAddress = '" + IP + "' AND Port = " + port
总结以上是内存溢出为你收集整理的从远程服务器读取证书哈希全部内容,希望文章能够帮你解决从远程服务器读取证书哈希所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)