Download ActiveSocket Network Communications Toolkit 4.1  (5105 KB - .exe file)
Download Manual  (505 KB - .htm file)
ASP .NET (Visual Basic) IPtoCountry Sample Source Code
ActiveSocket provides an easy-to-use development interface to a variety of IP protocols.
By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: ICMP, HTTP and HTTPs with support for proxy servers and secure web sites, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets (TCP and UDP), WOL (Wake-On-LAN), IP to country lookup and more.
ActiveSocket can be well integrated into .NET environments.
This document describes how ActiveSocket can be integrated into into ASP.NET projects.
Prerequisites
You must install and configre Internet Information Services (IIS) before using the ActiveSocket Toolkit with ASP .NET
If you don't have IIS installed, use the following steps:
- From the Control Panel, click 'Add/Remove Programs'.
Select the 'Add/Remove Windows Components' icon from the left pane, then select 'Application Server' and click on 'Details'.
You can now select both 'ASP .NET' and 'Internet Information Services (IIS)'. Click 'OK' to continue installation;
- Make sure that ASP .NET is allowed on the web server:

(Click on the picture to enlarge)
Step 1: Download and install ActiveSocket
Download ActiveSocket from the ActiveXperts Download Site and start the installation.
The installation guides you through the installation process.
Step 2: Create a new ASP .NET VB Project
Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu.
Choose 'New' from the 'File' menu and click on 'Web Site'. In the 'Web Site' dialog, select ASP .NET Web Site.
Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution').
Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):

(Click on the picture to enlarge)
Step 3: Refer to the ActiveSocket Library and create the objects
Now that a new project has been created, you must add a reference to the ActiveSocket library in the project to be able to use the ActiveSocket object.
To do so, choose 'Add Reference...' from the 'Project' menu.
In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveSocket 3.1 Type Library' as shown in the following picture:

