HowTo: Uniquely Identify Raspberry Pi

While building a stack of Raspberry Pi servers in the house, it is necessary to uniquely identify the device. This might be for different purposes, like keeping track of the processing records, ensuring all the devices connected are working properly, or for load balancing purposes while processing huge files through multiple Raspberry Pi devices. A few applications for Raspberry Pi require a unique serial number for the licensing process, the best way to find the serial number is by following the BASH command and copying the 16-digit serial number.

cat /proc/cpuinfo

If you just want the serial number with any data you can also try the following:

cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2

If you are looking for a python code to do the same, it’s as follows:

def getserial():
    # Extract serial from cpuinfo file
    cpuserial = "0000000000000000"
    try:
        f = open('/proc/cpuinfo','r')
        for line in f:
            if line[0:6]=='Serial':
                cpuserial = line[10:26]
        f.close()
    except:
        cpuserial = "ERROR000000000"

    return cpuserial

The above Python code is the courtesy of Raspberry Spy. If you need a code to do the same in any different language, please let us know.

This code works on all ARM-based CPU devices and can be used to identify the CPU.

Leave a Comment