naabu icon indicating copy to clipboard operation
naabu copied to clipboard

Add -f option for CSV output to allow field filtering

Open soonghee2 opened this issue 11 months ago • 3 comments

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!

soonghee2 avatar Feb 03 '25 16:02 soonghee2

Thanks for your contribution @soonghee2 ! :)

GeorginaReeder avatar Feb 04 '25 11:02 GeorginaReeder

Code updated!

  • Renamed variable CSVFields to Fields.
  • Refactored WriteCsvOutput and CSVHeaders to handle the main field filtering logic.
  • Updated comments and removed unnecessary whitespace.

soonghee2 avatar Feb 04 '25 14:02 soonghee2

@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.

ehsandeep avatar Feb 27 '25 14:02 ehsandeep

Closing this. Suppressed by https://github.com/projectdiscovery/naabu/pull/1387

dogancanbakir avatar Jul 24 '25 06:07 dogancanbakir