Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Get IP Address Machines on the Local Area network from Machine Name using System.DirectoryServices NameSpace .net 2.0.

Author: DevAsp Team
Download Source Code : 686_GetMachineIP.zip

In this simple article you will learn how you can Get IP Address Machines on the Local Area network from Machine Name using System.DirectoryServices NameSpace.

Simply just create New Project of VB.

 

Firstly Add Reference of System.DirectoryServices from references.

 

Now drag one Button, one TextBox and three Labels on the form

 

 

Now just write code on Form Load Event

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TextBox1.Text = "Localhost"

 

        Label2.Text = "Machine Name"

 

        Label3.Text = "IP"

 

        Button1.Text = "Get Machine IP"

 

        Me.Text = "Get Machine IP"

    End Sub

 

 

Now Write this Function

 

 

Function GetIPAddress(ByVal CompName As String) As String

        Dim oAddr As System.Net.IPAddress

 

        Dim sAddr As String

 

        Try

 

            With System.Net.Dns.GetHostByName(CompName)

 

                oAddr = New System.Net.IPAddress(.AddressList(0).Address)

 

                sAddr = oAddr.ToString

 

            End With

 

            GetIPAddress = sAddr

 

        Catch Excep As Exception

 

            MsgBox(Excep.Message, MsgBoxStyle.OkOnly, "DevAsp Messenger")

 

        Finally

 

        End Try

 

    End Function

 

 

Now write code on Button Click Event

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        Label1.Text = GetIPAddress(TextBox1.Text)

 

    End Sub

 

 

After Pressing this button you get IP address of machine in the textbox.

Article Comments
Great

Posted on 5/23/2007 1:34:10 PM by John Stendor

how to view all system ip address into single listbox in vb.net?

Posted on 3/20/2008 10:17:54 AM by prakash

dear all
I have built a project for control in my office, so i use client/server
and i want to know the client name and user name for insert into my database. so how can i do it please kindly reply me thank you!!

Posted on 11/29/2009 10:03:57 PM by khunheng

HI khunheng,

You can insert their name in database on connection time of client application and you can learn how to get client machine name from this article

http://www.devasp.net/net/articles/display/341.html

Thanks

Posted on 11/30/2009 4:39:39 AM by zunnair

i am arun & my mail id is narwal_boy23@yahoo.com

i want to create a site to make a attendence of the staff and when the user click the button & the ip address of the sysytem is updated on the database

kindly help me to make the programme

Posted on 5/19/2010 5:45:29 AM by arun narwal

this code is for ony see the particular system but i wants to know ipaddress of all system connected with lan. i am not on server i am working as a client on client system.

Posted on 11/16/2010 4:21:54 AM by problem of vb.net

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get all Machines on the Local Area network using System.DirectoryServices NameSpace .net 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net