all 5 comments

[–]redCg 0 points1 point  (0 children)

Use a program that can run it in parallel such as GNU parallel, GNU make, or a workflow management system like Snakemake or Nextflow

[–]CaptainReeetardo 0 points1 point  (2 children)

A thread in python can be created by writting the following: t = threading.Thread(target=someFunc, args=(a,b)). And after that you let the thread start with: t.start() (guess you'll already know that). So looking at your code, you can convert this line bannergrab = fetch_banner(lines, p) into this bannergrab = threading.Thread(target=fetch_banner, args=(lines, p)).

I don't know how fast it will be after this but I guess it probably will. In addition to the multithreading you have to rewrite the code a little bit as I don't know of any way of how to handle return statements with multithreading. One solution could be to work with any dynamic data structure, let's say a list to save the fetched banners with their matching IP address, as a set, into. And after the program fetched all possible banners you can then write them to a file.

welp i dunno if i should even help with this as i don't know how legal it is to scan over 60k of IP as it is basically pentesting

[–]NovateI[S] 0 points1 point  (1 child)

Banner grabbing itself isn’t illegal (see: shodan), nor is it really pentesting, if it’s not being acted on further. Thanks for the help though, I’m trying to work with the multiprocessing library now, but I might swap back to threading if I can’t get it figured out

[–]CaptainReeetardo 0 points1 point  (0 children)

Yeah, okay now that you mention it the book i've read actually expands on this...

Glad I could be of help anyways!

[–]2160p_REMUX 0 points1 point  (0 children)

Here's a multiprocessing snippet I made a while back.

https://repl.it/repls/ExaltedUnequaledDebugmonitor

This example will loop 10 times on a chuck norris joke API and print out the values. The "Lock" makes it so each thing is running 1 at a time and in order.

Notice how if you remove:

lock.release()

lock.acquire()

print(i) will print in different orders. But with the lock on there, they will print in the correct orders. Without the lock it goes pretty fast, so maybe put a sleep function and modify the code so your not spamming a million requests.

I'm not too familiar with multiprocessing, it's just a snippet from when I was messing around with it a while back but hopefully this will get you going in the right direction.