zoukankan      html  css  js  c++  java
  • 使用PowerShell 测试DNS

    运行环境:Windows Server 2012 R2

    获取服务器DNS命令,下面的仅获取一个dns

     (nslookup sql.ciras.com)[1].split(':')[1].trim() 

    此脚本用来验证DNS是否正常,实际原理就是ping域名的ip

    先ping域名

    再解析域名的ip地址

    判断域名是否解析域名是否为多个ip

    若为多个ip,则再次ping文件中给的ip地址

    最后输出表格

    # 验证DNS是否能ping通
    # author:lttr <www.cnblogs.com/GoCircle>
    # date:2019-08-09
    # eg. # C:UsersDesktopTestDNS.ps1 # 获取当前脚本绝对路径 $path = Split-Path -Parent $MyInvocation.MyCommand.Definition; $file = "域名及ip列表.txt"; # 读取txt文件获取列表信息 [array]$dnslist = (get-content -Path ($path + $file)) $sourcecount = $dnslist.Length-1 for($i=1;$i -le $sourcecount;$i++){ Write-Progress -Activity "正在检测DNS列表" -PercentComplete ($i/$sourceCount*100) -Status "Step $i of $sourcecount" $dnsip = ($dnslist[$i] -split ",")[1] $flage = Test-NetConnection ($dnslist[$i] -split ",")[0] -Hops 1 -InformationLevel Quiet -ErrorAction SilentlyContinue -WarningAction silentlyContinue $dnsresult = Resolve-DnsName -Name ($dnslist[$i] -split ",")[0] -ErrorAction SilentlyContinue if($dnsresult.IPAddress.count -gt 1){ $flage = Test-NetConnection $dnsip -Hops 1 -InformationLevel Quiet -ErrorAction SilentlyContinue -WarningAction silentlyContinue } [PSCustomObject]@{ 域名 = ($dnslist[$i] -split ",")[0].ToUpper() + " " DNS状态 = Switch($DNSLookupObject){ {!$flage}{"Ping失败 "} {$flage -and !($dnsresult.IPAddress -Match $dnsip)}{"IP不一致 "} {$flage -and $dnsresult.IPAddress -Match $dnsip}{"成功 "} } txt中IP地址 = $dnsip + " " Connection_IP地址 = $(if($flage){$dnsresult.IPAddress}) } }

    附带的txt文件格式

    输入格式【域名,IP】(中间使用英文逗号分隔),请保留本行且不能包含空行。
    www.baidu.com,127.0.0.1
    www.baidu.com,127.0.0.2
    www.baidu.com,127.0.0.3
    www.baidu.com,127.0.0.4

  • 相关阅读:
    Ensemble ID及转换
    FastQC及MultiQC整合使用
    Aspera下载安装使用
    RStudio代码折叠
    两样本检验
    单样本t检验,Python代码,R代码
    rMATS输出结果文件只有表头
    使用DiffBind 进行ATAC-seq peaks差异分析
    error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared
    Python遗传算法初尝,火狐像素进化
  • 原文地址:https://www.cnblogs.com/GoCircle/p/11325587.html
Copyright © 2011-2022 走看看