開いているすべてのポートを含むIPのリストを印刷するには、awkを使用してnmap出力ファイルを解析します。

開いているすべてのポートを含むIPのリストを印刷するには、awkを使用してnmap出力ファイルを解析します。

コマンドを使用して、開いているすべてのポートを含むIPアドレスのリストを見つけたいと思いますawk

私のnmap出力ファイルは次のとおりです。

# Nmap 7.01 scan initiated Sat Mar 18 06:27:08 2017 as: nmap -oG output.txt -T4 -f -iL iplist.txt
Host: 10.0.0.99 ()    Status: Up
Host: 10.0.0.99 ()    Ports: 135/open/tcp//msrpc///, 139/open/tcp//netbios-ssn///, 445/open/tcp//microsoft-ds///, 514/filtered/tcp//shell///, 554/open/tcp//rtsp///, 10243/open/tcp//unknown///    

Host: 192.168.0.1 ()    Status: Up
Host: 192.168.0.1 ()    Ports: 135/open/tcp//msrpc///, 139/open/tcp//netbios-ssn///, 445/open/tcp//microsoft-ds///, 10243/open/tcp//unknown/// 

Host: 192.168.0.101 ()    Status: Up
Host: 192.168.0.101 ()    Status: Up
# Nmap done at Sat Mar 18 06:29:02 2017 -- 3 IP addresses (3 hosts up) scanned in 113.19 seconds

予想出力:

10.0.0.99   135
10.0.0.99   139
10.0.0.99   445
10.0.0.99   514
10.0.0.99   554
10.0.0.99   10243
192.168.0.1 135
192.168.0.1 139
192.168.0.1 445 
192.168.0.1 10243

出力は他のファイル(parse.txtなど)に保存されます。

ベストアンサー1

と聞いてみましょうawkが、Perlでは正規表現の複数の一致を簡単に繰り返すことができるので、これはPerlに関してマイナーなことです。

$ perl -ne '$host = $1 if /^Host: (\S+)/; while(m,(\d+)/open,g) 
    { print "$host\t$1\n" } ' < nmap.out 
10.0.0.99       135
10.0.0.99       139
...


perl -ne                       # Run the code for each input line
'$host = $1 if /^Host: (\S+)/  # If the line starts with "Host: ", 
                               # save the next non-whitespace string
while( m,(\d+)/open,g ) {      # Go through all matches of `<digits>/open`
                               # on the line, catching the digits
    print "$host\t$1\n"        # Print the saved hostname and the matched digits.
}'                              

おすすめ記事