Skip to content
Advertisement

How to clean up masscan output (-oG)

I have a problem with the output produced by the masscan utility with the -oG options (“grep-able” output); for instance, it outputs this:

JavaScript

The above is neither very readable nor easy to understand.

How can I use Linux command-line utilities, e.g. sed, awk, or grep, to output something as follows, using the file above?

JavaScript

As you can see, the output is much more readable in this layout: sorted by IP address, with all associated ports listed below, consolidated across multiple input lines with the same IP address.

Advertisement

Answer

Try this:

JavaScript
  • This solution properly sorts the output by IP address and separates the ports with commas.
  • By contrast, for a given IP address, the port numbers are listed in the order they were encountered in the input (as in the sample output data in the question).
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement