Export Scan Results
In this step, you will learn how to export your Masscan results into different file formats. Exporting scan data properly is crucial because it allows you to analyze the findings, share reports with team members, or feed the data into other security tools. We'll create three common formats: CSV for spreadsheet analysis, plain text for quick review, and JSON for automated processing.
First, navigate to your project directory where the scan results are stored. This ensures all exported files will be saved in the correct location:
cd ~/project
The first conversion creates a CSV (Comma-Separated Values) file. CSV is ideal for importing into spreadsheet software like Excel. The awk command extracts the IP address, port number, and service name from the grepable format file:
awk -F'[ /]' '/Host:/ {ip=$2} /open/ {print ip","$4","$7}' scan_results.gnmap > scan_results.csv
Next, we'll generate a simple text report that's easy to read in terminal or text editors. This format is useful when you need to quickly check which hosts have open ports without opening a spreadsheet:
grep "open" scan_results.gnmap | awk '{print "Host:", $2, "Port:", $4}' > scan_report.txt
For integration with other tools or scripts, we'll create a JSON file. JSON is a structured format that most programming languages can easily parse. The commands below build a proper JSON array with all scan results:
echo '[' > scan_results.json
grep "open" scan_results.gnmap | awk '{print "{\"host\":\""$2"\",\"port\":\""$4"\",\"service\":\""$7"\"},"}' >> scan_results.json
sed -i '$ s/,$//' scan_results.json
echo ']' >> scan_results.json
Finally, verify all exported files were created successfully. This command lists the files with their sizes so you can confirm the exports worked as expected:
ls -l scan_results.* scan_report.txt
You should see output similar to:
-rw-r--r-- 1 labex labex 1234 scan_results.csv
-rw-r--r-- 1 labex labex 5678 scan_results.json
-rw-r--r-- 1 labex labex 9012 scan_report.txt