So, I've got a port scanner (masscan), and I want to redirect its output to a certain command-line which is going to check if every resulting IP:Port combination serves a certain web service.

So, it can go like this:

masscan -p8080 --max-rate 300000 | ./scanner.py

But this would be slow for huge IP ranges, since scanner.py is going to process one-by-one.

How can I do this in parallel? i.e redirecting each IP on its own and creating processes that will work in parallel processing the stdin that was redirected to them, thus making the scan faster.

  • 1
    You mean like creating 1000 processes per second? I don't think this is a good idea. I would rather dispatch within scanner.py, using process pool or something. – Franklin Yu Feb 9 '17 at 1:04

I'd think you can do something with xargs. For example the following:

masscan -p8080 --max-rate 300000 | \
    xargs -L1 -I+ -P200 sh -c "echo '+' | ./scanner.py"

That would run up to 200 parallel ./scanner.py, each one handling a single result line from masscan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.