Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to list all Windows server in a specific subnet?

Posted on 2011-02-14
5
Medium Priority
?
608 Views
Last Modified: 2012-08-14
How to list all Windows servers in a specific subnet?
0
Comment
Question by:SAM2009
[X]
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
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
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 …

730 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