C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






IPAddress To Country Resolver


Posted Date:     Total Responses: 0    Posted By: ABitSmart   Member Level: Diamond   Points/Cash: 100   


There are situations where we have to track visitors. The tracking might include the country from the visitor has browsed the website. These statistics are often important.

This project provides a library to resolve the country name given an IP. The project uses the Codeplex IPExtensions projects. This project has embedded information of the various ip address ranges assigned to different countries.

The major advantage of this method is a single DLL. It does not require any database setup etc. You just need to add reference to the IpToCountryLib DLL provided in the solution.

To resolve the country name, the library API to be used is "GetCountry". GetCountry takes in a string parameter which is the IP Address and returns the country name as the out parameter.

This is the code of the function,
C#

public bool GetCountry(string userHostIpAddress, out string countryName)
{
bool result = false;
countryName = string.Empty;

if (string.IsNullOrEmpty(userHostIpAddress))
return false;

IPAddress ipAddress;
if (IPAddress.TryParse(userHostIpAddress, out ipAddress))
{
countryName = ipAddress.Country();

result = true;
}

return result;
}

VB,

Public Function GetCounTry(ByVal userHostIpAddress As String, ByRef counTryName As String) As Boolean
Dim result As Boolean = False
counTryName = String.Empty

If String.IsNullOrEmpty(userHostIpAddress) Then
Return False
End If

Dim ipAddress As IPAddress
If IPAddress.TryParse(userHostIpAddress,out ipAddress) Then
counTryName = ipAddress.CounTry()

result = True
End If

Return result
End Function


To use the function you will do a call like this,
C#,

IPToCountry _lib = new IPToCountry();
string country;
_lib.GetCountry("111.111.111.111",out country);

VB.Net,

Dim _lib As IPToCounTry = New IPToCounTry()
Dim counTry As String
_lib.GetCounTry("111.111.111.111",out counTry)


I have attached the source code and also an exe for the application. The application attached contains a WPF application using the library and demonstrating the feature.

Have fun.

Attachments

  • Source Code (663-262226-IPToCountry.rar)
  • Exe (663-262226-EXE.rar)

  • Project Feedbacks

    Author: AnilMember Level: BronzeRevenue Score: 1 out of 5
    HI

    nice project i need the dll sourse code


    Author: divyaMember Level: BronzeRevenue Score: 2 out of 52 out of 5
    really good work especially for security reasons. But can u provide me with the source code and the details about executing the project? Iam doing my final year engg .so pls help me


    Author: vinaysrivastavaMember Level: BronzeRevenue Score: 1 out of 5
    nice project for security.but i want to know more detail of the program.i am final year mca student


    Author: Kritika YadavMember Level: GoldRevenue Score: 1 out of 5
    hey really nice code. do you have any code to get domain from where we reached the current page.


    Author: Johney JosephMember Level: SilverRevenue Score: 2 out of 52 out of 5
    hi,
    very nice to post such a project. this's a most wanted snippet needed by many serious developers.


    Author: Neeraj Kumar SInghMember Level: SilverRevenue Score: 1 out of 5
    hi,
    nice project.
    how we run this project?
    how we use it in our application?




    Post Feedback
    You must Sign In to post a feedback.
    Next Project: Bug Tracking System
    Previous Project: Training And Placement

    Return to Project Index

    Post New Project


    Related Projects



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use