import os, subprocess, fileinput
command_1 = [„snmpget -Oqv -c public -v 2c {} iso.3.6.1.2.1.43.10.2.1.4.1.1″,”snmpget -Oqv -c public -v 2c {} iso.3.6.1.2.1.43.5.1.1.16.1″,”snmpget -Oqv -c public -v 2c {} iso.3.6.1.2.1.43.5.1.1.17.1”]
command_2 = [„snmpget -Oqv -c public -v 2c {} iso.3.6.1.2.1.43.10.2.1.4.1.1″,”snmpget -Oqv -c public -v 2c {} iso.3.6.1.2.1.1.5.0”]
printers_1 = [„172.4.2.51″,”172.4.2.53″,”172.4.2.101″,”172.4.2.102″,”172.4.2.103”]
printers_2 = [„172.4.2.52″,”172.4.2.104”]
serial_52 = „52”
serial_104 = „104”
f = open(„./ricoh_count.csv”,”w+”)
f.write(„IP ;LICZNIK ;MODEL ;SN\n”)
for host in printers_1:
f.write(host)
for command in command_1:
proc = subprocess.Popen(command.format(host),shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)
out=proc.communicate()
out=str(out)
f.write(” ; „+out)
f.write(„\n”)
for host in printers_2:
f.write(host)
for command in command_2:
proc = subprocess.Popen(command.format(host),shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)
out=proc.communicate()
out=str(out)
f.write(” ; „+out)
if(host==”172.4.2.52″):
f.write(” ; „+serial_52+”\n”)
if(host==”172.4.2.104″):
f.write(” ; „+serial_104+”\n”)
f.close()
with open(„./ricoh_count.csv”,”r+”) as file:
filedata = file.read()
file.seek(0)
file.truncate()
filedata=filedata.replace(„('”,””)
filedata=filedata.replace(„, ”)”,””)
filedata=filedata.replace(„n”,””)
filedata=filedata.replace(„'”,””)
filedata=filedata.replace(„\\”,””)
filedata=filedata.replace('”’,”)
file.write(filedata)
file.close()