本文介绍了提取NMAP特定模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我有nmap的结果,像这样:

Imagine I have nmap results like so:

# Nmap 6.40 scan initiated Sat Jun 14 10:14:35 2014 as: nmap ...
Nmap scan report for x.x.x.x.
Host is up (0.21s latency).
PORT   STATE SERVICE
23/tcp open  telnet
| telnet-brute:
|_  No accounts found

Nmap scan report for y.y.y.y
Host is up (0.24s latency).
PORT   STATE SERVICE
23/tcp open  telnet

Nmap scan report for z.z.z.z
Host is up (0.22s latency).
PORT   STATE SERVICE
23/tcp open  telnet
|_telnet-brute: var1 - <blank>

Nmap scan report for w.w.w.w
Host is up (0.36s latency).
PORT   STATE SERVICE
23/tcp open  telnet
|_telnet-brute: var2 - var3

Nmap scan report for h.h.h.h
Host is up (0.22s latency).
PORT   STATE SERVICE
23/tcp open  telnet
| telnet-brute:
|_  No accounts found

Nmap scan report for f.f.f.f
Host is up (0.22s latency).
PORT   STATE SERVICE
23/tcp open  telnet
|_telnet-brute: var4 - <blank>

Nmap scan report for b.b.b.b
Host is up (0.23s latency).
PORT   STATE SERVICE
23/tcp open  telnet
| telnet-brute:
|_  No accounts found


    .
    .
    .

Nmap scan report for a.a.a.a
Host is up (0.22s latency).
PORT   STATE SERVICE
23/tcp open  telnet

# Nmap done at Sun Jun 15 10:20:45 2014 -- 262144 IP addresses (91295 hosts up) scanned in 86769.85 seconds

我怎么能有这样的结果:

How can I have the result like:

z.z.z.z  var1
w.w.w.w  var2  var3
f.f.f.f  var4

我想,如果有不显示它。 (最好使用 SED

我会尝试是:

sed -nr '/^Nmap.* /{s///;h};/|_telnet-brute/{n;H;g;s/\n\|\s*/ /;/:/p}' file

感谢您

推荐答案

和一个通过的grep Perl的正则表达式选项,

$ grep -oP "\w\.\w\.\w\.\w|(?<=brute:).*" file | paste - -
x.x.x.x  var1 - <blank>
y.y.y.y  var2 - var3
z.z.z.z

更新:

$ awk -v RS="" '{print $5,$18,$20}' file | awk '$2~/var/ {print}'
z.z.z.z var1 <blank>
w.w.w.w var2 var3
f.f.f.f var4 <blank>

如果你再要删除&LT;坯件GT; dtring然后运行,

If you again want to remove <blank> dtring then run,

$ awk -v RS="" '{print $5,$18,$20}' file | awk '$2~/var/ {gsub (/<blank>/,""); print}'
z.z.z.z var1
w.w.w.w var2 var3
f.f.f.f var4

您可以做到这一点伊纳单awk命令,

You could do this ina single awk command,

$ awk -v RS="" '$18~/var/ {gsub (/<blank>/,""); print $5,$18,$20}' file
z.z.z.z var1
w.w.w.w var2 var3
f.f.f.f var4

这篇关于提取NMAP特定模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 14:57