如何清理Masscan输出(-oL) [英] How to clean up masscan output (-oL)
问题描述
我对使用-oL选项的masscan实用程序产生的输出有问题(可复制的"输出);例如,它输出以下内容:
I have a problem with the output produced by the masscan utility with the -oL options ("grep-able" output); for instance, it outputs this:
Host: 143.137.155.7 () Ports: 80/open/tcp////
Host: 177.105.21.41 () Ports: 8080/open/tcp////
Host: 187.78.236.98 () Ports: 80/open/tcp////
Host: 177.137.76.220 () Ports: 8080/open/tcp////
Host: 177.105.10.112 () Ports: 9000/open/tcp////
Host: 191.232.34.9 () Ports: 80/open/tcp////
Host: 179.55.65.144 () Ports: 80/open/tcp////
Host: 177.83.203.147 () Ports: 8080/open/tcp////
Host: 177.182.50.124 () Ports: 8000/open/tcp////
上面的内容既不可读也不容易理解.
The above is neither very readable nor easy to understand.
如何使用Linux命令行实用程序,例如sed,awk或grep,使用上面的文件输出以下内容?
How can I use Linux command-line utilities, e.g. sed, awk, or grep, to output something as follows, using the file above?
143.137.155.7:80
177.105.21.41:8080
187.78.236.98:80
177.137.76.220:8080
177.105.10.112:9000
推荐答案
如何
sed 's/^Host: \([0-9.]*\).*Ports: \([0-9]*\).*$/\1:\2/g'
说明:
-
s/regex/replacement/
将regex
替换为replacement
-
^
匹配字符串的开头 -
Host:
与自己匹配 -
[0-9.]
是与数字0到9和.
匹配的字符范围
-
[0-9.]*
匹配零个或多个数字/点 -
\([0-9.]*\)
将匹配的IP地址替换为\1
-
.
匹配任何单个字符 -
.*
匹配零个或多个单个字符(即任何字符串) -
Ports:
与自己匹配 -
\([0-9]*\)
匹配一串数字,并使其作为\2
可用
-
.*$
与字符串的其余部分匹配
s/regex/replacement/
substitutesregex
withreplacement
^
matches the start of the stringHost:
matches itself[0-9.]
is a character range that matches the digits 0 to 9 and.
[0-9.]*
matches zero or more digits/dots\([0-9.]*\)
makes the matched IP address available in the replacement as\1
.
matches any single character.*
matches zero or more single characters (i.e. any string)Ports:
matches itself\([0-9]*\)
matches a string of digits and makes it available as\2
.*$
matches the rest of the string
最后的标志g
将替换应用于所有匹配项,而不是每行的第一个匹配项.在这种情况下,只能有一个匹配项(整行),因此该标志不会执行任何操作.我是出于习惯输入它的.
The flag g
at the end applies the replacement to all matches rather than the first match on each line. In this case, there can only be one match (the entire line), so the flag doesn't do anything. I type it out of habit.
这篇关于如何清理Masscan输出(-oL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!