Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to list all Windows server in a specific subnet?

Posted on 2011-02-14
5
587 Views
Last Modified: 2012-08-14
How to list all Windows servers in a specific subnet?
0
Comment
Question by:SAM2009
5 Comments
 
LVL 6

Expert Comment

by:ashunnag
ID: 34887566
you need a tool for ping sweep like R3X. you can download it from this link:
http://www.4shared.com/file/I23FIfhy/Project_R3x_v_060_SE.html
0
 
LVL 11

Expert Comment

by:kaskhedikar_tushar
ID: 34887644
0
 
LVL 5

Expert Comment

by:NotVeryFat
ID: 34887904
Just to add to the above, a very simple free tool is AngryIP (www.angryip.org) that can scan by IP address range/ subnet and export to csv etc.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 34892362
Hi there, this VBS will do the job.  It reads the servers names from Active Directory, and lists them in a CSV file in subnet order.

Regards,

Rob.
'http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0202.mspx
Const ADS_SCOPE_SUBTREE = 2

Set objShell = CreateObject("WScript.Shell")

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select name, operatingSystem, operatingSystemVersion from 'LDAP://" & strDNSDomain & "' where objectClass='computer' ORDER BY operatingSystem"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Const adVarChar = 200
Const MaxCharacters = 255
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Subnet", adVarChar, MaxCharacters
DataList.Fields.Append "ServerName", adVarChar, MaxCharacters
DataList.Fields.Append "OperatingSystem", adVarChar, MaxCharacters
DataList.Fields.Append "OperatingSystemVersion", adVarChar, MaxCharacters
DataList.Open

strCSVFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "ServersAndSubnets.csv"
Do Until objRecordSet.EOF
	If InStr(LCase(objRecordSet.Fields("operatingSystem").Value), "server") > 0 Then
		strServer = objRecordSet.Fields("name").Value
		strIP = ResolveIP(strServer)
		strOS = objRecordSet.Fields("operatingSystem").Value
		strOSVersion = objRecordSet.Fields("operatingSystemVersion").Value
		DataList.AddNew
		If InStr(strIP, ".") > 0 Then
			DataList("Subnet") = Left(strIP, InStrRev(strIP, ".") - 1)
		Else
			DataList("Subnet") = strIP
		End If
		DataList("ServerName") = strServer
		DataList("OperatingSystem") = strOS
		DataList("OperatingSystemVersion") = strOSVersion
		DataList.Update
	End If
	objRecordSet.MoveNext
Loop

DataList.Sort = "Subnet,ServerName"
DataList.MoveFirst

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutput = objFSO.CreateTextFile(strCSVFile, True)
objOutput.WriteLine """Subnet"",""Server Name"",""Operating System"",""Operating System Version"""
While Not DataList.EOF
	objOutput.WriteLine """" & DataList("Subnet") & """,""" & DataList("ServerName") & """,""" & DataList("OperatingSystem") & """,""" & DataList("OperatingSystemVersion") & """"
	DataList.MoveNext
Wend
DataList.Close
objOutput.Close

MsgBox "Done. Please see " & strCSVFile

Function ResolveIP(computerName)
	Set objShell = CreateObject("WScript.Shell")
	Set objExec = objShell.Exec("ping " & computerName & " -n 1")
	strOutput = objExec.StdOut.ReadAll
	Set RegEx = New RegExp
	RegEx.Pattern = "\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]"
	RegEx.Global = True
	If RegEx.Test(strOutput) Then
		ResolveIP = RegEx.Execute(strOutput)(0).Submatches(0)
	Else
		ResolveIP = "IP Address could not be resolved"
	End If
End Function

Open in new window

0
 
LVL 1

Author Closing Comment

by:SAM2009
ID: 34903775
Very good script! Thanks again!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question