'Objective: To Find SQL Server on the network using IP 'Created by: MAK 'Date: Sep 25, 2004 on error resume next Function Pingable(strHost) Dim objExec, objRE set objshell = wscript.createobject("wscript.shell") blnPingable = "False" 'assume failure Set objExec = objShell.Exec("cmd /C ping -a -n 2 " & strHost) string1 = objExec.StdOut.ReadAll if instr(1,string1,"TTL=",1) >0 then Pingable = True else pingable =false end if if pingable =True then Chaine = "Pinging " Chaine2 = "[" ValueSearch = InStr(1,string1,Chaine,1) ValueSearch2 = InStr(valuesearch,string1,Chaine2,1) If ValueSearch>=1 and ValueSearch2>1 Then y= mid(string1,ValueSearch,(ValueSearch2-ValueSearch)) else pingable="false" End If pingable = replace(y,"Pinging ","") pingable = replace(pingable," ","") if pingable =false or pingable="" then pingable ="False" end if end if Set objExec = Nothing Set objRE = Nothing End Function Set iFSO = CreateObject("Scripting.FilesyStemObject") Set oFSO = CreateObject("Scripting.FilesyStemObject") InputFile ="c:\IpRange\Source.txt" Outputfile="c:\IpRange\IpRangeLog.txt" Set ofile = ofso.createTextFile(OutputFile, True) Set ifile = iFSO.OpenTextFile(inputfile) Do until ifile.AtEndOfLine ip = ifile.ReadLine ofile.writeline "*************************************************" ofile.writeline "Scan SQL server for the ip range : " & ip & " Started" ofile.writeline now() x=ip For i = 1 to 254 x= x + cstr(i) 'msgbox test1 'ofile.writeline test servername = pingable(x) if servername<>"False" then ofile.writeline "________________________________________________" ofile.writeline "Machine= " & servername & ": IP Address= " & x Set objWMIService =nothing ' msgbox "winmgmts:\\" & servername & "\root\cimv2" Set objWMIService = GetObject("winmgmts:\\" & servername & "\root\cimv2") Set colItems = nothing query="" query = "Select * from Win32_Service" Set colItems = objWMIService.ExecQuery(query,,48) if err.number<>0 then ofile.writeline "Error: " & err.number ofile.writeline "Error: " & err.description else For Each objItem in colItems If left(objItem.name,5)="MSSQL" then ofile.writeline "Servicename: " & objItem.name end if next ofile.writeline "________________________________________________" end if 'msgbox cstr(ip)+cstr(i) else ofile.writeline "machine:" & x & " Not Pingable" end if x=ip next ofile.writeline "Scan SQL server for the ip range : " & ip &" COmpleted" ofile.writeline now() ofile.writeline "*************************************************" loop