TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Find IP to Country
Hemlata Kushwaha
Aug 07
2015
Code
968
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
void
Application_Start(
object
sender, EventArgs e)
{
// Code that runs on application startup
Application[
"GeoipDbPath"
] = HttpContext.Current.Server.MapPath(
"~/GeoIPDB/"
) +
"GeoIP.dat"
;
}
// Code that runs when a new session is started
string
ip =
"50.156.11.8"
;
//string ip = "202.57.6.130";
//string ip = "122.160.59.94";
//string ip = Request.UserHostAddress.ToString();
//Session["geoprice"] = "price_usd";
Session[
"geopriceicon"
] =
"$"
;
//open the database
LookupService ls =
new
LookupService(Application[
"GeoipDbPath"
].ToString());
Country c = ls.getCountryV6(ip);
Session[
"country"
] = c.getName();
if
(Convert.ToString(c.getCode()) ==
"IN"
|| Convert.ToString(c.getCode()) ==
"PK"
|| Convert.ToString(c.getCode()) ==
"BD"
|| Convert.ToString(c.getCode()) ==
"BT"
|| Convert.ToString(c.getCode()) ==
"NP"
|| Convert.ToString(c.getCode()) ==
"LK"
)
{
//Session["geoprice"] = "price";
Session[
"geopriceicon"
] =
"<i class='fa fa-inr'></i>"
;
}
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"Default.aspx.cs"
Inherits=
"_Default"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
<link rel=
"stylesheet"
href=
"//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"
>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<asp:Label ID=
"lblprice"
runat=
"server"
></asp:Label>
</div>
</form>
</body>
</html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
getsessiongeoprice();
}
}
private
void
getsessiongeoprice()
{
if
(Session[
"geopriceicon"
] !=
null
)
{
lblprice.Text =
"Country Name : "
+ Session[
"country"
] +
"<br/> Price : "
+ Session[
"geopriceicon"
] +
"40"
;
}
}
}
IP based country
IP Location Finder
IP to Country