Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getMacAddr() {
- try {
- List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
- for (NetworkInterface nif : all) {
- if (!nif.getName().equalsIgnoreCase("wlan0")) continue;
- byte[] macBytes = nif.getHardwareAddress();
- if (macBytes == null) {
- return "";
- }
- StringBuilder res1 = new StringBuilder();
- for (byte b : macBytes) {
- String hex = Integer.toHexString(b & 0xFF);
- if (hex.length() == 1)
- hex = "0".concat(hex);
- res1.append(hex.concat(":"));
- }
- if (res1.length() > 0) {
- res1.deleteCharAt(res1.length() - 1);
- }
- return res1.toString();
- }
- } catch (Exception ex) {
- }
- return "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement