gpt4 book ai didi

powershell - 如何通过 "The site' 的安全证书不受信任!”同时在 powershell 中监视 URL

转载 作者:太空宇宙 更新时间:2023-11-03 14:15:32 24 4
gpt4 key购买 nike

我正在使用 powershell 脚本来检查 Web URL 以查看它是否存在。但是,我必须检查几个站点,将您重定向到需要您单击按钮才能继续的站点。即使该站点正在运行,它也会由于预先的页面而返回失败。有没有办法使用 powershell 脚本来解决这个问题?我收到的错误在下面是我的代码。

错误

SSL 错误图标
该站点的安全证书不受信任!
您试图访问 ,但服务器出示了由您的计算机操作系统不信任的实体颁发的证书。这可能意味着服务器已生成自己的安全凭据,Chrome 无法依赖该凭据获取身份信息,或者攻击者可能正试图拦截您的通信。你不应该继续,特别是如果你以前从未见过这个网站的这个警告。

代码

$URLListFile = "\url_list.txt"  
$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
$Result = @()

#$OutputReport = "<html><title>PROD Monitoring Report</title><body><h2>PROD Monitoring Report</h2><table border=1 cellpadding=0 cellspacing=0><tr>Description</tr><tr>Status Code</tr><tr>Status</tr><tr>Response Time</tr>";
$OutputReport += "<HTML><TITLE>PROD Report</TITLE><BODY><font color=""#99000""><H2> PROD Monitoring Report </H2></font><Table border=1 cellpadding=0 cellspacing=0><TR bgcolor=gray><TD><B>Description</B></TD><TD><B>Code</B></TD><TD><B>Status</B></TD><TD><B>ResponseLength</B></TD></TR>"

Foreach($Uri in $URLList)
{
$startTime = Get-Date
$req = [system.Net.WebRequest]::Create($Uri)
try
{
$res = $req.GetResponse()
}
catch [System.Net.WebException]
{
$res = $_.Exception.Response
}
$endTime = Get-Date

$OutputReport += "<tr><td>"+$Uri+"</td>";
#$OutputReport += "<tr><td>Template</td>";
$web_status = [int]$res.StatusCode
if ($web_status -ne 200)
{
$OutputReport += "<td>"+$web_status+"</td><td bgcolor=red>Failure</td>"
}
else
{
$OutputReport += "<td>"+$web_status+"</td><td>Success</td>"
}
$OutputReport += "<td>"+($endTime - $startTime).TotalSeconds+" seconds</td></tr>"
}

$OutputReport += "</table></body></html>";
$Outputreport | out-file C:\Users\phall\Desktop\Docs\report.html

#Invoke-Expression C:\Scripts\Test.htm

最佳答案

假设您在这些网站上使用自签名证书,您必须将这些证书安装到运行脚本的系统上的证书库中,这样所有用户都可以访问它们。参见 this page举个例子。

以上内容与 PowerShell 无关,以下内容。

由于您使用的是 PowerShell 3.0,因此您应该了解 Invoke-WebRequest cmdlet。它可以通过允许您轻松调用 HTTP HEAD 请求来大大加快您的脚本,该请求只会告诉您您的 URL 是活跃的并且正在运行 - 无需拉动一切 发送回客户端。

Invoke-WebRequest -uri $uri -method HEAD |select-object statuscode

关于powershell - 如何通过 "The site' 的安全证书不受信任!”同时在 powershell 中监视 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20574292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com