Windows 上的类似挖掘功能?

Jas*_*rte 5 windows powershell perforce dig

在 Windows 系统上,我试图收集 DNS 名称的所有 IP 地址并使用每个 IP 地址调用一个工具。我知道如何从 shell 脚本执行此操作 - 但不知道如何从批处理或 powershell 文件执行此操作。

我想把它移植到windows..

#!/usr/bin/env bash
# Get all the IPs for our server instance
# and pass it to "p4 trust" to update the .p4trust file
for address in $(dig perforce.example.com +short)
do
    echo "processing address: $address:1666"
    p4 -p "ssl:$address:1666" trust -y -f || true
done
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 是否有预安装的 Windowsdig等效项仅返回 DNS 记录的 IP?
  2. 在批处理或 powershell 文件中,如何迭代来自另一个应用程序的多个结果?

pos*_*ote 6

尝试这个...

Get-Command -Name Resolve-Dns* | 
Format-Table -AutoSize

CommandType Name                   Version Source       
----------- ----                   ------- ------       
Cmdlet      Resolve-DnsName        1.0.0.0 DnsClient     

# Get parameters, examples, full and Online help for a cmdlet or function

(Get-Command -Name Resolve-DnsName).Parameters
Get-help -Name Resolve-DnsName -Examples
Get-help -Name Resolve-DnsName -Full
Get-help -Name Resolve-DnsName -Online


# Get all IPAddresses for the provided DNS name
$env:USERDNSDOMAIN | ForEach{Resolve-DnsName -Name $PSItem}

Name          Type   TTL   Section    IPAddress                                
----          ----   ---   -------    ---------                                
CONTOSO.COM A      600   Answer     192.168....                             
CONTOSO.COM A      600   Answer     10.10... 

# 
$env:USERDNSDOMAIN | 
ForEach{
    # Get all IP addresses for the provided DNS name
    $DNSIPA = (Resolve-DnsName -Name $PSItem).IPAddress
    
    # Check if the host is up for a given IPA and port number
    ForEach($IPA in $DNSIPA)
    {
        "Processing $IPA"
        Test-NetConnection -ComputerName $IPA -Port 1666
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,这个问题会转化为您是 PowerShell 的新手。因此,在您造成不必要的困惑/沮丧等之前,您必须花时间使用所有可用的免费 PowerShell 视频和电子书培训资源来加快速度。这里仅仅是少数。

MSDNMSDocsMVAMSChannel9YouTubeeBooks使用上述帮助文件。