Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -f option for CSV output to allow field filtering #1372

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

soonghee2
Copy link
Contributor

@soonghee2 soonghee2 commented Feb 3, 2025

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//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!

@GeorginaReeder
Copy link

Thanks for your contribution @soonghee2 ! :)

@soonghee2 soonghee2 marked this pull request as draft February 4, 2025 12:54
@soonghee2 soonghee2 marked this pull request as ready for review February 4, 2025 12:59
This commit refactors the CSV header and field handling logic to remove code duplication and improve readability. It consolidates the header and field selection functionality using the `selectedFields` parameter and eliminates the unnecessary global variable.
@soonghee2 soonghee2 marked this pull request as draft February 4, 2025 13:13
This commit addresses two issues:

- Fixed an import error that was preventing the code from compiling correctly.  The specific import that was missing or incorrect has been corrected.
- Removed the unnecessary `selectedFields` variable declaration. This variable was declared but not used, so it has been removed to clean up the code.
This commit addresses two issues:

- **Invalid Option Handling:** Modified the code to invalidate the option when "-f "" " is provided as input. This prevents unexpected behavior or errors when an empty string is passed with the -f flag.

- **GitHub Lint Test Fixes:** Implemented necessary changes to ensure the code passes the GitHub lint tests. These modifications address any style, formatting, or potential code quality issues identified by the linter.
@soonghee2 soonghee2 marked this pull request as ready for review February 4, 2025 13:48
@soonghee2
Copy link
Contributor Author

Code updated!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants