By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Student

P: n/a
Hey
I need to write an application that will scan my network, explicitly my network group. So it needs to do something
like a "nbtscan" (you give it a parameter like 192.168.0.0/24 and it gives you a list of computers in your network
). I don't have any idea how to get list of computers in my network ( dispite ping everything,but maybe there is
some more robust technique. After I will have a list of computers I need to search their shared resources to find
out if they have any *.doc ( for example ) files. Are in .net framework any classes that could help ? Beside
sockets... Is there any nice class like netbios( i didn't find one ;( ? Maybe exist some nice tutorial "how to Netbios with VB.Net ?" ?
Student
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

This will only work if you are connected to an active directory. Add
a reference to system.directoryservices. Replace NetworkName with your
network name.

Dim de As New System.DirectoryServices.DirectoryEntry("LDAP://NetworkName")

Dim ds As New System.DirectoryServices.DirectorySearcher(de)

Dim r As System.DirectoryServices.SearchResult

ds.Filter = "(objectClass=computer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLine(r.GetDirectoryEntry.Name.ToStrin g)

Next

Catch e As Exception

Console.WriteLine(e.ToString)

End Try
This NetServerEnum api will work for a network without a domain. I
pasted the code for a sample console app below.

Imports System.Runtime.InteropServices

Module Module1

Structure Computer_info_101

Public Platform_ID As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.dll" _

(ByVal Servername As Integer, ByVal level As Integer, _

ByRef buffer As Integer, ByVal PrefMaxLen As Integer, _

ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, _

ByVal ServerType As Integer, ByVal DomainName As String, _

ByRef ResumeHandle As Integer) As Integer

Declare Function NetApiBufferFree Lib "Netapi32.dll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_101

Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle As
Integer

Dim BufPtr As Integer

Dim iPtr As IntPtr

MaxLenPref = -1

level = 101

ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, TotalEntries,
_

SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your workgroup
name

If ret <> 0 Then

Console.WriteLine("An Error has occured")

Return

End If

' loop thru the entries

For i = 0 To EntriesRead - 1

' copy the stuff into our structure

Dim ptr As IntPtr = New IntPtr(BufPtr)

computerInfo = CType(Marshal.PtrToStructure(ptr,
GetType(Computer_info_101)), _

Computer_info_101)

BufPtr = BufPtr + Len(ComputerInfo)

Console.WriteLine(computerInfo.Name)

Next

NetApiBufferFree(BufPtr)

Console.Write("Press Enter to End")

Dim s As String = Console.ReadLine()

End Sub

End Module

Ken
---------------
"Student" <St*****@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
Hey
I need to write an application that will scan my network, explicitly my
network group. So it needs to do something
like a "nbtscan" (you give it a parameter like 192.168.0.0/24 and it gives
you a list of computers in your network
). I don't have any idea how to get list of computers in my network (
dispite ping everything,but maybe there is
some more robust technique. After I will have a list of computers I need to
search their shared resources to find
out if they have any *.doc ( for example ) files. Are in .net framework any
classes that could help ? Beside
sockets... Is there any nice class like netbios( i didn't find one ;( ?
Maybe exist some nice tutorial "how to Netbios with VB.Net ?" ?
Student
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.