(Click on the picture to enlarge)
Click 'OK' to close the 'Add Reference' dialog.
On top of your code, type the following line to use the ActiveSocket namespace:
Imports ASOCKETLib
In your Main function, declare and create the following object:
Public objIPtoCountry As IPtoCountry
objIPtoCountry = New IPtoCountry ()
Step 4: Perform an IP to country lookup
You can now convert IP addresses to country names.
The following code shows how to build a simple lookup utility using ASP.NET
webform1.aspx.vb
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents txtHostname As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCountry As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCountryCode As System.Web.UI.WebControls.TextBox
Protected WithEvents btnGetCountry As System.Web.UI.WebControls.Button
Protected WithEvents lblHostname As System.Web.UI.WebControls.Label
Protected WithEvents lblCountry As System.Web.UI.WebControls.Label
Protected WithEvents lblCountryCode As System.Web.UI.WebControls.Label
Protected WithEvents lblResult As System.Web.UI.WebControls.Label
Protected WithEvents LblHeader As System.Web.UI.WebControls.Label
Protected WithEvents lblHeader2 As System.Web.UI.WebControls.Label
Protected WithEvents txtResults As System.Web.UI.WebControls.TextBox
#Region " Web Form Designer Generated Code "
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Create the IpToCountry Object so you can get the location of your address
Dim objIpToCountry As ASOCKETLib.IPtoCountry
objIpToCountry = New ASOCKETLib.IPtoCountry()
End Sub
Private Sub btnGetCountry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCountry.Click
'First get the address and strip things like http://, because activeSocket
'is not able to process an address which starts with http:// or something
'like that...
Dim strAddress
strAddress = txtHostname.Text
strAddress = Replace(strAddress, "http://", "")
strAddress = Replace(strAddress, "https://", "")
strAddress = Replace(strAddress, "ftp://", "")
'and so on...
'
objIpToCountry.Clear()
objIpToCountry.Host = strAddress
objIpToCountry.Query()
If (objIpToCountry.LastError = 0) Then
'Before you print te results, make sure your query executed succesfully
txtCountry.Text = objIpToCountry.CountryName
txtCountryCode.Text = objIpToCountry.CountryCode
Else
'If it has not executed succesfully, print UNKNOWN and ??
txtCountry.Text = "UNKNOWN"
txtCountryCode.Text = "??"
End If
If (txtCountry.Text = "") Then
'If the query HAS succesfully been executed but there are no results
'Also print UNKNOWN and ??
txtCountry.Text = "UNKNOWN"
txtCountryCode.Text = "??"
End If
'And last, but not least, print the results/errormessages
Dim strResults
strResults = objIpToCountry.LastError
strResults = strResults & " : "
strResults = strResults & objIpToCountry.GetErrorDescription(objIpToCountry.LastError)
txtResults.Text = strResults
End Sub
End Class
Webform1.aspx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="IPtoCountryVB.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie3-2nav3-0">
<style>
INPUT { BORDER-RIGHT: navy 1px solid; BORDER-TOP: navy 1px solid; FONT-SIZE: x-small; BORDER-LEFT: navy 1px solid; COLOR: navy; BORDER-BOTTOM: navy 1px solid; FONT-FAMILY: verdana; BACKGROUND-COLOR: white }
TD { FONT-SIZE: x-small; COLOR: navy; FONT-FAMILY: verdana }
H2 { COLOR: navy; FONT-FAMILY: verdana }
H3 { COLOR: navy; FONT-FAMILY: verdana }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<TABLE height="678" cellSpacing="0" cellPadding="0" width="229" border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="229" height="678">
<form id="Form1" method="post" runat="server">
<TABLE height="212" cellSpacing="0" cellPadding="0" width="666" border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="6" height="8"></TD>
<TD width="1"></TD>
<TD width="89"></TD>
<TD width="67"></TD>
<TD width="1"></TD>
<TD width="66"></TD>
<TD width="286"></TD>
<TD width="150"></TD>
</TR>
<TR vAlign="top">
<TD colSpan="3" height="56"></TD>
<TD colSpan="5">
<asp:Label id="LblHeader" runat="server" Height="22px" Width="505px"><h2>ActiveSocket IP to Country Sample</h2></asp:Label>
</TD>
</TR>
<TR vAlign="top">
<TD colSpan="6" height="47"></TD>
<TD colSpan="2">
<asp:Label id="lblHeader2" runat="server" Height="22px" Width="150px"><h3>In ASP.NET VB</h3></asp:Label>
</TD>
</TR>
<TR vAlign="top">
<TD colSpan="4" height="2"></TD>
<TD colSpan="3" rowSpan="2">
<asp:TextBox id="txtHostname" runat="server" Width="350px" Height="22px">http://forum.activexperts.com</asp:TextBox>
</TD>
<TD>
</TD>
</TR>
<TR vAlign="top">
<TD height="23"></TD>
<TD colSpan="3">
<asp:Label id="lblHostname" runat="server" Height="22px" Width="150px">Hostname:</asp:Label>
</TD>
<TD>
<asp:Button id="btnGetCountry" runat="server" Height="22px" Width="147px" Text="Get country!"></asp:Button>
</TD>
</TR>
<TR vAlign="top">
<TD colSpan="4" height="3"></TD>
<TD colSpan="4" rowSpan="2">
<asp:TextBox id="txtCountry" runat="server" Height="22px" Width="500px" Enabled="False"></asp:TextBox>
</TD>
</TR>
<TR vAlign="top">
<TD height="22"></TD>
<TD colSpan="3">
<asp:Label id="lblCountry" runat="server" Height="22px" Width="150px">Country:</asp:Label>
</TD>
</TR>
<TR vAlign="top">
<TD colSpan="5" height="3"></TD>
<TD colSpan="2" rowSpan="2">
<asp:TextBox id="txtCountryCode" runat="server" Height="22px" Width="150px" Enabled="False"></asp:TextBox>
</TD>
<TD rowSpan="2"></TD>
</TR>
<TR vAlign="top">
<TD height="22"></TD>
<TD colSpan="3">
<asp:Label id="lblCountryCode" runat="server" Height="22px" Width="150px">Country code:</asp:Label>
</TD>
<TD>
</TD>
</TR>
<TR vAlign="top">
<TD colSpan="5" height="3"></TD>
<TD colSpan="3" rowSpan="2">
<asp:TextBox id="txtResults" runat="server" Height="22px" Width="500px" Enabled="False"></asp:TextBox>
</TD>
</TR>
<TR vAlign="top">
<TD colSpan="2" height="23">
</TD>
<TD colSpan="2">
<asp:Label id="lblResult" runat="server" Height="22px" Width="150px">Result:</asp:Label>
</TD>
<TD>
</TD>
</TR>
</TABLE>
</form>
</TD>
</TR>
</TABLE>
</body>
</HTML>
There are many working samples included with the product.
You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/asocket.
NOTE: Demo Projects are created with Microsoft Visual Studio 2002
The ActiveSocket project ships with a set of Microsoft Visual Studio .NET samples, including samples for Microsoft ASP .NET (Visual Basic).
The projects are created with Microsoft Visual Studio 2002.
Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.
The ActiveSocket tool is a Network Communications ActiveX software component (SDK).
This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform,
including Visual Basic .NET, Visual CSharp .NET,
ASP .NET (VB,CS),
ASP,
Visual Basic,
Visual Studio/Visual C++,
Delphi,
PHP,
ColdFusion,
HTML,
VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.
|