ARTICLE

IP Lookup program in VB.NET

Posted by Michael Marasco Articles | Visual Basic 2010 June 26, 2003
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.
 
Reader Level:

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 'IPLookUp

share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor