I am trying to write a python script to test a 4 digit pincode with brute forcing(and a password) when connecting to local host. The command that needs to be run is:
echo password pincode | nc localhost 30002 >> /tmp/joesPin/pinNumber
(writes response to a new file).
This worked when written as a bash script, but I am struggling with the subprocess module in Python.
import subprocess
password = "UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ"
for i in range(10000):
pincode = str('{0:04}'.format(i)) #changes 4 to 0004
subprocess.call('echo', password, pincode,'|','nc localhost 30002 >> /tmp/joesPin/' + pincode,shell=True)
I want it to call:
echo UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ 0001 | nc localhost 30002 >> /tmp/joesPin/0001