Click here to Skip to main content
15,664,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

How do I find the ipaddress of a localhost like
Updated 8-Dec-10 22:35pm
Rajesh Anuhya 9-Dec-10 3:35am    
can you explain it little bit more.., Normally localhost IP is
Dalek Dave 9-Dec-10 4:35am    
Minor Edit for Readability.

Do you want to know your own IP or form an other computer?
For this case i use this code:

Public Shared Function GetIP(Optional ByVal computer As String = "") As ArrayList
    Dim computername As String
    Dim host As IPHostEntry
    Dim hostadresses() As IPAddress
    Dim i As Integer = 0
    Dim IPs As ArrayList = New ArrayList

    If computer = String.Empty Then
        computername = Dns.GetHostName()
        computername = computer
    End If

    host = Dns.GetHostEntry(computername)
    hostadresses = host.AddressList()
    For i = 0 To hostadresses.GetLength(0) - 1

    Return IPs
End Function

If you leave the Optional Byval computer empty, you will get your own IP-Adress.
If the DNS-Name of an other computer is known -> you can get the IP.
The Function returns the Ip-Adresses in an ArrayList.

I hope I can help with this code-sample :cool:

Share this answer
See the following Codeproject's article (I know it is C#, but translation to VB.NET should be straightforward): "How To Get IP Address Of A Machine"[^].

P.S.: Make sure to check out the following remark in the article's follow up:[^].

Share this answer
add name space

after place bellow code

public void UseDNS()
   string hostName = Dns.GetHostName();
   Console.WriteLine("Host Name = " + hostName);
   IPHostEntry local = Dns.GetHostByName(hostName);
   foreach(IPAddress ipaddress in local.AddressList)
      Console.WriteLine("IPAddress = " + ipaddress.ToString());
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900