Repository navigation
Commit ada4124
feat: add greppable output (spoonmap_output.gnmap)
Closes #36. Originally proposed in PR #11 (Feb 2021), closed as unmergeable.
Each port's banner pass now writes nmap_results/portN.gnmap via -oG, and those
are merged into spoonmap_output.gnmap after the workers join.
Why not #11's approach: it pointed every port at one shared -oG file with
--append-output. That was safe when nmap ran serially, but nmap_scan() now runs
five concurrent workers, so five processes would interleave their appends into a
plausible-looking but corrupt host list — the worst outcome for a format whose
whole purpose is machine consumption. One file per port gives each a single
writer.
Merged, not concatenated: a host open on three ports is scanned by three nmap
runs and so appears in three files, but grepable output is one line per host.
Concatenating would make anything counting lines over-count hosts and would
disagree with spoonmap_output.xml/.json, which merge the same hosts. Hosts are
ordered by _ip_sort_key() and port entries numerically, so the file is stable
across runs and diffable between scans.
Two consistency details:
- _quarantine_failed_output() now renames the sibling .gnmap too. Otherwise a
port excluded from spoonmap_output.xml would still contribute its partial
hosts to spoonmap_output.gnmap, leaving the greppable artifact the more
optimistic of the two about what was actually scanned.
- Ports holding an .xml with no .gnmap — what a resume from before this feature
looks like — are named in a warning instead of being silently absent. An
artifact that quietly covers less than the run did is a coverage claim the
scan never made. port{N}_sql.xml is excluded from that check, since
_scan_extra_sql_ports() writes it with no -oG and it is not a gap.
Adding .gnmap to nmap_results/ is safe for existing readers: all three that scan
the directory filter on an .xml extension, and _parse_result_xml() returns None
for anything else. spoonmap_output.gnmap is registered in _RESULT_FILES so
--cleanup removes it.
The parser was verified against real nmap 7.99 -oG output, not just a fixture:
tab-separated fields, the 'Status: Up' line emitted alongside the ports line,
the trailing 'Ignored State' field, and the comment header/footer.
939 tests pass (32 new), 100% coverage.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 9675406 commit ada4124
3 files changed
Lines changed: 411 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
284 | 285 | | |
285 | 286 | | |
286 | 287 | | |
287 | 288 | | |
| 289 | + | |
288 | 290 | | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
292 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
293 | 310 | | |
294 | 311 | | |
295 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1155 | 1155 | | |
1156 | 1156 | | |
1157 | 1157 | | |
1158 | | - | |
| 1158 | + | |
1159 | 1159 | | |
1160 | 1160 | | |
1161 | 1161 | | |
| |||
1979 | 1979 | | |
1980 | 1980 | | |
1981 | 1981 | | |
1982 | | - | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
1983 | 1989 | | |
1984 | 1990 | | |
1985 | 1991 | | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
1986 | 1997 | | |
1987 | 1998 | | |
1988 | 1999 | | |
| |||
2001 | 2012 | | |
2002 | 2013 | | |
2003 | 2014 | | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
2004 | 2021 | | |
2005 | 2022 | | |
2006 | 2023 | | |
| |||
2009 | 2026 | | |
2010 | 2027 | | |
2011 | 2028 | | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
2012 | 2033 | | |
2013 | 2034 | | |
2014 | 2035 | | |
| |||
4560 | 4581 | | |
4561 | 4582 | | |
4562 | 4583 | | |
| 4584 | + | |
| 4585 | + | |
| 4586 | + | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
| 4590 | + | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
| 4594 | + | |
| 4595 | + | |
| 4596 | + | |
| 4597 | + | |
| 4598 | + | |
| 4599 | + | |
| 4600 | + | |
| 4601 | + | |
| 4602 | + | |
| 4603 | + | |
| 4604 | + | |
| 4605 | + | |
| 4606 | + | |
| 4607 | + | |
| 4608 | + | |
| 4609 | + | |
| 4610 | + | |
| 4611 | + | |
| 4612 | + | |
| 4613 | + | |
| 4614 | + | |
| 4615 | + | |
| 4616 | + | |
| 4617 | + | |
| 4618 | + | |
| 4619 | + | |
| 4620 | + | |
| 4621 | + | |
| 4622 | + | |
| 4623 | + | |
| 4624 | + | |
| 4625 | + | |
| 4626 | + | |
| 4627 | + | |
| 4628 | + | |
| 4629 | + | |
| 4630 | + | |
| 4631 | + | |
| 4632 | + | |
| 4633 | + | |
| 4634 | + | |
| 4635 | + | |
| 4636 | + | |
| 4637 | + | |
| 4638 | + | |
| 4639 | + | |
| 4640 | + | |
| 4641 | + | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
| 4653 | + | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
| 4666 | + | |
| 4667 | + | |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
| 4671 | + | |
| 4672 | + | |
| 4673 | + | |
| 4674 | + | |
| 4675 | + | |
| 4676 | + | |
| 4677 | + | |
| 4678 | + | |
| 4679 | + | |
| 4680 | + | |
| 4681 | + | |
| 4682 | + | |
| 4683 | + | |
| 4684 | + | |
| 4685 | + | |
| 4686 | + | |
| 4687 | + | |
| 4688 | + | |
| 4689 | + | |
| 4690 | + | |
| 4691 | + | |
| 4692 | + | |
| 4693 | + | |
| 4694 | + | |
| 4695 | + | |
| 4696 | + | |
| 4697 | + | |
| 4698 | + | |
| 4699 | + | |
| 4700 | + | |
| 4701 | + | |
| 4702 | + | |
| 4703 | + | |
4563 | 4704 | | |
4564 | 4705 | | |
4565 | 4706 | | |
| |||
5702 | 5843 | | |
5703 | 5844 | | |
5704 | 5845 | | |
| 5846 | + | |
| 5847 | + | |
| 5848 | + | |
| 5849 | + | |
| 5850 | + | |
5705 | 5851 | | |
5706 | 5852 | | |
5707 | 5853 | | |
| |||
0 commit comments