메뉴 건너뛰기

enjoyTools.net

System unique id 추출

2016.06.23 00:39

꿈돌이 조회 수:799

Ancient C codes. :-p

 

Windows

/* Get cpu-id */
 
#include <stdio.h>
#include <intrin.h>
 
int main() {
 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]);
 }
 
 return 0;
}

 

/* Get MAC Address */
 
#pragma comment(lib, "Iphlpapi.lib")
 
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
 
int main() {
 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");
 }
 //}
 
 free(info);
 
 return 0;
}

 

 

Linux

/* Get cpu-id */
 
#include <stdio.h>
 
int main() {
  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
 
    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);
 
    ifreq* it = ifc.ifc_req;
    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 , it->ifr_name , IFNAMSIZ-1);

    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

 

번호 제목 글쓴이 날짜 조회 수
공지 툴 북마크 꿈돌이 2021.02.11 80864
75 C# GDI 좌표 꿈돌이 2015.08.31 135485
74 우분투 키보드 입력 속도 조정 꿈돌이 2018.06.18 68793
73 원격데스크톱 연결 - 로컬계정 사용 꿈돌이 2015.05.25 30887
72 LZ4 압축하기, 해제하기 간단 예제 file 꿈돌이 2017.04.18 25060
71 윈도우10 앱 및 기능 에서 삭제 안되는 프로그램을 목록에서 강제로 제거하기 꿈돌이 2019.05.02 12539
70 공중파 케이블 vod file 꿈돌이 2019.05.26 9374
69 내꺼 스타트, 엔드 G코드 꿈돌이 2020.05.05 8919
68 GTK3/Cairo 버튼 클릭시 이벤트 처리 꿈돌이 2015.03.16 8678
67 SKR mini E3 교체한 Ender 3에 Klipper OctoPrint 설치, 설정 및 적용 외 꿈돌이 2019.11.16 7520
66 MS-Windows에서 php_screw 사용하기 꿈돌이 2015.11.17 5625
65 dlib dnn_metric_learning_ex.cpp 꿈돌이 2020.02.07 4880
64 윈도우10 배율 (dpi) 변경 스크립트 file 꿈돌이 2019.08.27 3934
63 node.js 전역 모듈 제거 꿈돌이 2017.03.16 3544
62 윈도우 cmd에서 저장된 WIFI Profile의 비번 확인 꿈돌이 2019.07.03 2948
61 GnuWin32 패키지 목록 페이지 꿈돌이 2018.12.14 2650
60 윈도우8.1 core 버전에서 원격데스크톱 사용 file 꿈돌이 2015.03.13 2462
59 윈도우 10 260자 초과하는 파일경로 허용 꿈돌이 2018.11.03 2357
58 라즈베리파이 전용 7인치 터치LCD 제어 꿈돌이 2018.01.30 2049
57 wsl 관련된 개체 종류에 대한 해당 작업은 지원되지 않습니다 file 꿈돌이 2021.11.01 1980