【问题标题】:dig-like functionality on windows?Windows上的类似挖掘功能?
【发布时间】:2019-06-08 02:42:43
【问题描述】:

在 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

问题:

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

【问题讨论】:

  • foreach 在 powershell 中。你有 nslookup 和 resolve-dnsname。不要使用批处理。毕竟是 2019 年。

标签: windows powershell perforce dig


【解决方案1】:

试试这个...

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
    }
}

然而,这个问题将转化为您是 PowerShell 的新手。因此,在你给自己造成过度的困惑/沮丧等之前,花时间使用所有可用的免费 PowerShell 视频和电子书培训资源来加快速度是至关重要的。这里只是一些。

MSDNMSDocsMVAMSChannel9YouTubeeBooks,使用上述帮助文件。

【讨论】:

  • 不错!这正是我一直在寻找的。谢谢@postanote!
  • 不用担心。很高兴它会有所帮助。只是一个注释。 Test-NetConnection 不在所有版本的 PowerShell 中,并且取决于您所在的操作系统。如果您不在具有此 cmdlet 的 PowerShell / OS 版本上,则需要借助 .Net TCPClient 命名空间来执行此类操作,好吧,用于端口检查。例如:community.idera.com/database-tools/powershell/powertips/b/tips/…
猜你喜欢
  • 2021-09-20
  • 1970-01-01
  • 2011-02-22
  • 2011-02-07
  • 1970-01-01
  • 1970-01-01
  • 2014-02-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多