Get IP From Hostname

|
  1. Create a new project
  2. Add a TextBox and name it “txtHostname”
  3. Add another TextBox and name it “txtIP”
  4. Add a button and name it “btnResolve” and give it appropriate text like “Resolve IP”
  5. Double click on the button to auto generate the button action code and insert code as shown below
Imports System.Net

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResolve.Click
		Dim hostname As IPHostEntry = Dns.GetHostByName(txtHostname.Text)

		Dim ip As IPAddress() = hostname.AddressList

		txtIP.Text = ip(0).ToString()
End Sub
End Class
Originally Posted on September 23, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.