Detecing Network

Posted on 2007-07-27
Last Modified: 2013-11-26
Hi, By using VB.Net i want to detect the computers' names which are connected to network, Can I ?
Question by:ashraf_t
    LVL 6

    Expert Comment

    If you have an Active Directory in your network, you can retrieve machines with the System.DirectoryServices namespace, Just add a reference System.DirectoryServices.dll, then add the following code to the Form Load Event(you need a multiline TextBox TextBox1 on your Form):

    //... Add this to the top of your code:
    Imports System.DirectoryServices

    //...Add this inside the Form Load EventHandler:

            Dim objDirEnt As DirectoryEntry = New DirectoryEntry(adpath,username,password)
            Dim objChildDE As DirectoryEntry
            For Each objChildDE In objDirEnt.Children
                TextBox1.Text += objChildDE.Name + vbNewLine
            Next objChildDE

    LVL 6

    Expert Comment

    The adpath you'll have to figure out for yourself. Try something like this(replace DOMAINNAME):
    Dim adpath As String = "LDAP://DOMAINNAME.LOCAL/CN=Computers,DC=DOMAINNAME,DC=LOCAL"

    ... You can swap "CN=Computers" for "CN=Users" to get all the users.

    For username and password, the credentials of a user with administrator rights to the server should be enough.

    Dim username As String = "UserWithServerAdministratorPrivileges"
    Dim password As String = "UsersPassword"

    Author Comment

    there is no active directory , it just a simple netwrok
    LVL 6

    Accepted Solution

    LVL 96

    Assisted Solution

    by:Bob Learned
    You could use the net view /domain way:

    Imports System.Collections.Generic
    Imports System.Diagnostics

    Public Class NetViewDomain

      Public Shared Function GetDomainList(ByVal domain As String) As Dictionary(Of String, String)

        Dim proc As New Process()

        proc.StartInfo.FileName = "net.exe"
        proc.StartInfo.Arguments = "view /domain:" & domain
        proc.StartInfo.RedirectStandardOutput = True
        proc.StartInfo.UseShellExecute = False
        proc.StartInfo.CreateNoWindow = True
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden


        Dim output As String = proc.StandardOutput.ReadToEnd()

        Return ParseNames(output)

      End Function

      Private Shared Function ParseNames(ByVal input As String) As Dictionary(Of String, String)

        Dim list As New Dictionary(Of String, String)

        Dim text As New TextBox()
        Dim withinBlock As Boolean
        text.WordWrap = False
        text.Text = input

        For Each line As String In text.Lines
          If withinBlock Then
            Dim position As Integer = line.IndexOf(" ")
            If position <> -1 AndAlso Not line.Equals("The command completed successfully.") Then
              Dim name As String = line.Substring(0, position).Trim()
              Dim value As String = line.Substring(position + 1).Trim()
              list.Add(name, value)
            End If
            withinBlock = line.StartsWith("Server Name")
          End If
        Next line

        Return list

      End Function

    End Class

    Dim computers As Dictionary(Of String, String) = NetViewDomain.GetDomainList(Environment.UserDomainName)



    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now