How to all machines in LAN using VB.NET

No.of Views1097
Bookmarked7 times
Downloads 
Votes0
By  shanaj   On  13 Apr 2010 09:04:17
Tag : VB.NET , How to
How to all machines in LAN using VB.NET
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

 Introduction

In this snippet,getting all machines in LAN using VB.NET.Drag one list box and name it as LBox,In form load write the below code.

Dim childEntry As DirectoryEntry
Dim ParentEntry As New DirectoryEntry
Try
ParentEntry.Path = "WinNT:"
For Each childEntry In ParentEntry.Children
Select Case childEntry.SchemaClassName
Case "Domain"

Dim SubChildEntry As DirectoryEntry
Dim SubParentEntry As New DirectoryEntry
SubParentEntry.Path = "WinNT://" & childEntry.Name
For Each SubChildEntry In SubParentEntry.Children

Select Case SubChildEntry.SchemaClassName
Case "Computer"
LBox.Items.Add(SubChildEntry.Name)
End Select
Next
End Select
Next
Catch Excep As Exception
MsgBox("Error While Reading Directories")
Finally
ParentEntry = Nothing
End Try



On listbox changed write the below code to get the ip address

Try
Dim IPHEntry As Net.IPHostEntry
Dim IPAdd() As Net.IPAddress

Dim localHost As String
localHost = Dns.GetHostName()
IPHEntry = Dns.GetHostByName(LBox.SelectedItem.ToString())
IPAdd = IPHEntry.AddressList
Dim i As Integer

For i = 0 To IPAdd.GetUpperBound(0)

'Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)
MessageBox.Show(IPAdd(i).ToString)
'txtIp.Text = IPAdd(i).ToString
Next


Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Thank you

 
Sign Up to vote for this article
 
About Author
 
shanaj
Occupation-Not Provided
Company-Not Provided
Member Type-Junior
Location-Not Provided
Joined date-22 Oct 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top