Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a computer's name and IP address using VB.NET?

Tags:

vb.net

How can i get ip address of system by sending mac ip address as input using vb.net coding?

like image 223
ahmed Avatar asked Feb 10 '10 05:02

ahmed


2 Answers

Here is Example for this. In this example we can get IP address of our given host name.

   Dim strHostName As String = "jayeshsorathia.blogspot.com"
    'string strHostName = "www.microsoft.com";
    ' Get DNS entry of specified host name
    Dim addresses As IPAddress() = Dns.GetHostEntry(strHostName).AddressList

    ' The DNS entry may contains more than one IP addresses.
    ' Iterate them and display each along with the type of address (AddressFamily).
    For Each address As IPAddress In addresses
        Response.Write(String.Format("{0} = {1} ({2})", strHostName, address, address.AddressFamily))
        Response.Write("<br/><br/>")
    Next
like image 83
Jayesh Sorathia Avatar answered Sep 28 '22 06:09

Jayesh Sorathia


Private Function GetIPv4Address() As String
    GetIPv4Address = String.Empty
    Dim strHostName As String = System.Net.Dns.GetHostName()
    Dim iphe As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(strHostName)

    For Each ipheal As System.Net.IPAddress In iphe.AddressList
        If ipheal.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
            GetIPv4Address = ipheal.ToString()
        End If
    Next

End Function
like image 24
EagleEyes Avatar answered Sep 28 '22 07:09

EagleEyes