How to find IP Address of Host using .net code

By: Issac Viewed: 153245 times  Printer Friendly Format    


Here is a simple code for you to find the IP address of a host machine System.net namespace provides the information about IP Address.

If you pass localhost in GetHostByName return the IP Address of local machine.

Imports System.Net
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim hostname As IPHostEntry = Dns.GetHostByName(TextBox1.Text)
        Dim ip As IPAddress() = hostname.AddressList
        TextBox2.Text = ip(0).ToString()
    End Sub
End Class

This source code returns the ip address of the host you are working with.


Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)

Comment on this tutorial