

The benefit of using this method is that you can now use the exact method to execute many more commands. Then print the whole data that is inside the file. Now we will open the file using ifstream. Once the system command is executed the output will be saved inside the file. It is the name of the file which will contain the output of the command. The filename can be anything a user wants. It is already saved in cmd string inside the main function. In the above code, we will use the system() function to execute the command.

Secondly, we will open the file and print the data in it. This function allows us to execute any command from a c++ program.įirstly, we will execute the “getmac” command through the program using system function. We are going to use “ system()” function. How to get MAC address of a device using C++

Process aProc = Runtime.getRuntime().exec("ipconfig /all") to filter out bluetooth devices): public String obtainMacAddress() Here I also make sure that this address has an associated IP (e.g. Butterchicken's solution is ok, but will only work on english versions of Windows.Ī somewhat better (language independent) solution would be to match the pattern for MAC addresses.
