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 | 82380 |
41 | 윈도우 cmd에서 저장된 WIFI Profile의 비번 확인 | 꿈돌이 | 2019.07.03 | 3022 |
40 | mysql update _priv='Y' root 복구용 | 꿈돌이 | 2019.06.25 | 456 |
39 | 리눅스 sh에서 실행파일 삭제 | 꿈돌이 | 2019.06.10 | 540 |
38 |
공중파 케이블 vod
![]() | 꿈돌이 | 2019.05.26 | 9911 |
37 | 윈도우10 앱 및 기능 에서 삭제 안되는 프로그램을 목록에서 강제로 제거하기 | 꿈돌이 | 2019.05.02 | 13065 |
36 | mysql_error() equivalent is mssql_get_last_message() | 꿈돌이 | 2019.03.11 | 422 |
35 | certbot 수동 갱신 | 꿈돌이 | 2019.01.27 | 269 |
34 | GnuWin32 패키지 목록 페이지 | 꿈돌이 | 2018.12.14 | 2737 |
33 | 윈도우 10 260자 초과하는 파일경로 허용 | 꿈돌이 | 2018.11.03 | 2437 |
32 | 라즈베리파이 USB메모리 자동 마운트 | 꿈돌이 | 2018.10.30 | 756 |
31 | 윈도우 cmd에서 랜카드 dhcp on/off | 꿈돌이 | 2018.09.29 | 548 |
30 | 리눅스에서 php -r | 꿈돌이 | 2018.07.25 | 1201 |
29 | 우분투 USB 리셋 - MS 무선마우스 휠 문제 | 꿈돌이 | 2018.06.18 | 318 |
28 | 우분투 키보드 입력 속도 조정 | 꿈돌이 | 2018.06.18 | 70117 |
27 |
디버그모드에서 안드로이드 instant run
![]() | 꿈돌이 | 2018.04.20 | 312 |
26 |
라즈베리파이 메모
![]() | 꿈돌이 | 2018.02.13 | 465 |
25 | 라즈베리파이 전용 7인치 터치LCD 제어 | 꿈돌이 | 2018.01.30 | 2177 |
24 | 안드로이드 스마트폰으로 웹서버 만들기 | 꿈돌이 | 2018.01.04 | 1278 |
23 |
LZ4 압축하기, 해제하기 간단 예제
![]() | 꿈돌이 | 2017.04.18 | 25456 |
22 | golang Powershell에서 현재 디렉터리를 gopath로 지정 | 꿈돌이 | 2017.04.03 | 420 |