需要一个 windows Nmap 行用于“# awk '/open/{print $2}' hostdiscovery.gnmap > livehosts.txt”

问题描述

我需要在第一次扫描端口后执行这一步,之后我有一个 hostdiscovery.gnmap 文件,这是我的下一步:

awk '/open/{print $2}' hostdiscovery.gnmap > livehosts.txt

但这是一个 Linux 命令行,我在这个项目中使用了 Windows,我需要在我的 PC 上执行...你知道我如何获得类似的 Windows 命令吗?

这是我在第 2 步的来源:https://www.networkstraining.com/nmap-commands-cheat-sheet/

解决方法

使用 Powershell:

ForEach ( $lin in Get-Content hostdiscovery.gnmap ) { if ($lin -like "*open*") { $wrds=$lin.Split(" "); Write-Output $wrds[1] } } >> livehosts.txt

逐行读取文件hostdiscovery.gnmap,如果该行包含“open”,则将该行拆分为数组wrds并打印第一个索引(第二个字)