Obtaining device ID using smartmontools

Obtaining device ID using smartmontools

S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology; written as SMART) SMART is a system for monitoring and early detection of errors of storage media such as hard disks or SSDs.

NOTE:Run IDE as administrator and SMARTMONTOOLS should be installed in the system

import os class SMART: def __init__(self): self.deviceList=list() #to run a smartctl command def RunSmartCtl(self, strArgs): #get the command with strArgs as the argument cmdString = "smartctl " + strArgs #get command output and store each line in a list output = os.popen(cmdString).read() lines = str.splitlines(output) return lines #to obtain all device ids def GetDeviceIds(self): lines = self.RunSmartCtl("--scan") for line in lines: deviceId = str.split(line, " " ,1)[0] self.deviceList.append(deviceId) #function to display deviceID's def displayDeviceID(self): print("Device ID's are:") i=1 for id in self.deviceList: print(i,id) i=i+1 def main(): smart_features = SMART() smart_features.GetDeviceIds() smart_features.displayDeviceID() if __name__ == '__main__': main()