/** * Gets the SSID of the currently associated WiFi access point if there is one. Otherwise, * returns empty string. */ @CalledByNative public static String getWifiSSID(Context context) { if (context == null) { return ""; } final Intent intent = context.registerReceiver( null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); if (intent != null) { final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); if (wifiInfo != null) { final String ssid = wifiInfo.getSSID(); if (ssid != null) { return ssid; } } } return ""; }
public String b4() { WifiInfo connectionInfo = this.hV.getConnectionInfo(); if (connectionInfo == null) { return null; } try { String bssid = connectionInfo.getBSSID(); if (bssid != null) { bssid = bssid.replace(":", ""); if ("000000000000".equals(bssid) || "".equals(bssid)) { return null; } } bssid = null; return bssid; } catch (Exception e) { return null; } }
/** * <p>need permission {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p> */ @SuppressLint("HardwareIds") private static String getMacAddressByWifiInfo(Context context) { try { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifi != null) { WifiInfo info = wifi.getConnectionInfo(); if (info != null) return info.getMacAddress(); } } catch (Exception e) { e.printStackTrace(); } return "02:00:00:00:00:00"; }
@Override public void onReceive(Context context, Intent intent) { WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); String name = wifiInfo.getSSID(); for(ScanResult result: wifiMgr.getScanResults()){ WifiApListProvider.this.output(new WifiAp(result, name.equals(result.SSID))); } WifiApListProvider.this.finish(); }
public static String getDeviceId(Context context) { String deviceID = null; // MAC WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info; if (wifi != null && (info = wifi.getConnectionInfo()) != null) { deviceID = info.getMacAddress(); } // TelephonyManager.DeviceId String tmSerial = "null"; if (TextUtils.isEmpty(deviceID)) { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null) { tmSerial = "" + tm.getSimSerialNumber(); deviceID = tm.getDeviceId(); } } // Settings.Secure.ANDROID_ID + TelephonyManager.SimSerialNumber if (TextUtils.isEmpty(deviceID)) { deviceID = generateId(context, tmSerial); } return deviceID; }
private InetAddress getDeviceIpAddress(WifiManager wifi) { InetAddress result = null; try { // default to Android localhost result = InetAddress.getByName("10.0.0.2"); // figure out our wifi address, otherwise bail WifiInfo wifiinfo = wifi.getConnectionInfo(); int intaddr = wifiinfo.getIpAddress(); byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) }; result = InetAddress.getByAddress(byteaddr); } catch (UnknownHostException e) { e.printStackTrace(); Log.e(TAG, "getDeviceIpAddress Error: " + e.getMessage()); } return result; }
public static boolean isHotelNewWork(Context context) { WifiManager wifiManger = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); //获取wifi服务 WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); //判断wifi是否开启 if (!wifiManager.isWifiEnabled()) { return false; }else { WifiInfo wifiInfo = wifiManger.getConnectionInfo(); String localIp = intToIp(wifiInfo.getIpAddress()); if("192.168.43".equals(localIp)) return true; else return false; } }
public static String a() { try { Context context = Global.getContext(); if (context == null) { return ""; } WifiManager wifiManager = (WifiManager) context.getSystemService("wifi"); if (wifiManager == null) { return ""; } WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo == null) { return ""; } return connectionInfo.getMacAddress(); } catch (Throwable e) { f.b("MobileInfoUtil", "getLocalMacAddress>>>", e); return ""; } }
/** * This method retrieves the SSID for the currently connected network * * @param callbackContext A Cordova callback context * @return true if SSID found, false if not. */ private boolean getConnectedSSID(CallbackContext callbackContext){ if(!wifiManager.isWifiEnabled()){ callbackContext.error("Wifi is disabled"); return false; } WifiInfo info = wifiManager.getConnectionInfo(); if(info == null){ callbackContext.error("Unable to read wifi info"); return false; } String ssid = info.getSSID(); if(ssid.isEmpty()) { ssid = info.getBSSID(); } if(ssid.isEmpty()){ callbackContext.error("SSID is empty"); return false; } callbackContext.success(ssid); return true; }
public static String getCurrentSSID(Context context) throws Exception { try { WifiManager wifiManager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo.getSSID(); } catch (Exception e) { throw new Exception("目前WIFI連線名稱讀取時發生錯誤"); } }
public int GetWifiDBM() { int dbm = 0; WifiManager wifiManager = (WifiManager) _context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiManager == null) { return -1; } if (wifiManager.isWifiEnabled()) { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { dbm = wifiInfo.getRssi(); } } return dbm; }
private void checkWifiConnection(){ try{ if(isWifiConnected()){ Toast.makeText(getApplicationContext(), "Wifi is connected", Toast.LENGTH_SHORT).show(); WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); final String activeWifiName = wifiInfo.getSSID().replace("\"",""); btnActiveWifi.setText(activeWifiName); //debug btnActiveWifi.setText(btnActiveWifi.getText()+"\n("+AutoLoginService.getState(getBaseContext())+")"); } else{ btnActiveWifi.setText("Wifi Not Connected !!"); //debug btnActiveWifi.setText(btnActiveWifi.getText()+"\n("+AutoLoginService.getState(getBaseContext())+")"); }} catch (Exception ex){ txtView.setText(ex.getMessage()); //Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG); } }
@Override protected void onBindHooks() { super.onBindHooks(); addHook(new StaticHook("getConnectionInfo") { @Override public Object call(Object who, Method method, Object... args) throws Throwable { WifiInfo info = (WifiInfo) super.call(who, method, args); if (info != null) { if (info.getMacAddress() != null) { PhoneInfoDelegate phoneInfoDelegate = VirtualCore.get().getPhoneInfoDelegate(); if (phoneInfoDelegate != null) { try { Reflect.on(info).set("mMacAddress", phoneInfoDelegate.getMacAddress((String) Reflect.on(info).get("mMacAddress"))); } catch (Exception ignored) { } } } } return info; } }); }
@SuppressLint("HardwareIds") public String getMacAddress() throws Exception { WifiManager wifiMan = (WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiMan == null) { return null; } WifiInfo wifiInf = wifiMan.getConnectionInfo(); if (wifiInf == null) { return getMacByFile(); } String mac = wifiInf.getMacAddress(); if (FAKE_MAC_ADDRESS.equals(mac)) { mac = null; } if (mac == null) { mac = getMacByInterface(); if (mac == null) { mac = getMacByFile(); } } return mac; }
public static boolean wifiConnection(Context context, String wifiSSID, String password) { WifiManager wifi = (WifiManager) context.getSystemService("wifi"); String strQuotationSSID = "\"" + wifiSSID + "\""; WifiInfo wifiInfo = wifi.getConnectionInfo(); if (wifiInfo != null && (wifiSSID.equals(wifiInfo.getSSID()) || strQuotationSSID.equals(wifiInfo.getSSID()))) { return true; } List<ScanResult> scanResults = wifi.getScanResults(); if (scanResults == null || scanResults.size() == 0) { return false; } for (int nAllIndex = scanResults.size() - 1; nAllIndex >= 0; nAllIndex--) { String strScanSSID = ((ScanResult) scanResults.get(nAllIndex)).SSID; if (wifiSSID.equals(strScanSSID) || strQuotationSSID.equals(strScanSSID)) { WifiConfiguration config = new WifiConfiguration(); config.SSID = strQuotationSSID; config.preSharedKey = "\"" + password + "\""; config.status = 2; return wifi.enableNetwork(wifi.addNetwork(config), false); } } return false; }
public static String getLocalMacAddress(Context context) { WifiManager wifi = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); String mac = ""; if (wifi != null) { WifiInfo info = wifi.getConnectionInfo(); if (info != null) { mac = info.getMacAddress(); } } return mac == null ? "" : mac; }
public ApConnector(Context ctx) { this.appContext = ctx.getApplicationContext(); this.client = new DecoratedClient(); this.wifiFacade = WifiFacade.get(appContext); this.softAPConfigRemover = new SoftAPConfigRemover(appContext); this.mainThreadHandler = new Handler(Looper.getMainLooper()); this.wifiLogger = SimpleReceiver.newReceiver( appContext, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION), (context, intent) -> { log.d("Received " + WifiManager.NETWORK_STATE_CHANGED_ACTION); log.d("EXTRA_NETWORK_INFO: " + intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO)); // this will only be present if the new state is CONNECTED WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); log.d("WIFI_INFO: " + wifiInfo); }); }
public String getSSID() { WifiManager wifiManager = (WifiManager) getSystemService("wifi"); if (wifiManager == null) { return null; } WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo == null) { return null; } String ssid = connectionInfo.getSSID(); if (ssid == null) { ssid = null; } return ssid; }
public static String getConnectedSSID(Context context) { if (context == null) return null; String networkName = null; int networkState = getConnectionStatus(context); Log.i(TAG, "Network State:" + networkState); if (networkState == NetworkUtil.WIFI) { //no wifi connection and alert dialog allowed //i-why no wifi connection? WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { networkName = wifiInfo.getSSID().replaceAll("\"", ""); } } } if (networkName == null || networkName.equals("<unknown ssid>") || networkName.equals("0x") || networkName.equals("")) { networkName = null; } return networkName; }
private String getWifiSsid() { String ssid = null; final WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null) { final Object wifiSsid = XposedHelpers.callMethod(connectionInfo, "getWifiSsid"); if (wifiSsid != null) { ssid = wifiSsid.toString(); } } } if (TextUtils.isEmpty(ssid)) { int resId = mContext.getResources().getIdentifier( "quick_settings_wifi_not_connected", "string", PieController.PACKAGE_NAME); // TODO: translate ssid = resId == 0 ? "Not connected" : mContext.getString(resId); } return ssid; }
public static int getIpAddress() { int ipAddress = 0; WifiManager wifiManager = (WifiManager) FDApplication .getInstance().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo == null || wifiInfo.equals("")) { return ipAddress; } else { ipAddress = wifiInfo.getIpAddress(); } return ipAddress; }
/** * 获取当前连接wifi的名称 * * @return */ public static String getConnectWifiSsid(Context context) { if (isWifiConnected(context)) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo.getSSID(); } return null; }
/** * 获取当前连接wifi的名称 * * @return */ public static String getConnectWifiIp(Context context) { if (isWifiConnected(context)) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); if (ipAddress == 0) { return null; } return ((ipAddress & 0xff) + "." + (ipAddress >> 8 & 0xff) + "." + (ipAddress >> 16 & 0xff) + "." + (ipAddress >> 24 & 0xff)); } return null; }
/** * 获取 MAC 地址 * 须配置android.permission.ACCESS_WIFI_STATE权限 */ public static String getMacAddress(Context context) { //wifi mac地址 WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); String mac = info.getMacAddress(); LogUtils.i(TAG, " MAC:" + mac); return mac; }
/** * 获取设备MAC地址 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p> * * @return MAC地址 */ @SuppressLint("HardwareIds") private static String getMacAddressByWifiInfo() { try { @SuppressLint("WifiManagerLeak") WifiManager wifi = (WifiManager) Utils.getApp().getSystemService(Context.WIFI_SERVICE); if (wifi != null) { WifiInfo info = wifi.getConnectionInfo(); if (info != null) return info.getMacAddress(); } } catch (Exception e) { e.printStackTrace(); } return "02:00:00:00:00:00"; }
public static String D(Context context) { try { WifiInfo B = B(context); if (B != null) { return B.getSSID(); } } catch (Object th) { f.e(th); } return null; }
/** * get MAC address */ public static String getMacAddress(Context context) { String macAddress = ""; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { if (!intf.getName().equalsIgnoreCase("wlan0")) { continue; } byte[] mac = intf.getHardwareAddress(); if (mac == null) { break; } StringBuilder buf = new StringBuilder(); for (int idx = 0; idx < mac.length; idx++) { buf.append(String.format("%02X", mac[idx])); } macAddress = buf.toString(); break; } } catch (Exception ex) { } } else { WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); macAddress = info.getMacAddress().replaceAll(":", "").toUpperCase(); } // macAddress = "C81479F6A4EC"; Log.i(TAG, "MAC Address : " + macAddress); return macAddress; }
/** * Get IP * * @param context context * @return IP */ public static String getIp(Context context) { int networkType = getNetworkType(context); if (networkType == ConnectivityManager.TYPE_WIFI) { WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); return (ipAddress & 0xFF) + "." + ((ipAddress >> 8) & 0xFF) + "." + ((ipAddress >> 16) & 0xFF) + "." + (ipAddress >> 24 & 0xFF); } else { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress(); } } } } catch (SocketException e) { e.printStackTrace(); } return null; } }
private String getMacAddress(Context ctx){ WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if(null == wifiInfo || null == wifiInfo.getMacAddress()){ return ""; } return wifiInfo.getMacAddress().replaceAll(":", ""); }
/** * 获取设备mac地址 * * @param context * @return */ public String getMacAddress(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); String mac = info.getMacAddress(); return mac; }
public static String getIPAddress(Context context) { NetworkInfo info = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); if (info != null && info.isConnected()) { if (info.getType() == ConnectivityManager.TYPE_MOBILE) {//当前使用2G/3G/4G网络 try { //Enumeration<NetworkInterface> en=NetworkInterface.getNetworkInterfaces(); for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress(); } } } } catch (SocketException e) { e.printStackTrace(); } } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {//当前使用无线网络 WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());//得到IPV4地址 return ipAddress; } } else { //当前无网络连接,请在设置中打开网络 return ""; } return null; }
public static String getWifiName(Context context) { if(context == null) return null; WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiMgr.getConnectionInfo(); String wifiId = info != null ? info.getSSID() : null; if(!TextUtils.isEmpty(wifiId)) { wifiId = wifiId.replace("\"",""); } return wifiId; }
public String b0() { String str = null; try { WifiInfo connectionInfo = this.hV.getConnectionInfo(); if (connectionInfo != null) { str = connectionInfo.getMacAddress(); } } catch (Exception e) { } return str; }
public static String U(Context context) { try { WifiInfo T = T(context); if (T != null) { return T.getBSSID(); } } catch (Throwable th) { Log.e("MtaSDK", "encode error", th); } return null; }
public String getMac() { if (TextUtils.isEmpty(macAddress)) { try { WifiManager wifi = (WifiManager) mContext .getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); macAddress = info.getMacAddress(); } catch (Exception ex) { LogUtils.e(ex.toString()); } } return macAddress; }
private void updateWifiInfo() { WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); wifiSsid = wifiInfo.getSSID(); wifiBssid = wifiInfo.getBSSID(); }
/** * 获取 MAC 地址 * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> */ public static String getMacAddress(Context context) { //wifi mac地址 WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); String mac = info.getMacAddress(); JLog.i(" MAC:" + mac); return mac; }
@Override public void onReceive(Context context, Intent intent) { WifiManager wifiManager = (WifiManager) context .getSystemService(context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo.getBSSID() != null) { // wifi信号强度 int signalLevel = WifiManager.calculateSignalLevel( wifiInfo.getRssi(), 4); if (signalLevel == 0) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.wifi_1)); } else if (signalLevel == 1) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.wifi_2)); } else if (signalLevel == 2) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.wifi_3)); } else if (signalLevel == 3) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.networkstate_on)); } if (d) Toast.makeText(context, "wifi level" + signalLevel, Toast.LENGTH_SHORT).show(); } }