【Ruby简单脚本01】查看wifi密码

脚本

ruby 复制代码
# 使用io库  
def get_cmd_result(cmd)  
  IO.popen(cmd,:external_encoding=>'GBK').read.encode("utf-8")  
end  

def list_wifi  
  wifi_pwds = Hash.new  

  # 获取所有wifi文件  
  o1 = get_cmd_result("netsh wlan show profiles")  
  # 获取所有匹配结果  
  wifi_names = o1.scan(/所有用户配置文件\s*:\s*(.*?)\n/m)  
  unless wifi_names.empty?  
    wifi_names.each do |wifi_name|  
      o2 = get_cmd_result("netsh wlan show profile name=\"#{wifi_name[0]}\" key=clear")  
      wifi_pwd = o2.scan(/关键内容\s*:\s*(.*)\n/)  
      wifi_pwds.update({wifi_name[0] => wifi_pwd[0]})  
    end  
  end  wifi_pwds  
end  

puts list_wifi

输出结果

{"TP-LINK_2301"=>["1234567"], "CU_trtsds"=>["123456"], "Mi 10S"=>["12345678"]}

本文由【产品经理不是经理】gzh 同步发布,欢迎关注

相关推荐
好奇的菜鸟3 小时前
在 Postman 中高效生成随机环境变量的完整指南
测试工具·lua·postman
旷世奇才李先生8 天前
Lua 安装使用教程
开发语言·lua
Accpdaiyekun8 天前
C# 操作mongodb 多次查询快还是使用管道查询速度快
mongodb·c#·lua
快下雨了L8 天前
Lua现学现卖
开发语言·lua
WIN赢18 天前
PostMan使用
测试工具·lua·postman
多多*18 天前
计算机网络期末 网络基础概述
运维·服务器·网络·数据库·计算机网络·oracle·lua
18 天前
Lua复习之何为闭包
开发语言·unity·游戏引擎·lua·交互
码上库利南18 天前
详解Redis的LUA脚本、管道 (Pipelining)、事务事务 (Transactions)
数据库·redis·lua
RPGMZ18 天前
RPGMZ 游戏引擎如何与lua进行互相调用 初探
开发语言·javascript·游戏引擎·lua·rpgmz
Hello.Reader20 天前
Lua 事务双写、RedisGears 异步双写、零停机索引迁移与容量预估
开发语言·lua