Add -f option for CSV output to allow field filtering
Description
This PR enhances the existing -csv output functionality by adding support for a -f (or --fields) option. Users can now specify which columns they want in the CSV output instead of always receiving all available fields.
Related Issue
Closeshttps://github.com/projectdiscovery/naabu/issues/1371
Changes Introduced
Added -f option to allow field filtering when using -csv. Updated CSV output logic to include only specified fields.
Example Usage
Outputs only the ip and port columns instead of the full dataset.
naabu$ ./naabu -host example.com -p 80,443 -csv -f "ip,port"
__
___ ___ ___ _/ / __ __
/ _ \/ _ \/ _ \/ _ \/ // /
/_//_/\_,_/\_,_/_.__/\_,_/
projectdiscovery.io
[INF] Current naabu version 2.3.4 (latest)
[INF] Host discovery disabled: less than two ports were specified
[INF] Running CONNECT scan with non root privileges
ip,port
23.215.0.138,443
ip,port
23.215.0.138,80
[INF] Found 2 ports on host example.com (23.215.0.138)
In a future update, we can extend this functionality so that -json -f "ip,port" also filters the JSON response accordingly.
Looking forward to feedback!
Thanks for your contribution @soonghee2 ! :)
Code updated!
- Renamed variable
CSVFieldstoFields. - Refactored
WriteCsvOutputandCSVHeadersto handle the main field filtering logic. - Updated comments and removed unnecessary whitespace.
@soonghee2 thanks for the PR, we are reworking this in https://github.com/projectdiscovery/naabu/pull/1387 using common utils, so similar option can be used across other projects as well.
Closing this. Suppressed by https://github.com/projectdiscovery/naabu/pull/1387