Created
April 22, 2021 22:46
-
-
Save karlek/e2578ffe68eb72f3ed3535c12e826065 to your computer and use it in GitHub Desktop.
Simple mac changer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <net/if.h> | |
#include <net/if_arp.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/ioctl.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
int main(int argc, char** argv) { | |
struct ifreq ifr; | |
int s; | |
char mac_char[] = "12:34:56:78:12:34"; | |
sscanf(mac_char, | |
"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", | |
&ifr.ifr_hwaddr.sa_data[0], | |
&ifr.ifr_hwaddr.sa_data[1], | |
&ifr.ifr_hwaddr.sa_data[2], | |
&ifr.ifr_hwaddr.sa_data[3], | |
&ifr.ifr_hwaddr.sa_data[4], | |
&ifr.ifr_hwaddr.sa_data[5]); | |
s = socket(AF_INET, SOCK_DGRAM, 0); | |
assert(s != -1); | |
strcpy(ifr.ifr_name, "eth0"); | |
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | |
assert(ioctl(s, SIOCSIFHWADDR, &ifr) != -1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment