So, I'm trying to get similar results using python as I do with a bash script.
Code for the bash script:
#!/bin/bash for ip in $(seq 1 254); do ping -c 1 10.10.10.$ip | grep "bytes from" | cut -d " " -f 4 | cut -d ":" -f 1 & done
The thing that I would like to do is get the same results with similar speed. The issue that I've had with every version of the python script is that it takes a very long time to complete compared to the few seconds the batch script takes.
The batch file takes about 2 seconds to sweep a /24 network while the the best I can get with the python script is about 5-8 minutes.
Latest version of python script:
import subprocess cmdping = "ping -c1 10.10.10." for x in range (2,255): p = subprocess.Popen(cmdping+str(x), shell=True, stderr=subprocess.PIPE) while True: out = p.stderr.read(1) if out == '' and p.poll() != None: break if out != '': sys.stdout.write(out) sys.stdout.flush()
I've tried several different ways in python but can't get anywhere near the speed of the bash script.
Any suggestions?