List All machines on a network

Here is a snippit


Imports System.DirectoryServices 
     
        Dim de As New DirectoryEntry("WinNT://TEST") ' Put the name of yourworkgroup/domain here 
        Dim computer As DirectoryEntry 
        For Each computer In de.Children 
            ListBox1.Items.Add(computer.Name) 
        Next 

Here is a more complete one


Imports System.DirectoryServices 

        Dim objDE As DirectoryEntry 

        Dim MyWorkGroupName As String = "Mshome" '-- Change to your workgroup name 

        Dim strPath As String = "WinNT://" & MyWorkgroupName 

        objDE = New DirectoryEntry(strPath) '-- Create a new DirectoryEntry with the given path. 

        Dim objChildDE As DirectoryEntry 
        For Each objChildDE In objDE.Children 
            Console.WriteLine(objChildDE.Path) 
        Next objChildDE

This is an enhanced one


Dim compname As String 
        Dim strPath As String = "WinNT://" & System.Environment.UserDomainName 
        Dim mySearcher As DirectorySearcher = New DirectorySearcher(strPath) 
        mySearcher.Filter = ("(objectClass=computer)") ' <-----------------Here is the filter! Just computers 
        Dim resEnt As SearchResult 
        For Each resEnt In mySearcher.FindAll() 
           compname = Right(resEnt.GetDirectoryEntry().Name.ToString(), Len(resEnt.GetDirectoryEntry().Name.ToString())-3) 
           Console.WriteLine(compname) 
        Next 

Here is a function to find the ip of those machine names:


Function GetIPAddress(ByVal hostname As String) As String 
        Dim oAddr As System.Net.IPAddress 
        Dim sAddr As String 
        Try 
            With System.Net.Dns.GetHostByName(hostname) 
                oAddr = New System.Net.IPAddress(.AddressList(0).Address) 
                sAddr = oAddr.ToString 
            End With 
            GetIPAddress = sAddr 
        Catch 
            GetIPAddress = "" 
        End Try 
    End Function 

Here is a VB6 version to find a machine names on a network

machinelister.zip (4.09 KB)