Reputation: 361
I have two questions about my script, how can I get it to output to the file I requested. I ask this because it loops infinitely and when I cancel the script and show the file it is empty. Also, how can I use the variables assigned if I must cancel the script to input anything? Thanks!
import subprocess
import datetime
#open results file and assign to results variable, add append rights
results = open("results.txt", "a")
#Run until stopped
while 1:
#split the blah variable by line
#Run tshark command 100 times, then restart script. Assign to blah variable
blah = subprocess.check_output(["tshark -i mon0 -f \"subtype probe-req\" -T fields -e wlan.sa -e wlan_mgt.ssid -c 20"], shell=True)
splitblah = blah.split("\n")
#repeat for each line, ignore first line since it contains headers
for value in splitblah[:-1]:
#split each line by tab delimiter
splitvalue = value.split("\t")
#Assign variables to split fields
MAC = str(splitvalue[1])
SSID = str(splitvalue[2])
time = str(datetime.datetime.now())
#write and format output to results file
Results.write(MAC+" "+SSID+" "+time+"\r\n")
Upvotes: 0
Views: 60
Reputation: 86
You should put a condition in your while
statement, or the program will (indeed) never stop.
Also, datas are not necessarily written on the disk immediately after someFileObject.write
function call, you need to call someFileObject.flush
to insure that.
Upvotes: 1