In This post I am going to explain
about locating the IP Address using ASP.NET with C# programming i.e; If we know
the IP address of the system then locating the system where this IP belongs. To
do this first we need to download the 3rd party IP Adress Extension
DLL.
Please download IP Address extension dll from http://ipaddressextensions.codeplex.com/
After Downloading then create a new project and add the downloaded dll in to our solution.e; Right click on references and add the dll.
Please download IP Address extension dll from http://ipaddressextensions.codeplex.com/
After Downloading then create a new project and add the downloaded dll in to our solution.e; Right click on references and add the dll.
Then add the New Aspx page with the
following code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
IP
Address :
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1"
runat="server"
onclick="Button1_Click"
style="height: 26px" Text="Locate"
/>
</div>
</form>
</body>
</html>
After creating Aspx page then code
behind and add the following namespaces.
using System.Net;
using WorldDomination.Net;
Then add the following code in the
code behind file
protected void Page_Load(object sender, EventArgs
e)
{
}
protected void
Button1_Click(object sender, EventArgs e)
{
string userHostIpAddress = TextBox1.Text;
IPAddress ipAddress;
if (IPAddress.TryParse(userHostIpAddress,
out ipAddress))
{
string country = ipAddress.Country();//To Get Country of Ip Adress
string iso3166TwoLetterCode =
ipAddress.Iso3166TwoLetterCode();//To Get ISO Two
Letter Code of Ip Adress
string iso3166ThreeLetterCode= ipAddress.Iso3166ThreeLetterCode();//To Get ISO Three Letter Code of Ip Adress
string registry = ipAddress.Registry();//To Get registry of Ip Adress
Response.Write("Country : " + country + "<br/>" + "ISO
Two Letter Code : " +
iso3166TwoLetterCode + "<br/>"
+ "ISO Three Letter Code :" + iso3166ThreeLetterCode + "<br/>" + "registry :" + registry);
}
}
No comments:
Post a Comment