exitmap
exitmap copied to clipboard
Make modules parameterised
It should be possible to pass parameters to modules. For example, the DNS module could then be invoked with custom domains and their according IP addresses:
exitmap dns -d www.example.com 1.2.3.4
I'd like to take a crack at this; any suggestions/starting point/hints?
Python's argparse module allows sub commands, which is probably what we need here: https://docs.python.org/2.7/library/argparse.html#sub-commands
The idea is that modules can define their own sub commands that are then loaded by the main argument parsing code. That's all I have, unfortunately, so you will have to experiment a bit.
I've run into a problem here. As I understand, this is what the call should look like for parameterised modules(just an example):
./bin/exitmap --first-hop CCEF02AA454C0AB0FE1AC68304F6D8C4220C1912 dns -d www.example.com 1.2.3.4 www.foobar.com 11.22.33.44 checktest
As we want to take multiple values for -d, i.e. multiple custom domains and IP addresses for dns, it takes checktest as a parameter for -d, which is a problem.
There is probably no elegant way to do this in the exitmap.py itself using subparsers.
It will have to be done like this:
./bin/exitmap dns -d www.example.com 1.2.3.4 www.foo.com 5.6.7.8 -- checktest
or by calling the script twice
./bin/exitmap dns -d www.example.com 1.2.3.4 www.foo.com 5.6.7.8
./bin/exitmap checktest
Plus, I then have to name all modules while writing the sub-parsers, and thus the parser will need to be modified every time a module is to be added or deleted.
A solution I can think of can be to parse the command-line arguments to the modules in the module itself, i.e. parse_known_args()
in exitmap.py
, and parse the remaining_argv
in their respective modules.
What do you think?
Could you give here a list parameters to the modules? So far you have given only an example and I would like to know the parameters to be able to code them.
For the DNS module, I think we would certainly like a destination
argument. That would also come in handy for the cloudflared module. We could also create an argument for the patchingCheck module, to instruct it to download arbitrary files.
It would be great if we could take the current values as default values, if no module argument is given.
Can I proceed on this using optparse?
Can I proceed on this using optparse?
Feel free to give it a shot!