Python implements a script to remotely shut down the computer using 163 mailbox, python163
After learning Python for a week, I wrote the code very rough, just to use the 163 mailbox Remote Computer shutdown function. Send the Code directly. To run the command, you must install some modules first. Check the import Statement.
I wrote it in early October. I didn't write much about python after I wrote it. I forgot a lot about it.
- I originally wanted to simulate logon from mail.163.com, but the button for submitting this webpage is a bit complicated. It may take a few hours.
- I went around and logged in from http://reg.163.com/logins.jsp. Login to this page will be blocked, or you will not be able to get to the mailbox. But the logon is successful. We can get a logon authentication.
- Then access the http://entry.mail.163.com, so login mailbox succeeded, but because after the mailbox, the page is too complex. It is still difficult to get the mail information.
- Obtain the sid from step 3, generate a URL, and access the XML document page of the email directly from this URL.
- Then it's easy. Capture the page, parse the mail content, and execute the command according to the Mail content. In fact, you can not only shut down your computer, but also remotely write a batch processing script in windows. You can also modify the code in linux.
Halla. py
Import requestsimport mechanic icalsoupimport bs4import reimport TESTimport timeimport argparsefrom datetime import datetimeimport lxmlparser = argparse. argumentParser (description = 'login to GitHub. ') parser. add_argument ("username") parser. add_argument ("password") args = parser. parse_args () n = 0 startime = datetime. strptime (datetime. now (). strftime ('% Y-% m-% d % H: % M: % s'),' % Y-% m-% d % H: % M: % s') while True: # Open "browse "Browser = machicalsoup. Browser () # The first page url =" http://reg.163.com/logins.jsp? Type = 1 & product = mail163 & url = http://entry.mail.163.com/coremail/fcg/ntesdoor2? Lightweight % 3D1% 26 verifycookie % 3D1% 26 language % 3D-1% 26 style % 3D1 "# Open the Netease logon page login_page = browser. get (url) # enter the account password and submit the form login_form = login_page.soup.select ("# fLogin") [0] login_form.select ("# username ") [0] ['value'] = args. username login_form.select ("# password") [0] ['value'] = args. password page2 = browser. submit (login_form, login_page.url) # obtain page2 content page2_soup = bs4.BeautifulSoup (page2.content) # Use page2. Get_dict () page3 = browser. get ('HTTP: // entry.mail.163.com/coremail/fcg/ntesdoor2') # obtain the sid in the url of page3 and give the XMLurl sid = re. findall (R '(? <= ).*(? = &) ', Page3.url) XMLurl = 'HTTP: // mail.163.com/js6/s? Sid = '+ sid [0] +' & func = mbox: listMessages & packages = 1 & TopTabReaderShow = 1 & TopTabLofterShow = 1 & Records = 1 & LeftNavfolder1Click = 1 & mbox_folder_enter = 1' # Open the XMLurl page and get the mail page4 = browser. post (XMLurl) with open (r'q. xml ', 'w', encoding = 'utf-8') as q: q. write (page4.text) TEST. PPP (r'q. xml', startime ). ppp () n + = 1 print ("cyclic execution No." + str (n) + 'sub') time. sleep (30)
TEST. py
import lxml.etreeimport osfrom datetime import datetimeclass PPP(): def __init__(self, src, startime): self.src = src self.startime = startime def ppp(self): parser = lxml.etree.XMLParser(recover=True) tree = lxml.etree.parse(self.src, parser) root = tree.getroot() array = root.find('array') for objects in array: FLAG = False for items in objects: if items.get('name') == 'subject': if items.text == '999': FLAG = True if items.get('name') == 'sentDate': raw_sentData = items.text sentData = datetime.strptime(raw_sentData,'%Y-%m-%d %H:%M:%S') if self.startime<sentData and FLAG==True: print('shutdown -s -t 60')
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.