Python3 利用POP3與smtplib進行電腦遠端控制

來源:互聯網
上載者:User

標籤:一個   [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進行電腦遠端控制

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.