-
Notifications
You must be signed in to change notification settings - Fork 4
/
raspidata.py
48 lines (38 loc) · 1.07 KB
/
raspidata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
""" A Raspberry Pi class.
To access some of the most useful hardware information
"""
#class RaspiData():
# Get Raspberry Serial Number
# You can do it in bash:
# cat /proc/cpuinfo | perl -n -e '/^Serial[ ]*: ([0-9a-f]{16})$/ && print "$1\n"'
# Or with perl:
# cat cpuinfo | perl -n -e '/^Serial[ ]*: ([0-9a-f]{16})$/ && print "$1\n"'
#
#
# def __init__(self):
# pass
from uuid import getnode as get_mac
# @staticmethod
# def get_serial(self):
def get_serial():
"""Extract serial from cpuinfo file"""
cpu_serial= "0000000000000000"
try:
f = open('/proc/cpuinfo','r')
for line in f:
if line[0:6]=='Serial':
cpu_serial = line[10:26]
f.close()
except:
cpu_serial = "ERROR000000000"
return cpu_serial
def mac_address():
"""Extract rth0 MAC address"""
# mac = '00:00:00:00:00:00'
# mac = '00:00:00:00:00:00'
try:
t = get_mac()
except:
t = "000000000000"
mac = ':'.join(("%012X" % t)[i:i+2] for i in range(0, 12, 2))
return mac