gaugustine
Posts: 13
Score: 2 Joined: 9/20/2004 Status: offline
|
here is a copy of it and i hope it is useful, there are some things that will need to be changed such as the info in the idmif that it creates. The first time you collect the information it should create the database table for the info to be stored in. The printer makes are also hardcoded so if it finds it, it know where to look for more info. It could be shorted or expanded to meet your needs. also need to know what your standard is for ip addressing. we use the range of x.x.x.200~254. in the script you can change that if you have specific ranges. Here is a list of what printers it should collect: Lexmark T630, T640, C720, T632, T620, T522, T520, T430, T420, c510, Optra T614, Optra T610, Optra C710, Optra M412, Optra SC 1275 IBM Infoprint 1125 Dell Laser Printer 5100cn, Laser Printer M5200, Laser Printer 1700N HP InkJet CP1700, Bussiness InkJet 2300, LaserJet 2500, LaserJet 4100 Series, LaserJet 4200 Series, LaserJet 4250, LaserJet 4600, LaserJet 5si, LaserJet 8000 Series, LaserJet 8100 Series, LaserJet 8150 Series, laserjet 4345 mfp tektronix Phaser 740E '*********************************************************************************** '* Printercollection.vbs '* Written by Greg Augustine '* Requires net-snmp-5.2.1.2-1.win32.exe to be installed (snmpget, snmpwalk) '*********************************************************************************** set objArgs = Wscript.Arguments dim wshshell, objFSO, Scansub, subnetparse, subcount, machinecount, intsize dim ipad, snmp, objfile, strPlist, pgcount, checkname, listorscan, rexec dim finderror, arcount, listorsingle, donedb, make, model, descr, serial dim arripaddresses() ' this get the servername, and queries sms to get the subnets to search dim subnets() subnetssize = 0 Set objNetwork = WScript.CreateObject("WScript.Network") set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") 'Need to replace SMSXXX with Server name 'Have compiled in SMS installer Script to pass userid and password to attach to SMS using objArgs() set objSWbemServices= objSWbemLocator.ConnectServer("SMSXXX", "root\sms",objArgs(0),objArgs(1)) Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation") For Each Location In ProviderLoc If Location.ProviderForLocalSite = True Then Set objSWbemServices = objSWbemLocator.ConnectServer _ (Location.Machine, "root\sms\site_" + Location.SiteCode,objArgs(0),OBJaRGS(1)) End If Next strQuery3 = "select servername, sitecode, Sitename from SMS_Site where servername = '" & objnetwork.computername & "'" Set objsiteserver = objSWbemServices.ExecQuery(strQuery3) for each sitesrv in objsiteserver location = sitesrv.sitename Query4 = "select AssignDetails from sms_sci_siteassignment where sitecode = '" & sitesrv.sitecode &"'" set AssocSet = objSWbemServices.ExecQuery(Query4) For each assoc in AssocSet for x = 0 to UBound(Assoc.AssignDetails) ReDim Preserve subnets(subnetsSize) subnets(subnetsSize) = assoc.assigndetails(x) subnetssize = subnetssize + 1 next next next set wshshell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 for each subnet in subnets subcount = len(subnet) subnetparse = left(subnet, (subcount - 1)) machinecount = 200 ' change this to change range to search 200 searches 200~254 intsize = 0 'wscript.StdOut.Write " Scanning on " & subnetparse & "0 " do while machinecount <= 254 ' change back to 254 ipad = subnetparse & machinecount set rexec = WshShell.Exec("snmpget -v1 -cpublic -OQv " & ipad & " system.sysDescr.0") finderror = rexec.stdout.readline finderror = lcase(finderror) if instr(finderror, "lexmark") > 0 then expandarr() elseif instr(finderror, "hp") > 0 then expandarr() elseif instr(finderror, "dell") > 0 then expandarr() elseif instr(finderror, "ibm") > 0 then expandarr() end if machinecount = machinecount + 1 loop 'Wscript.echo "" strPlist = "C:\~prtcol901.txt" if objFSO.FileExists(strPlist) then set StrPath = objFSO.openTextFile(strPlist, forwriting) arcount = 0 do while arcount < (intsize) strPath.writeline arripaddresses(arcount) arcount = arcount + 1 loop else set strPath = objFSO.CreateTextFile(StrPlist) arcount = 0 do while arcount < (intsize) strPath.writeline arripaddresses(arcount) arcount = arcount + 1 loop end if strPath.close reDim arripaddresses(0) Set objFile = objFSO.OpenTextFile(strPlist, ForReading) Do until objFile.AtEndofStream strPrinter = objFile.readline snmp = "snmpget -v1 -cpublic -OQv " & strPrinter on error resume next set oExec = WshShell.Exec(snmp & " .1.3.6.1.2.1.43.10.2.1.4.1.1") pgcount = oexec.stdout.readline set pExec = WshShell.Exec(snmp & " hrDeviceDescr.1") descr = pexec.stdout.readline set qExec = WshShell.Exec(snmp & " interfaces.ifTable.ifEntry.ifDescr.2") getmfp = qExec.StdOut.Readline if lcase(left(getmfp, 3)) = "mfp" then mfp = "Yes" else mfp = "No" end if walk = "snmpwalk -v1 -cpublic -OQv " & strPrinter & " ip.ipAddrTable.ipAddrEntry.ipAdEntAddr.10" set rexec = WshShell.Exec(walk) findip = rexec.stdout.readline if findip = "" then findip = strPrinter elseif findip = "End of MIB" then findip = strPrinter end if set rxexc = wshshell.exec(snmp & " sysName.0") name = rxexc.stdout.readline if name = "" then name = findip end if make = left(Descr, 2) GETMAKE() bb = 1 aa = len(strPrinter) dim arrhexs() intsize4 = 0 do while intsize4 <= aa - 1 ReDim Preserve arrhexs(intsize4) arrhexs(intsize4) = mid(strPrinter, bb, 1) intsize4 = intsize4 + 1 bb = bb + 1 loop chgsize = 0 nextstep = 0 dim arroctets(3) do while chgsize <= aa - 1 if arrhexs(chgsize) = "." then nextstep = nextstep + 1 else arroctets(nextstep) = arroctets(nextstep) & arrhexs(chgsize) end if chgsize = chgsize + 1 loop uid = hex(arroctets(0)) & hex(arroctets(1)) & hex(arroctets(2)) & hex(arroctets(3)) key1 = "HKLM\SOFTWARE\Microsoft\SMS\Client\Configuration\Client Properties" idmifkey = wshshell.regread(key1 & "\IDMIF Directory") set CreateIDMif = objFSO.CreateTextFile(idmifkey & "\" & name & ".mif") ' will need to change the following to meet your needs CreateIDMif.writeline "//Architecture<Network_Printer>" CreateIDMif.writeline "//Uniqueid<" & uid & ">" CreateIDMif.writeline "Start Component" CreateIDMif.writeline " Name = ""Printer Information""" CreateIDMif.writeline " Start Group" CreateIDMif.writeline " Name = ""Printer Information""" CreateIDMif.writeline " ID = 1" CreateIDMif.writeline " Class = ""Network_Printer""" CreateIDMif.writeline " Key = 1" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""PrinterName""" CreateIDMif.writeline " ID = 1" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & name & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""PrinterMake""" CreateIDMif.writeline " ID = 2" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & make & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""PrinterModel""" CreateIDMif.writeline " ID = 3" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & model & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""PrinterMFP""" CreateIDMif.writeline " ID = 4" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & mfp & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""PrinterSerial""" CreateIDMif.writeline " ID = 5" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & serial & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""PrinterIP""" CreateIDMif.writeline " ID = 6" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & findip & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""PrinterPageCount""" CreateIDMif.writeline " ID = 7" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & pgcount & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " Start Attribute" CreateIDMif.writeline " Name = ""County""" CreateIDMif.writeline " ID = 8" CreateIDMif.writeline " Type = String(50)" CreateIDMif.writeline " Storage = Specific" CreateIDMif.writeline " Value = """ & location & """" CreateIDMif.writeline " End Attribute" CreateIDMif.writeline " End Group" CreateIDMif.writeline "End Component" CreateIDMif.close erase arrhexs erase arroctets Make = "" model = "" mfp = "" serial = "" findip = "" pgcount = "" Loop objfile.close objFSO.deletefile(strPlist) Next '*********************************************************************************** ' Function GETMAKE '*********************************************************************************** function GETMAKE() if lcase(make) = "le" then make = "Lexmark" elseif lcase(make) = "ib" then make = "IBM" elseif lcase(make) = "de" then make = "Dell" elseif lcase(make) = "hp" then make = "HP" elseif lcase(make) = "te" then if lcase(left(descr, 9)) = "tektronix" then make = "Tektronix" end if else set pExec = WshShell.Exec(snmp & " sysDescr.0") descr = pexec.stdout.readline descr = left(descr, 51) descr = right(descr, 9) if lcase(descr) = "jetdirect" then Make = "JetDirect Device" else make = "Can not Determine" end if end if if Make = "Lexmark" then model = left(Descr, 12) model = right(model, 4) if lcase(model) = "t630" then model = "T630" lex1() elseif lcase(model) = "t640" then model = "T640" lex1() elseif lcase(model) = "c720" then model = "C720" lex1() elseif lcase(model) = "t632" then model = "T632" lex1() elseif lcase(model) = "t620" then model = "T620" serial = left(Descr, 21) serial = right(serial, 8) elseif lcase(model) = "t522" then model = "T522" lex1() elseif lcase(model) = "t520" then model = "T520" lex1() elseif lcase(model) = "t430" then model = "T430" lex1() elseif lcase(model) = "t420" then model = "T420" lex1() elseif lcase(model) = "c510" then model = "c510" lex1() else model = left(Descr, 18) model = right(model, 10) if lcase(model) = "optra t614" then model = "Optra T614" serial = right(Descr, 7) if lcase(serial) = "partnum" then noserial() end if elseif lcase(model) = "optra t610" then model = "Optra T610" serial = left(Descr, 26) serial = right(serial, 7) elseif lcase(model) = "optra c710" then model = "Optra C710" serial = right(Descr, 7) elseif lcase(model) = "optra m412" then model = "Optra M412" serial = right(Descr, 7) elseif lcase(model) = "internatio" then set sExec = WshShell.Exec(snmp & " system.sysDescr.0") descr2 = sexec.stdout.readline i = len(descr2) descr2 = left(descr2, (i - 21)) model = right(descr2, 7) if lcase(model) = "sc 1275" then model = "Optra SC 1275" serial = right(descr, 7) end if else nomodel() noserial() end if end if elseif Make = "IBM" then model = left(Descr, 18) model = right(model, 14) if lcase(model) = "infoprint 1125" then model = "Infoprint 1125" serial = left(Descr, 26) serial = right(serial, 7) else nomodel() noserial() end if elseif make = "Dell" then i = len(descr) model = right(descr, (i - 5)) if len(model) > 20 then model = left(model, 20) end if if lcase(model) = "laser printer 5100cn" then model = "Laser Printer 5100cn" cn5100() elseif lcase(model) = "laser printer m5200 " then model = "Laser Printer M5200" m5200() elseif lcase(model) = "laser printer 1700n " then model = "Laser Printer 1700N" serial = left(descr, 32) serial = right(serial, 7) elseif i = 12 then model = descr if lcase(model) = "deskjet 6122" then Model = "DeskJet 6122" noserial() end if else nomodel() noserial() end if elseif make = "HP" then model = right(Descr, 13) if lcase(model) = "laserjet 4250" then model = "LaserJet 4250" hp1() elseif lcase(model) = "laserjet 2500" then model = "LaserJet 2500" hp1() elseif lcase(model) = "laserjet 4600" then model = "LaserJet 4600" hp1() elseif lcase(model) = "inkjet cp1700" then model = "InkJet CP1700" noserial() elseif lcase(right(descr, 11)) = "inkjet 2300" then Model = "Bussiness InkJet 2300" noserial() elseif lcase(right(descr, 20)) = "laserjet 8150 series" then model = "LaserJet 8150 Series" hp1() elseif lcase(right(descr, 20)) = "laserjet 8000 series" then model = "LaserJet 8000 Series" hp1() elseif lcase(right(descr, 20)) = "laserjet 4100 series" then model = "LaserJet 4100 Series" hp1() elseif lcase(right(descr, 20)) = "laserjet 4200 series" then model = "LaserJet 4200 Series" hp1() elseif lcase(right(descr, 13)) = "laserjet 4200" then model = "LaserJet 4200" hp1() elseif lcase(right(descr, 12)) = "laserjet 5si" then model = "LaserJet 5si" hp1() elseif lcase(right(descr, 20)) = "laserjet 8100 series" then model = "LaserJet 8100 Series" hp1() elseif lcase(right(descr, 20)) = "hp laserjet 4345 mfp" then model = "laserjet 4345 mfp" hp1() else model = "Can not Determine" noserial() end if elseif make = "tektronix" then model = left(descr, 28) model = right(model, 11) if lcase(model) = "phaser 740e" then model = "Phaser 740E" serial = right(descr, 7) end if elseif make = "JetDirect Device" then model = "Can not Determine" noserial() else model = "Can not Determine" noserial() end if end function '*********************************************************************************** ' Function expandarr '*********************************************************************************** function expandarr() ReDim Preserve arripaddresses(intsize) arripaddresses(intsize) = ipad intsize = intsize + 1 end function '*********************************************************************************** ' Function nomodel '*********************************************************************************** function nomodel() model = "Can not Determine" end function '*********************************************************************************** ' Function noserial '*********************************************************************************** function noserial() serial = "Can not Determine" end function '*********************************************************************************** ' Function lex1 '*********************************************************************************** function lex1() serial = left(Descr, 20) serial = right(serial, 7) end function '*********************************************************************************** ' Function hp1 '*********************************************************************************** function hp1() set tExec = WshShell.Exec(snmp & " .1.3.6.1.2.1.43.5.1.1.17.1") serial = tExec.StdOut.Readline serial = left(serial, 11) serial = right(serial, 10) end function '*********************************************************************************** ' Function m5200 '*********************************************************************************** function m5200() strURL = "http://" & strPrinter & "/printer/info" if objFSO.fileExists(".\temp~1.txt") then objFSO.DeleteFile(".\temp~1.txt") end if Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0") oXMLHTTP.Open "GET", strURL, False OXMLHTTP.Send If oXMLHTTP.Status = 200 Then strBody = oXMLHTTP.responsetext Set objFile2 = objFSO.CreateTextFile (".\temp~1.txt") objFile2.Write strbody objfile2.close End If Set objFile3 = objFSO.OpenTextFile (".\temp~1.txt", 1) do until objfile3.atendofstream linein = objfile3.readline If Instr(linein, "Dell Service Tag Number") > 0 Then linein = objfile3.readline serial = right(linein, 12) serial = left(serial, 7) found = 1 Exit Do End If loop if found <> 1 then noserial() end if objfile3.close objFSO.deletefile(".\temp~1.txt") end function '*********************************************************************************** ' Function 5100cn '*********************************************************************************** function cn5100() strURL = "http://" & strPrinter & "/ews/status/infomation.htm" if objFSO.fileExists(".\temp~1.txt") then objFSO.DeleteFile(".\temp~1.txt") end if Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0") oXMLHTTP.Open "GET", strURL, False OXMLHTTP.Send If oXMLHTTP.Status = 200 Then strBody = oXMLHTTP.responsetext Set objFile2 = objFSO.CreateTextFile (".\temp~1.txt") objFile2.Write strbody objfile2.close End If Set objFile3 = objFSO.OpenTextFile (".\temp~1.txt", 1) do until objfile3.atendofstream linein = objfile3.readline If Instr(linein, "Dell Service Tag Number") > 0 Then serial = right(linein, 17) serial = left(serial, 7) found = 1 Exit Do End If loop if found <> 1 then noserial() end if objfile3.close objFSO.deletefile(".\temp~1.txt") end function
< Message edited by gaugustine -- 7/3/2006 1:41:38 PM >
|