查找死网站/域的脚本 [英] Script to find dead website/domain

查看:124
本文介绍了查找死网站/域的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Powershell脚本来查找未在我们的服务器上运行或指向另一台服务器的网站.我正在从文件中获取所有网站名称,并使用它来查找那些不在我们的服务器上运行的网站.我正在尝试使用以下脚本,但出现错误.

I am working on a powershell script to find websites which are either not running on our server or pointing to another server. I am fetching all website names from a file and using it to find only those websites which are not running on our server. I'm trying to use below script but getting an error.

一如既往,我们将非常感谢您的帮助或建议.

As always, and help or advice would be much appreciated.

$servers = get-content "path_to_the_file"
foreach ($server in $servers) {
$addresses = [System.Net.Dns]::GetHostAddresses($server)
foreach($a in $addresses) {
"{0},{1}" -f $server, $a.IPAddressToString
 }
}     

以下是我得到的错误:

Exception calling "GetHostAddresses" with "1" argument(s): "No such host is known" At      
C:\test1.ps1:3 char:50 + $addresses = [System.Net.Dns]::GetHostAddresses <<<< ($server) + 
CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : 
DotNetMethodException

推荐答案

只需捕获异常:

try {
    $addresses = [System.Net.Dns]::GetHostAddresses($server);
}
catch {
    $addresses = [IPAddress]'0.0.0.0';
}

这篇关于查找死网站/域的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