0

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.

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by daviddoria
0

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

0

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.

0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.