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
Private
IPaddress As String
Public
Sub New()
Text = "IP Look Up"
BackColor = Color.White
txtBox1 =
New TextBox
txtBox1.Parent =
Me
txtBox1.Text = "Enter URL"
txtBox1.Location =
New Point(Font.Height * 6, Font.Height * 2)
Dim btnlook As New Button
btnlook.Parent =
Me
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 =
Me
label.Text = "IP Address"
label.Location =
New Point(Font.Height * 6, Font.Height * 10)
txtBox2 =
New TextBox
txtBox2.Parent =
Me
txtBox2.Text = " "
txtBox2.Location =
New Point(Font.Height * 6, Font.Height * 12)
Dim btnquit As New Button
btnquit.Parent =
Me
btnquit.BackColor = SystemColors.ControlDark
btnquit.Text = "Quit"
btnquit.Location =
New Point(Font.Height * 7, Font.Height * 16)
AddHandler btnquit.Click, AddressOf ButtonQuitOnClick
End Sub
'New
Public Sub ButtonOnClick(ByVal sender As Object, ByVal ea As EventArgs)
address = txtBox1.Text
GetIP(address)
End Sub
'ButtonOnClick
Private Sub GetIP(ByVal address As String)
Try
Dim IPHost As IPHostEntry = Dns.Resolve(address)
Dim addresses As IPAddress() = IPHost.AddressList
IPaddress = addresses(0).ToString()
txtBox2.Text = IPaddress
Catch exc As Exception
MessageBox.Show(exc.ToString())
End Try
End
Sub 'GetIP
Public Sub ButtonQuitOnClick(ByVal sender As Object, ByVal ea As EventArgs)Application.Exit()
End Sub
'ButtonQuitOnClick
Public Shared Sub Main()
Application.Run(
New IPLookUp)
End Sub 'Main
End Class 'IPLookUpv

Up Next
    Ebook Download
    View all
    Learn
    View all