Find IP to Country

  1. void Application_Start(object sender, EventArgs e)   
  2. {  
  3.         // Code that runs on application startup  
  4.         Application["GeoipDbPath"] = HttpContext.Current.Server.MapPath("~/GeoIPDB/") + "GeoIP.dat";  
  5. }  
  1. // Code that runs when a new session is started  
  2.         string ip = "50.156.11.8";  
  3.         //string ip = "202.57.6.130";  
  4.         //string ip = "122.160.59.94";  
  5.   
  6.         //string ip = Request.UserHostAddress.ToString();  
  7.         //Session["geoprice"] = "price_usd";  
  8.         Session["geopriceicon"] = "$";  
  9.         //open the database  
  10.         LookupService ls = new LookupService(Application["GeoipDbPath"].ToString());  
  11.         Country c = ls.getCountryV6(ip);  
  12.           
  13.         Session["country"] = c.getName();  
  14.           
  15.         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")  
  16.         {  
  17.             //Session["geoprice"] = "price";  
  18.             Session["geopriceicon"] = "<i class='fa fa-inr'></i>";  
  19.         }  
    1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4.   
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head runat="server">  
    7.     <title></title>  
    8. <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">  
    9. </head>  
    10. <body>  
    11.     <form id="form1" runat="server">  
    12.     <div>  
    13.     <asp:Label ID="lblprice" runat="server"></asp:Label>  
    14.     </div>  
    15.     </form>  
    16. </body>  
    17. </html>  
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Web;  
    5. using System.Web.UI;  
    6. using System.Web.UI.WebControls;  
    7.   
    8. public partial class _Default : System.Web.UI.Page  
    9. {  
    10.     protected void Page_Load(object sender, EventArgs e)  
    11.     {  
    12.         if (!IsPostBack)  
    13.         {  
    14.             getsessiongeoprice();  
    15.         }  
    16.     }  
    17.     private void getsessiongeoprice()  
    18.     {  
    19.         if (Session["geopriceicon"] != null)  
    20.         {  
    21.             lblprice.Text = "Country Name : " + Session["country"] + "<br/> Price : " + Session["geopriceicon"] + "40";  
    22.         }  
    23.     }  
    24. }