Please see this thread for reference
How can I scan using nmap and Zenmap all hostnames that begin with a particular string?
One of the answers in the thread above uses the following query (I take no credit at all for the command):
nmap -sL -oG - 192.168.0.0/24 | awk '$3~/^(org/{print $2}' | nmap -iL -`
It scans all nodes for hostnames starting with org and returns a list of matching nodes.
It works great in a Unix/Linux environment, but I need an equivalent for Windows. I'd prefer not to use awk, sed, or grep packages for Windows. I'd like to maintain a standard and use PowerShell and/or Perl.
Is there an equivalent way to construct this query using PowerShell and/or Perl, along with nmap?
The Nmap parts of that command should work the same. To convert the
awk
command to Perl, use:(Because of quoting differences between Windows cmd.exe and most *nix shells, *nix shells should use single quotes instead of double)
To do the same in PowerShell, this should work (not tested):