Sinisterly
[VB.NET]DNS IP Lookup - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: [VB.NET]DNS IP Lookup (/Thread-VB-NET-DNS-IP-Lookup)



[VB.NET]DNS IP Lookup - Sapientia - 07-17-2013

Well, for this tutorial you should add 2 Labels, 2 TextBox Controls and 1 Button. Make your form look something like this:
[Image: cLK6eR3.png]


Go in to the code view, and paste this function which will retrieve the ip of the website.

Code:
Public Function GetIP(ByVal URL As String) If url.ToString.Contains("http://") Then url = url.Replace("http://", String.Empty) End If If url.ToString.Contains("/") Then url = url.Replace("/", String.Empty) End If Dim hostname As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(URL) Dim ip As System.Net.IPAddress() = hostname.AddressList Return ip(0).ToString() End Function

Then, go back to design view and double click your button and paste the code below which will place the IP in TextBox2
Code:
TextBox2.Text = GetIP(TextBox1.Text)

If this works, you should see something like this:
[Image: mFiOsAd.png]


RE: [VB.NET]DNS IP Lookup - Eternity - 07-17-2013

Could be useful for future projects of mine, thanks Smile.

You can also use "" instead of string.empty like so:
url = url.Replace("http://", "")