Detecing Network

Hi, By using VB.Net i want to detect the computers' names which are connected to network, Can I ?
Thanx
ashraf_tAsked:
Who is Participating?
 
ToFroCommented:
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

0
 
ToFroCommented:
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"
0
 
ashraf_tAuthor Commented:
there is no active directory , it just a simple netwrok
0
 
Bob LearnedCommented:
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
    proc.Start()

    proc.WaitForExit(20000)

    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
      Else
        withinBlock = line.StartsWith("Server Name")
      End If
    Next line

    Return list

  End Function

End Class

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

Bob

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.