System unique id 추출
2016.06.23 00:39
Ancient C codes. :-p
Windows
/* Get cpu-id */
#include <stdio.h>
#include <intrin.h>
#include <intrin.h>
int main() {
int b[4];
int b[4];
for (int a = 0; a < 5; a++) {
__cpuid(b, a);
printf("The code %i gives %i, %i, %i, %i\r\n", a, b[0], b[1], b[2], b[3]);
}
__cpuid(b, a);
printf("The code %i gives %i, %i, %i, %i\r\n", a, b[0], b[1], b[2], b[3]);
}
return 0;
}
}
/* Get MAC Address */
#pragma comment(lib, "Iphlpapi.lib")
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <iphlpapi.h>
#include <stdio.h>
int main() {
IP_ADAPTER_INFO *info = NULL, *pos;
DWORD size = 0;
IP_ADAPTER_INFO *info = NULL, *pos;
DWORD size = 0;
GetAdaptersInfo(info, &size);
info = (IP_ADAPTER_INFO *)malloc(size);
GetAdaptersInfo(info, &size);
//for (pos = info; pos != NULL; pos = pos->Next) {
pos = info;
if (info != NULL) {
printf("Mac : ");
printf("%2.2x", pos->Address[0]);
for (unsigned int i = 1; i < pos->AddressLength; i++)
printf(":%2.2x", pos->Address[i]);
printf("\r\n");
}
//}
pos = info;
if (info != NULL) {
printf("Mac : ");
printf("%2.2x", pos->Address[0]);
for (unsigned int i = 1; i < pos->AddressLength; i++)
printf(":%2.2x", pos->Address[i]);
printf("\r\n");
}
//}
free(info);
return 0;
}
}
Linux
/* Get cpu-id */
#include <stdio.h>
int main() {
int a, b;
int a, b;
for (a = 0; a < 5; a++) {
__asm__("cpuid"
:"=a"(b) // EAX into b (output)
:"0"(a) // a into EAX (input)
:"%ebx","%ecx","%edx"); // clobbered registers
__asm__("cpuid"
:"=a"(b) // EAX into b (output)
:"0"(a) // a into EAX (input)
:"%ebx","%ecx","%edx"); // clobbered registers
printf("The code %i gives %i\n", a, b);
}
}
return 0;
}
}
/* Get MAC Address */
#include <stdio.h> //printf
#include <string.h> //strncpy
#include <sys/ioctl.h>
#include <net/if.h> //ifreq
#include <unistd.h> //close
int main() {
int fd;
struct ifreq ifr;
char *iface = "eth0";
unsigned char *mac;
fd = socket(AF_INET, SOCK_DGRAM, 0);
#include <string.h> //strncpy
#include <sys/ioctl.h>
#include <net/if.h> //ifreq
#include <unistd.h> //close
int main() {
int fd;
struct ifreq ifr;
char *iface = "eth0";
unsigned char *mac;
fd = socket(AF_INET, SOCK_DGRAM, 0);
ifreq* it = ifc.ifc_req;
const ifreq* const end = it + (ifc.ifc_len / sizeof(ifreq));
const ifreq* const end = it + (ifc.ifc_len / sizeof(ifreq));
ifr.ifr_addr.sa_family = AF_INET;
//for ( ; it != end ; ++it) {
strncpy(ifr.ifr_name , iface , IFNAMSIZ-1);
strncpy(ifr.ifr_name , iface , IFNAMSIZ-1);
//strncpy(ifr.ifr_name , it->ifr_name , IFNAMSIZ-1);
ioctl(fd, SIOCGIFHWADDR, &ifr);
close(fd);
ioctl(fd, SIOCGIFHWADDR, &ifr);
close(fd);
mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
//display mac address
printf("Mac : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n" , mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
//}
return 0;
}
출처:
- https://en.wikipedia.org/wiki/CPUID
- http://stackoverflow.com/questions/2069855/getting-machines-mac-address-good-solution
- http://www.binarytides.com/c-program-to-get-mac-address-from-interface-name-on-linux/
- http://stackoverflow.com/questions/1779715/how-to-get-mac-address-of-your-machine-using-a-c-program
- http://stackoverflow.com/questions/1779715/how-to-get-mac-address-of-your-machine-using-a-c-program
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
공지 | 툴 북마크 | 꿈돌이 | 2021.02.11 | 81013 |
78 | 윈도우 터미널 색상, 글꼴 설정 | 꿈돌이 | 2024.04.24 | 2 |
77 | 윈도우 키보드 입력 속도 조정 | 꿈돌이 | 2024.04.21 | 2 |
76 | 윈도우에서 fstrim | 꿈돌이 | 2024.04.03 | 2 |
75 | wsl 지정 경로에 수동 설치 | 꿈돌이 | 2023.05.28 | 136 |
74 | windows 11 ssh-keygen.exe directory | 꿈돌이 | 2023.03.29 | 152 |
73 | GPU cloud | 꿈돌이 | 2023.03.26 | 49 |
72 | 윈도우 폴더명 파일명 소문자로 바꾸기 | 꿈돌이 | 2023.01.09 | 155 |
71 | scp 몰아서 보내기 | 꿈돌이 | 2022.07.21 | 80 |
70 | softether 연결 | 꿈돌이 | 2022.07.21 | 85 |
69 | 해상도 fps 다른 동영상 합치기 | 꿈돌이 | 2022.05.09 | 230 |
68 | 크롬 cmd switch | 꿈돌이 | 2022.05.07 | 76 |
67 | sql server 애슬론 암호건 상태에서 안 될 경우 | 꿈돌이 | 2021.12.18 | 128 |
66 | wsl 관련된 개체 종류에 대한 해당 작업은 지원되지 않습니다 | 꿈돌이 | 2021.11.01 | 1994 |
65 | 확인용 | 꿈돌이 | 2021.08.30 | 84 |
64 | MS SQL Server Express 설치 | 꿈돌이 | 2021.08.20 | 122 |
63 | Voron v0 클리퍼 설정 | 꿈돌이 | 2021.03.29 | 180 |
62 | QEMU 데비안 클라 구성 세트 | 꿈돌이 | 2021.03.25 | 114 |
61 | .jsbeautifyrc | 꿈돌이 | 2020.11.04 | 351 |
60 | 프리캐드 사용법 | 꿈돌이 | 2020.10.14 | 555 |