locked
How do I get the IP address of a computer? RRS feed

  • Question

  • How do I get the Internet IP of a computer using VB? not the xxx.xxx.x.xxx of a router. This code will go into a Windows Forms control and will be storable.
    • Edited by Carstairs Sunday, June 6, 2010 3:09 AM how I plan to implement it
    Sunday, June 6, 2010 3:07 AM

Answers

  • You can use this code

     

        Dim ipAddress() As IPAddress = Dns.GetHostEntry(My.Computer.Name).AddressList
    
    
        Dim ip = From i As IPAddress In ipAddress Where i.AddressFamily = Sockets.AddressFamily.InterNetwork Select i
    
        If ip IsNot Nothing AndAlso ip.Count > 0 Then
          MessageBox.Show(ip(0).ToString)
        End If
    • Proposed as answer by Cor Ligthert Thursday, June 10, 2010 7:59 AM
    • Marked as answer by Liliane Teng Friday, June 11, 2010 8:50 AM
    • Marked as answer by Liliane Teng Friday, June 11, 2010 10:26 AM
    Sunday, June 6, 2010 3:38 AM
  • Hello Carstairs,
    Thanks for your post.
    Here are also two complete examples about getting IP address of using VB.NET. Hope them helpful.
    http://www.vbdotnetheaven.com/UploadFile/prvn_131971/ipvb11162005073000AM/ipvb.aspx
    (Get IP Address of a Host using VB.NET)
    http://www.devasp.net/net/articles/display/273.html
    (How to get IP Address using VB.Net)

    If you have any problems, please feel free to follow up.
    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Carstairs Wednesday, October 13, 2010 9:42 PM
    Thursday, June 10, 2010 3:43 AM

All replies

  • What do you know about the other computer? Do you know its name? Are you within the same network?
    Sunday, June 6, 2010 3:10 AM
  • The host computer will have the program installed and when a button is clicked, the IP address will be given. And the IP address will be stored in a text file as well.
    Sunday, June 6, 2010 3:12 AM
  • You can use this code

     

        Dim ipAddress() As IPAddress = Dns.GetHostEntry(My.Computer.Name).AddressList
    
    
        Dim ip = From i As IPAddress In ipAddress Where i.AddressFamily = Sockets.AddressFamily.InterNetwork Select i
    
        If ip IsNot Nothing AndAlso ip.Count > 0 Then
          MessageBox.Show(ip(0).ToString)
        End If
    • Proposed as answer by Cor Ligthert Thursday, June 10, 2010 7:59 AM
    • Marked as answer by Liliane Teng Friday, June 11, 2010 8:50 AM
    • Marked as answer by Liliane Teng Friday, June 11, 2010 10:26 AM
    Sunday, June 6, 2010 3:38 AM
  • Thanks
    Sunday, June 6, 2010 3:58 AM
  • Hello Carstairs,
    Thanks for your post.
    Here are also two complete examples about getting IP address of using VB.NET. Hope them helpful.
    http://www.vbdotnetheaven.com/UploadFile/prvn_131971/ipvb11162005073000AM/ipvb.aspx
    (Get IP Address of a Host using VB.NET)
    http://www.devasp.net/net/articles/display/273.html
    (How to get IP Address using VB.Net)

    If you have any problems, please feel free to follow up.
    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Carstairs Wednesday, October 13, 2010 9:42 PM
    Thursday, June 10, 2010 3:43 AM