Created
February 4, 2023 17:10
-
-
Save R3DHULK/46cc9ed6c54fee14a523b25fc01155cc to your computer and use it in GitHub Desktop.
Mac Changer In CPP
This file contains 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 <iostream> | |
#include <cstring> | |
#include <unistd.h> | |
#include <sys/ioctl.h> | |
#include <net/if.h> | |
#include <arpa/inet.h> | |
#include <sys/socket.h> | |
#include <linux/if_ether.h> | |
using namespace std; | |
int main(int argc, char* argv[]) { | |
int sock; | |
struct ifreq ifr; | |
char* iface = argv[1]; | |
char* new_mac = argv[2]; | |
sock = socket(AF_INET, SOCK_STREAM, 0); | |
if (sock == -1) { | |
cout << "Could not create socket." << endl; | |
return -1; | |
} | |
strncpy(ifr.ifr_name, iface, IFNAMSIZ-1); | |
int res = ioctl(sock, SIOCGIFHWADDR, &ifr); | |
if (res == -1) { | |
cout << "Could not retrieve MAC address." << endl; | |
return -1; | |
} | |
int success = 0; | |
success = ioctl(sock, SIOCSIFHWADDR, &ifr); | |
if (success == -1) { | |
cout << "Could not change MAC address." << endl; | |
return -1; | |
} else { | |
cout << "MAC address changed successfully." << endl; | |
} | |
close(sock); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment