Get IP address, mac address of all interface
C/C++ Way Here is a short example of how to get the ip address, mac address of all network interface in linux from a c++ program. This code is available for all Linux distributions even though I tested on the Ubuntu 18.04. #include <stdio.h> #include <stdlib.h> #include <iostream> #include <unistd.h> #include <string.h> #include <string> #include <sys/types.h> #include <ifaddrs.h> #include <linux/if_packet.h> #include <net/ethernet.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <net/if.h> #include <sys/ioctl.h> using namespace std; unsigned char * getMACAddress ( const char * pinterface) { static unsigned char mac[ 8 ]; int sock = socket(PF_INET, SOCK_DGRAM, 0 ); struct ifreq req; int i = 0 ; memset( & req, 0 , sizeof (req)); strncpy(req.ifr_name, pinterface, IF_NAMESIZE - 1 );...