通过shell枚举Windows DNS服务器区域属性

前端之家收集整理的这篇文章主要介绍了通过shell枚举Windows DNS服务器区域属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用命令行工具列出(主)区域配置的辅助服务器(如果有).

Dnscmd接近:

dnscmd server /ZoneResetSecondaries:[list of secondaries]

但是,我不想破坏任何当前设置,我只想查看它们. PowerShell(甚至在Server 2012上)似乎没有帮助.

谢谢.

你是最正确的,你可以:

>枚举区域并查找“主要”区域
>检索每个区域的区域信息

我以前@L_502_0@使用PowerShell,这应该完成第1步:

function Get-DNSZones
{
    param(
    [String]$ComputerName = "."
    )

    $enumZonesExpression = "dnscmd $ComputerName /enumzones"
    $dnscmdOut = Invoke-Expression $enumZonesExpression
    if(-not($dnscmdOut[$dnscmdOut.Count - 2] -match "Command completed successfully."))
    {
        Write-Error "Failed to enumerate zones"
        return $false
    }
    else
    {
        # The output header can be found on the fifth line: 
        $zoneHeader = $dnscmdOut[4]

        # Let's define the the index,or starting point,of each attribute: 
        $d1 = $zoneHeader.IndexOf("Zone name")
        $d2 = $zoneHeader.IndexOf("Type")
        $d3 = $zoneHeader.IndexOf("Storage")
        $d4 = $zoneHeader.IndexOf("Properties")

        # Finally,let's put all the rows in a new array:
        $zoneList = $dnscmdOut[6..($dnscmdOut.Count - 5)]

        # This will store the zone objects when we are done:
        $zones = @()

        # Let's go through all the rows and extrapolate the information we need:
        foreach($zoneString in $zoneList)
        {
            $zoneInfo = @{
                Name       =   $zoneString.SubString($d1,$d2-$d1).Trim();
                ZoneType   =   $zoneString.SubString($d2,$d3-$d2).Trim();
                Storage    =   $zoneString.SubString($d3,$d4-$d3).Trim();
                Properties = @($zoneString.SubString($d4).Trim() -split " ")
                }
            $zoneObject = New-Object PSObject -Property $zoneInfo
            $zones += $zoneObject
        }

        return $zones
    }
}

现在,您可以列出所有主要区域:

Get-DNSZones|Where-Object {$_.ZoneType -eq 'Primary'}

然后,您可以使用区域阵列自动查找所有主要区域:

$PrimaryZones = Get-DNSZones|Where-Object {$_.ZoneType -eq 'Primary'}
$PrimaryZones |% {$out = iex "dnscmd . /ZoneInfo $($_.ZoneName) |find `"Zone Secondaries`" "; "$($_.ZoneName) = $out"}
原文链接:https://www.f2er.com/bash/385501.html

猜你在找的Bash相关文章