CLI option to also show closed ports - #736
Merged
Merged
Conversation
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
January 23, 2025 12:47
db1f410 to
64e6ad4
Compare
fabianbees
force-pushed
the
feat/show_closed_ports
branch
2 times, most recently
from
February 10, 2025 09:04
9b56a19 to
462771a
Compare
Contributor
Author
|
I have rebased the feature onto master. |
fabianbees
force-pushed
the
feat/show_closed_ports
branch
2 times, most recently
from
February 24, 2025 06:29
01a0d89 to
29b77d6
Compare
Contributor
Author
|
@bee-san Can you please also have a look at this PR? |
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
March 3, 2025 08:52
29b77d6 to
f76d254
Compare
fabianbees
force-pushed
the
feat/show_closed_ports
branch
2 times, most recently
from
March 18, 2025 08:56
b04d8f5 to
882789e
Compare
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
March 24, 2025 11:54
882789e to
498dbf7
Compare
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
April 1, 2025 13:41
498dbf7 to
e014b0e
Compare
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
April 24, 2025 08:45
e014b0e to
16f97cd
Compare
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
June 6, 2025 10:01
16f97cd to
773cc2c
Compare
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
October 24, 2025 12:57
773cc2c to
5194440
Compare
Owner
|
thanks for this! has a merge conflict :( |
fabianbees
force-pushed
the
feat/show_closed_ports
branch
from
June 9, 2026 10:16
5194440 to
7d9fc7c
Compare
Contributor
Author
|
Hi @bee-san, I have rebased this PR again onto master, so no more merge conflicts anymore. Can you please have another look? I am looking forward in getting this merged, thank you! |
master has changed the scanner and main heavily since this branch (quiet library output bee-san#916, println_safe bee-san#941, UDP payload lookup bee-san#886, removal of the socket-opening tests and benchmark_portscan.rs bee-san#942). Take master's src/main.rs, src/scanner/mod.rs and src/lib.rs here and keep the --closed option/config plumbing from this branch; the scanner/main side of the feature is re-applied on top in the next commit.
Re-apply the scanner/main side of --closed on top of current master: - Scanner::with_closed_ports() opts into reporting TCP ports that refuse the connection as PortStatus::Closed. Scanner::new() and run() keep their signatures and semantics; run_with_status() returns open and closed sockets. - Without --closed nothing changes: refused connections are retried and dropped as before, so no extra memory is used for 65k closed ports and the 'no open ports found' hint still appears for hosts that only reject. - With --closed, closed ports are printed live (non-greppable) and listed in a 'closed ports:' summary. Scripts (nmap) are only ever run against open ports. Based on the original implementation by @fabianbees. Co-authored-by: Fabian <fabianbees@users.noreply.github.com>
bee-san
approved these changes
Oct 1, 2026
bee-san
left a comment
Owner
There was a problem hiding this comment.
Thanks @fabianbees, and sorry it took so long! Seeing RSTs really is useful for spotting firewalls. The scanner and main had changed a lot on master, so I re-applied your feature on top, credited to you, with a few changes to keep it safe and non-breaking:
- No change without
--closed. Before, refused connections were returned asClosedon every scan. That cost memory on full-range scans (up to 65k closed entries) and hid the 'no open ports found' hint for hosts that only reject. Now they're only collected when--closedis set. - Scripts only run on open ports.
print_summarywould have started the default nmap script against closed ports. Closed ports are now only printed: live asClosed ip:port, then in yourclosed ports:summary. - No library API break.
Scanner::new()andrun()keep their signatures.Scanner::with_closed_ports()andrun_with_status() -> Vec<PortStatus>are new, following the builder pattern from #916.
CI is green on all four platforms.
Contributor
Author
|
Excellent, thank you very much for having a look at this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the new CLI option
--closed, which enables the option to also show ports which are closed.From a security perspective, it is very useful information to see whether we got any response at all for a given port, even when the response is a RST (conn-refused).
It can indicate that our request was denied (or specifically blocked by a firewall).
Currently this behavior is behind the
--closedCLI flag and not enabled by default.Nmap, for example, shows closed ports by default.
Regarding the output of the
--closedoption, it mimics the output for open ports, but instead ofOpenit showsClosedright before the IP Address.If the
-g(grepable) option is set, first all open ports are printed for each IPs, then the text closed ports: is printed and the same output is repeated for all closed ports.Here is an example:
And with the -g option: