Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:22:31+00:00 2026-06-05T07:22:31+00:00

I was having a problem to get the mac address of a machine, which

  • 0

I was having a problem to get the mac address of a machine, which was solved in this question using the follow code:

Process p = Runtime.getRuntime().exec("getmac /fo csv /nh"); 
java.io.BufferedReader in = new java.io.BufferedReader(new  java.io.InputStreamReader(p.getInputStream())); 
String line; 
line = in.readLine();         
String[] result = line.split(","); 

System.out.println(result[0].replace('"', ' ').trim()); 

However, I would like to know why this code is not working. Every time it reads the MAC address it returns a different value. First I thought it was because getHash, maybe using a timestamp I dont know… But even removing it the result changes.

Code

    public static byte[] getMacAddress() {
        try {
            Enumeration<NetworkInterface> nwInterface = NetworkInterface.getNetworkInterfaces();
            while (nwInterface.hasMoreElements()) {
                NetworkInterface nis = nwInterface.nextElement();
                if (nis != null) {
                    byte[] mac = nis.getHardwareAddress();
                    if (mac != null) {
                        /*
                         * Extract each array of mac address and generate a
                         * hashCode for it
                         */
                        return mac;//.hashCode();
                    } else {
                        Logger.getLogger(Utils.class.getName()).log(Level.WARNING, "Address doesn't exist or is not accessible");
                    }
                } else {
                    Logger.getLogger(Utils.class.getName()).log(Level.WARNING, "Network Interface for the specified address is not found.");
                }
                return null;
            }
        } catch (SocketException ex) {
            Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}

Output example (i’m printing directly from byte array, but its enough to see that different i think)

[B@91cee
[B@95c083
[B@99681b
[B@a61164
[B@af8358
[B@b61fd1
[B@bb7465
[B@bfc8e0
[B@c2ff5
[B@c8f6f8
[B@d251a3
[B@d6c16c
[B@e2dae9
[B@ef5502
[B@f7f540
[B@f99ff5
[B@fec107

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:22:32+00:00Added an answer on June 5, 2026 at 7:22 am

    B@91cee actually is the result toString() method of the byte[] arrays.

    I would suggest you print the value using new String(mac) instead.

    byte[].toString() is implemented as:

    public String toString() {
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }
    

    Since default Object.hashCode() is implemented as address in memory, thus it is not consistent as you are creating new Object each time.

    Edit:

    Since the returned byte is in hex, so you should convert it into decimal String. The code can see from here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problem to get a numerical value for this expression where I
I'm having a strange problem with ZeroMQ, in which some messages get stuck, and
Having a really aggravating problem using Managed Metadata in SP2010 where I can get
I'm having a problem understanding how to find a contact in the Mac Address
Having big problems trying to get my php script to send email. Using this
I am only having this problem when running my program on a Mac; linux
I'm having problem with Rails plugin attachment_fu . On every upload, I get validation
I'm having a problem that a statusbar get displayed over the content of the
I am having a problem with my Windows Phone application. When I get the
I'm having a problem with my site http://artygirl.co.uk/pixie/about/ I can't seem to get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.