Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  1. is there a pre-installed windows dig equivalent that will only return the IPs of the DNS record?
  2. in a batch or powershell file, how do you iterate over multiple results from another application?
like image 252
Jason De Arte Avatar asked Jan 14 '19 04:01

Jason De Arte


People also ask

Is there a dig command in Windows?

The dig command (Domain Information Groper) is a popular Linux utility used for performing DNS lookups. It provides more flexibility than Windows NSLookup but, unfortunately, it isn't available in Windows 10 by default. One option for using dig on Windows is to install BIND.

What is dig in CMD?

The dig (domain information groper) command is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the queried name server(s).

What is the difference between nslookup and dig commands?

Dig and nslookup are two tools that can be used to query DNS servers. They both perform similar functions, but there are some key differences. For example, nslookup can only be used to query one DNS server at a time, while dig can query multiple DNS servers simultaneously.


1 Answers

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.

like image 140
postanote Avatar answered Oct 06 '22 00:10

postanote