Hi;

in Ubuntu and C++, i need the code to obtain and show for screen myself MAC.

Can you help me?.

This is part of a big program and it's the only thing which i have problems


I can use:

#include <algorithm>

#include <cassert>

#include <iostream>

#include <sstream>

#include <vector>

#include <netdb.h>

#include "linklayer.h"


Thanks in advance.

You want to get your MAC address in c++?

Surely there are better solutions, but here is an easy one:

Use the system() function to run "ifconfig > file.txt". Then load this file using ifstream and parse it to get the string after HWaddr. This is your mac address.

Dave

Well, this solution is not good for me because i have to find and show my mac for screen of terminal in Linux so ifconfig>file.txt does not work.

Any other idea?.


Many thanks Dave.

Like I said, writing to the file is the first step. The second step is then reading the file and parsing it so you can get the MAC address as a string. Then you can do whatever you want with it. Am I missing a requirement?