#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void setMac(char * mac)
{
char cmd[64];
//network interface
char nwkInf[5]="eth0";
memset(cmd,0X00,64);
//command to link down network
sprintf((char *)cmd,(const char *)"ip link set %s down",nwkInf);
system((const char *)cmd);
usleep(500);
memset(cmd,0X00,64);
//command to set MAC address
sprintf((char *)cmd,(const char *)"ifconfig %s hw ether %s",nwkInf,mac);
system((const char *)cmd);
usleep(500);
memset(cmd,0X00,64);
//command to link up network
sprintf((char *)cmd,(const char *)"ip link set %s up",nwkInf);
system((const char *)cmd);
usleep(500);
}
int main()
{
//funcion call to set MAC address
setMac("67:45:C4:AC:2F:CA");
return 0;
}
Here,"67:45:C4:AC:2F:CA" is MAC address to be assigned.
Consider the program:
Here, "67:45:C4:AC:2F:CA" is MAC address to be assigned.
need an explanation for this answer? contact us directly to get an explanation for this answer