首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何清理质量输出(-oG)

如何清理质量输出(-oG)
EN

Stack Overflow用户
提问于 2014-06-04 03:28:18
回答 1查看 2.3K关注 0票数 0

masscan实用程序生成的带有-oG选项的输出("grep-able“输出)有问题;例如,它输出如下:

代码语言:javascript
运行
复制
# Masscan 1.0.3 scan initiated Wed Jun  4 01:35:02 2014
# Ports scanned: TCP(3;21-23,) UDP(0;) SCTP(0;) PROTOCOLS(0;)
Host: 192.168.100.19 () Ports: 2222/open/tcp////
Host: 192.168.100.13 () Ports: 2222/open/tcp////
Host: 192.168.100.16 () Ports: 443/open/tcp////
Host: 192.168.100.8 ()  Ports: 21/open/tcp////
Host: 192.168.100.5 ()  Ports: 22/open/tcp////
Host: 192.168.100.5 ()  Ports: 443/open/tcp////
Host: 192.168.100.16 () Ports: 80/open/tcp////
Host: 192.168.100.19 () Ports: 22/open/tcp////
Host: 192.168.100.7 ()  Ports: 80/open/tcp////
Host: 192.168.100.8 ()  Ports: 80/open/tcp////
Host: 192.168.100.12 () Ports: 2222/open/tcp////
Host: 192.168.100.13 () Ports: 22/open/tcp////
# Masscan done at Wed Jun  4 01:35:16 2014

上面的内容既不容易读,也不容易理解。

如何使用Linux命令行实用程序,例如sedawkgrep,使用上面的文件输出如下内容?

代码语言:javascript
运行
复制
Host: 192.168.100.5
Ports: 22, 443

Host: 192.168.100.7
Ports: 80

Host: 192.168.100.8
Ports: 21, 80

Host: 192.168.100.12
Ports: 2222

Host: 192.168.100.13
Ports: 2222, 22

......

如您所见,在这个布局中,输出的可读性要高得多:按IP地址排序,下面列出的所有相关端口都合并在具有相同IP地址的多个输入行中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-04 04:28:19

试试这个:

代码语言:javascript
运行
复制
awk -F' +|/' '
  !/\s*#/ {    # ignore comment lines
      # Add the port on the current line to the associative array 
      # element for the IP address on the current line.
    ips[$2] = ips[$2] (ips[$2] == "" ? $5 : ", " $5)
  }
  END {
      # Enumerate all IPs and the ports for each.
      # Since the IPs will be listed in no specific order, the output
      # is piped as a _single_ line to "sort" in order to sort by IP address,
      # and then expanded into 2 lines via "tr".
    for (ip in ips) {
      printf "Host: %s@Ports: %s@\n", ip, ips[ip] | \
        "sort -t. -n -k 1.6,1 -k 2,2 -k 3,3 -k 4,4 | tr @ \"\n\""
    } 
  }
  ' file
  • 该解决方案根据IP地址对输出进行适当排序,并用逗号分隔端口。
  • 相反,对于给定的IP地址,端口号按输入中遇到的顺序列出(如问题中的示例输出数据)。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24028505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档