feat(scan): work out the network you are on instead of demanding a CIDR - #7
Merged
Conversation
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.
Two commits, the second found while testing the first.
The subnet is now optional
netdiff scanandnetdiff auditwork out the network you are on. Walking into somewhere new and running the tool no longer means first going to read your own IP settings.local_address()gets our own address byconnecting a UDP socket to TEST-NET-1. A connected UDP socket sends nothing - the kernel just consults the routing table and binds a source address, which is exactly the question being asked. The destination is reserved and routed nowhere, so that stays true even if it ever did send.The mask is then read from
ip -o -4 addrorifconfig, in all three shapes those print it: a CIDR suffix, a macOS hex mask, a Linux dotted mask. Samerunner=seam asread_arp_table, so the tests cover all three against captured output without touching a socket.If the mask cannot be read it raises and asks for a subnet rather than assuming /24. Guessing would be right most of the time, which is precisely the kind of nearly-true this tool refuses everywhere else.
resolve_subnetprints the subnet it inferred. That is not decoration - a scan whose target was inferred has to show its target, or the report is about a network the reader never chose.--no-portswas inventing changesFound by running the above against a live network:
Nothing closed. Nothing was looked at. A device with no ports scanned and a device with no ports open are the same empty tuple, so the diff could not tell them apart and the caller has to say -
diff(..., compare_ports=False).Worth fixing properly rather than quietly: a change that did not happen is the one failure mode
diff.pyexists to avoid, and it is the same class of decision already made forservices, which is deliberately never compared because one missed mDNS reply would report a change every other scan.