Click here to Skip to main content
15,888,579 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 122.164.97.87.?
Posted
Updated 8-Dec-10 22:35pm
v3
Comments
Rajesh Anuhya 9-Dec-10 3:35am    
can you explain it little bit more.., Normally localhost IP is 127.0.0.1
Dalek Dave 9-Dec-10 4:35am    
Minor Edit for Readability.

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

VB
Imports system.net
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()
    Else
        computername = computer
    End If

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

    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:


Regards,
Z
 
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:
http://www.codeproject.com/Messages/3479471/Re-My-vote-of-1.aspx[^].

:)
 
Share this answer
 
v3
add name space System.net

after place bellow code

C#
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