Thread: CPU Serial number in C with GCC

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    7

    Question CPU Serial number in C with GCC

    I need to find a unique identifier with any PC.
    The only sure way seems to be reading CPU serial number.

    How do I do that in vanilla C?

    My sole experience is with C, not C++.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    You'll probably have to do inline assembly. Look at the documentation for your compiler on how exactly to do that. There is no way in pure standard C to do it.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by fopetesl View Post
    I need to find a unique identifier with any PC.
    In general this is a difficult task. It requires reading multiple pieces of information and being able to deal with "reasonable" hardware changes. If it's important to you then you should purchase a commercial solution.

    The only sure way seems to be reading CPU serial number.
    Nope!

    How do I do that in vanilla C?
    Impossible.

  4. #4
    Registered User
    Join Date
    Jan 2017
    Posts
    7
    OK, thanks for the responses.

    Certainly it CAN be done since we purchased a commercial solution some years ago for a different software project.
    It isn't what we need now so I thought to write my own code to do it.

  5. #5
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by fopetesl View Post
    Certainly it CAN be done
    I never said it couldn't. But it CANNOT be done in "vanilla C", if by "vanilla" you mean standard C, and what else could that possibly mean? If you're allowed to use any library and inline assembly, etc, then you can do absolutely anything in C.

  6. #6
    Registered User
    Join Date
    Jan 2017
    Posts
    7
    Sorry. I took your "impossible" too generally.

    I have coded Assembler but that was in MSDOS days so I'd struggle to find the correct calls, today.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you're just looking for a unique identifier...
    uuidgen - Google Search
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jan 2017
    Posts
    7
    Quote Originally Posted by Salem View Post
    If you're just looking for a unique identifier...
    uuidgen - Google Search
    I had a look at uuidgen. Managed to download a Windows copy with PUP embedded.
    However it doesn't do what I need.
    It generates a UUID but it's not repeatable for one computer, i.e. every time it is asked to generate a UUID it comes up with a different one every time.
    So not usable for software protection.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    assembly - CPUID implementations in C++ - Stack Overflow

    But if you're serious about software protection, then consider an off the shelf package. Be wary of spending large amounts of time on s/w protection (in an inferior way) that could be better spent making your actual s/w functionality better.

    A machine fingerprint should perhaps consist of (motherboard + cpu + gpu + ram + harddisk). You can change any two and still call it the same machine.

    At the moment, you're suggesting if I replace just the CPU in the machine, then your licensing will break.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    The CPUID is not at all unique to the individual CPU, however. It just gives information about the CPU. So as Salem said, you need to combine information and allow a couple pieces to change. That's what a commercial package will do.

    If you just want something quick-and-dirty, people often try using the MAC address, although this is easily spoofed and can also obviously change.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to get serial number of HD?
    By tjc in forum C Programming
    Replies: 1
    Last Post: 11-11-2008, 12:18 AM
  2. HD Serial number
    By wallace.oliveir in forum C Programming
    Replies: 16
    Last Post: 07-07-2005, 05:37 AM
  3. HD Serial number
    By groorj in forum C Programming
    Replies: 2
    Last Post: 05-12-2005, 12:12 AM
  4. Serial Number of the Motherboard!
    By param in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-04-2003, 08:16 PM
  5. HELP - Reading CPU Serial Number
    By Rigoberto Croes in forum C++ Programming
    Replies: 2
    Last Post: 03-22-2002, 06:15 AM

Tags for this Thread