hello,
can anybody teach me how to do that(I'm newbie in network programming), to detect all the computer name's list in the network(LAN with(out) domain) and also the IP's list of the computers, thanks before
Printable View
hello,
can anybody teach me how to do that(I'm newbie in network programming), to detect all the computer name's list in the network(LAN with(out) domain) and also the IP's list of the computers, thanks before
Well.. theres lots of ways I would imagine.. but we need an idea of your network... do you use Active Directory? Is this being ran on a server or on a client machine?
maybe from just the basic LAN, just simple networking without the server, so the program just detecting all the comp in LAN
I couldnt find any info on the subject when searching around. Looks like you might have to resort to api...
I did find this one link of a VB6 project that uses a couple classes in order to list the computers in a domain using API, of course it would need to be converted to .NET code..
http://www.planet-source-code.com/vb...15174&lngWId=1
well, thanks for the effort to help me, i'll try to look at it then
Perhaps you could also utilize the output of Net View or use WMI...
what is Net View and WMI, and how could I use that for detecting comps in network ? :confused:Quote:
Originally Posted by dee-u
You would need to write some unmanaged code suing the NetServerEnum API. I have some code that does it but its in VB6. I havent converted it to VB.NET yet as I havent had the need. Maybe if no one else has a solution I will make an effort to convert it.
Go Rob! :wave:Quote:
Originally Posted by RobDog888
Well, basically I'm waiting for John to post stating that it can be done easily with a certain class in .NET. :D I think I'll search until then. Maybe I'll beat him to it.
so far I found a calss to determine if your local system is connected to a network or not. :(
VB Code:
MessageBox.Show(System.Windows.Forms.SystemInformation.Network.ToString())
Guess I'll have a go at it then.
What is "LMCSTR"? Its in an API declaration.
I think its something like this?
VB Code:
<MarshalAs(UnmanagedType.LPStr)> _ Private Const LMCSTR As Int32 = LPCSTR <MarshalAs(UnmanagedType.LPStr)> _ Private Const LPCSTR As Int32 = UnmanagedType.LPStr
????
sorry but im really2 confused
I am about 75% way complete but I have run into a couple of issues converting the calls. I dont think I will be done tonight. Should be able to post it tomorrow.
Gotta love those API call conversions... (remember.. byval or byref :) )
Hey gig! Mind if I throw some APIs at you? :D
Error isVB Code:
<StructLayout(LayoutKind.Sequential)> _ Public Structure SERVER_INFO_100 <MarshalAs(UnmanagedType.LPStr)> _ Friend sv100_platform_id As Integer <MarshalAs(UnmanagedType.LPStr)> _ Friend sv100_name As Integer End Structure Private Declare Auto Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pTo As Integer, ByRef uFrom As Integer, ByVal lSize As Integer) Private Declare Auto Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pTo As String, ByRef uFrom As Integer, ByVal lSize As Integer) Private Sub Button1_Click(blah, blah, blah.... Dim se100 As SERVER_INFO_100 Dim bufptr As Integer Dim nStructSize As Integer Dim Cnt As Integer '... CopyMemory(se100, bufptr + (nStructSize * Cnt), nStructSize) 'ERRORQuote:
D:\Development\Tips .NET\Network Neighborhood\clsNetwork.vb(61): Overload resolution failed because no accessible 'CopyMemory' can be called with these arguments:
'Declare Auto Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As String, ByRef uFrom As Integer, lSize As Integer)': Value of type 'Network_Neighborhood.clsNetwork.SERVER_INFO_100' cannot be converted to 'String'.
'Declare Auto Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Integer, ByRef uFrom As Integer, lSize As Integer)': Value of type 'Network_Neighborhood.clsNetwork.SERVER_INFO_100' cannot be converted to 'Integer'.
First instinct would be to change "ByRef uFrom" to "ByVal uFrom" ... (it worked before hehehe)... but id have to search for examples of that, because ive never used it before..
I think that part is ok but the error message shows that its the conversion of the structure to a string or integer.
I overloaded the API call to see if either would work but nada. :(Quote:
SERVER_INFO_100' cannot be converted to 'String'
SERVER_INFO_100' cannot be converted to 'Integer'
Hey rob.. check out this link... has sample of vb.net code using it.. lists the declaration they use as well as their server_info_100 structure
http://www.eggheadcafe.com/forums/Fo...11135&INTID=14
***EDIT -Whoops.. forgot its the copymemory that the problem is at....
Cool! I dont like the way they do it but I will use the types for the APIs. I was sooo close. Intptr intstead of Integer. Shouldnt be long now. :)
Also, Marshal.SizeOf instead of LenB
Looks like they dont even use CopyMemory. The use a DirectCast -
:thumb: :DVB Code:
se101 = DirectCast(Marshal.PtrToStructure(New IntPtr(bufptr.ToInt32 + (nStructSize * cnt)), GetType(SERVER_INFO_101)), SERVER_INFO_101)
I got the class file to work now. :D Its similar to the link gig posted. I'll attach it if you want. I think I will make a little Net Neighborhood program out of it just for fun.
thanks rob :thumb: , but how to use it?, ill be waiting for your source code of the program :wave:Quote:
Originally Posted by RobDog888
How about this?
for the without domain bit:
from google groups
VB Code:
' 'Imports system.runtime.interopservices Dim WithEvents b As New Button Dim lv As New ListView Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load b.Location = New Point((Me.ClientSize.Width - b.Width) \ 2, Me.ClientSize.Height - 60) b.Text = "list" lv.View = View.Details lv.Columns.Add("Workgroup Computers", 300, HorizontalAlignment.Left) lv.Dock = DockStyle.Top lv.Height = Me.ClientSize.Height - 80 Me.Controls.Add(lv) Me.Controls.Add(b) AddHandler b.Click, AddressOf b_click End Sub 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 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 Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers Private Sub ListCompsInWorkgroup() 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) ' Enter your workgroup name here 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) lv.Items.Add(ComputerInfo.Name) Next NetApiBufferFree(BufPtr) End Sub Private Sub b_click(ByVal sender As Object, ByVal e As System.EventArgs) ListCompsInWorkgroup() End Sub
I posted the source code in the class attachment. Just use it like so.
VB Code:
'Adds to a listview control: Dim Servers As New clsNetwork Dim compNames As New ArrayList Dim compName As String Dim x As Integer compNames = Servers.GetServers(vbNullString, Servers.SV_TYPE_ALL).Clone() For x = 0 To compNames.Count - 1 lvwNetwork.Items.Add(compNames.Item(x).ToString) Next compNames.Clear()
thanks to all,
and i've tried rob's program(it worked), and jools too, thanks to u all, now i must learn the source code.
o , and what about the IP number of each computer, and in jools code, we must enter workgroup's name by ourself, but how to make the program automatically search comps name and ip only in its workgroup, thanks
Heya, could you please give your version in VB6 Rob?
Can anyone let me know where ROb's class attachment exists so that I can try it out? I am in dire need of that? where can I find clsNetwork?