windows - dig-like functionality on windows?
问题描述
On a windows system, I'm trying to gather all the IP addresses for a DNS name & call a tool with each IP address. I know how to do it from a shell script - but not how to do it from a batch or powershell file.
I want to port this to 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
Questions:
- is there a pre-installed windows
dig
equivalent that will only return the IPs of the DNS record? - in a batch or powershell file, how do you iterate over multiple results from another application?
解决方案
Try this...
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
}
}
Yet, this question would translate into you are new to PowerShell. So, before you cause yourself undue confusion/frustration, etc., it is vital you spend the time getting up to speed on it using all the available free PowerShell video and eBook training resources. Here are just a few.
MSDN, MSDocs, MVA, MSChannel9, YouTube, eBooks, use the help files as noted above.
推荐阅读
- python - Python dataframe group by index level rather than index names
- javascript - Firestore 查询未获取最新数据
- php - Laravel在生产环境中“无法找到组件的类或视图”
- sql - 选择更新时的 SQL 死锁
- php - Cake PHP 迁移后图像丢失/损坏
- sql - 根据几个标准选择最后一条记录
- ms-word - 在 Word 中显示方程式编号的域代码
- php - 如何在没有 UI 的情况下通过代码更改元素或小部件的内容
- c# - SignalR 客户端使用机器上的所有端口
- java - 使用 JPA createQuery() 获取数百万条记录时超出 GC 开销限制;