IP Lookup program in VB.NET

This is an IP look up program that uses VB.NET Windows Forms and IPHostEntry to resolve the DNS request. You enter the URL in the first box and press the Look Up button and the IP shows in the bottom box.

I created the controls, instead of using the form designer and in doing so the placement is not that great. But it should give a very basic example of creating your own controls and how the IPHostEntry works.

Imports System
Imports System.IO
Imports System.Drawing
Imports System.Net
Imports System.Net.Sockets
Imports System.Windows.Forms
Imports System.Text
Class IPLookUp
Inherits Form
Private txtBox1 As TextBox
Private txtBox2 As TextBox
Private address As String
IPaddress As String
Sub New()
Text = "IP Look Up"
BackColor = Color.White
txtBox1 =
New TextBox
txtBox1.Parent =
txtBox1.Text = "Enter URL"
txtBox1.Location =
New Point(Font.Height * 6, Font.Height * 2)
Dim btnlook As New Button
btnlook.Parent =
btnlook.BackColor = SystemColors.ControlDark
btnlook.Text = "Look UP"
btnlook.Location =
New Point(Font.Height * 7, Font.Height * 6)
AddHandler btnlook.Click, AddressOf ButtonOnClick
Dim label As New Label
label.Parent =
label.Text = "IP Address"
label.Location =
New Point(Font.Height * 6, Font.Height * 10)
txtBox2 =
New TextBox
txtBox2.Parent =
txtBox2.Text = " "
txtBox2.Location =
New Point(Font.Height * 6, Font.Height * 12)
Dim btnquit As New Button
btnquit.Parent =
btnquit.BackColor = SystemColors.ControlDark
btnquit.Text = "Quit"
btnquit.Location =
New Point(Font.Height * 7, Font.Height * 16)
AddHandler btnquit.Click, AddressOf ButtonQuitOnClick
End Sub
Public Sub ButtonOnClick(ByVal sender As Object, ByVal ea As EventArgs)
address = txtBox1.Text
End Sub
Private Sub GetIP(ByVal address As String)
Dim IPHost As IPHostEntry = Dns.Resolve(address)
Dim addresses As IPAddress() = IPHost.AddressList
IPaddress = addresses(0).ToString()
txtBox2.Text = IPaddress
Catch exc As Exception
End Try
Sub 'GetIP
Public Sub ButtonQuitOnClick(ByVal sender As Object, ByVal ea As EventArgs)Application.Exit()
End Sub
Public Shared Sub Main()
New IPLookUp)
End Sub 'Main
End Class 'IPLookUpv

Similar Articles