//根据需求修改网卡名称
//IpGetMac.cpp
#include <net/if.h>
#include <sys/ioctl.h>#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#define ETH_NAME "eth0" //如果要获取其他网卡的地址,将这个换为其他网卡名称,比如eth0
std::string get_ip();
void get_mac(char * mac_a);
int main()
{
//ip
std::string ip = get_ip();
printf("ip: %s: ", ip.c_str());
// mac address
char * this_mac = new char[6];
get_mac(this_mac);
printf("mac: %02x:%02x:%02x:%02x:%02x:%02x\n", this_mac[0]&0xff, this_mac[1]&0xff, this_mac[2]&0xff, this_mac[3]&0xff, this_mac[4]&0xff, this_mac[5]&0xff);
return 0;
}
std::string get_