Get Started With IP2Proxy HTTP Module

Dependencies

This module requires IP2Proxy BIN database to function. You may download the BIN database at


Requirements

  1. Visual Studio 2010 or later.

  2. Microsoft .NET 3.5 framework.

  3. IntX.

  4. Microsoft ILMerge.

Supported Microsoft IIS Versions: 7.0, 7.5, 8.0, 8.5, 10.0 (website needs to be running under a .NET 2.0 application pool in integrated mode)


Compilation

Just open the solution file in Visual Studio and compile. Or just use the IP2ProxyHTTPModule.dll in the dll folder.

Note

After compilation, the final IP2ProxyHTTPModule.dll will be in the merged folder as the post-build event will merge the IntXLib.dll with the original IP2ProxyHTTPModule.dll to make it easier for deployment.


Installation

You can choose to install the IP2Proxy HTTP Module in either per website mode or per server mode.

Note

In per-website mode, you must install and configure IP2Proxy for each site individually.
In per-server mode, a single installation covers all websites on the server.

Per website mode

  1. Copy the IP2ProxyHTTPModule.dll, IP2Proxy-config.xml and the BIN data file to the bin folder of your website.

  2. Modify your web.config as below:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true">
                <add name="IP2ProxyModule" type="IP2Proxy.HTTPModule" />
            </modules>
        </system.webServer>
    </configuration>
    
  3. Open the IP2Proxy-config.xml in your bin folder using any text editor. Fill in the tag with the path to your BIN data file and remove the HTTP_X_FORWARDED_FOR if your website is not behind a proxy. Save your changes.

    <?xml version="1.0" encoding="utf-8"?>
    <IP2Proxy_Configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Settings>
        <BIN_File>bin\your_database_file.BIN</BIN_File>
        <Custom_IP_Server_Variable>HTTP_X_FORWARDED_FOR</Custom_IP_Server_Variable>
      </Settings>
    </IP2Proxy_Configuration>
    

Per server mode

  1. Create a new folder.

  2. Copy the IP2ProxyHTTPModule.dll, IP2Proxy-config.xml and the BIN data file to that folder.

  3. Create a Windows environment system variable to store the path of the new folder.

    1. Open the Control Panel then double-click on System then click on Advanced System Settings.

    2. Click on the Environment Variables button to open up the Environment Variable settings.

    3. Under System variables, create a new variable called IP2ProxyHTTPModuleConfig and set the value to the full path of the new folder.

  4. Create a PowerShell script called installgac.ps1 and paste the following code into it.

    Set-location "C:\<new folder>"
    [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
    $publish = New-Object System.EnterpriseServices.Internal.Publish
    $publish.GacInstall("C:\<new folder>\IP2ProxyHTTPModule.dll")
    iisreset
    
  5. Create a PowerShell script called uninstallgac.ps1 and paste the following code into it.

    Set-location "C:\<new folder>"
    [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
    $publish = New-Object System.EnterpriseServices.Internal.Publish
    $publish.GacRemove("C:\<new folder>\IP2ProxyHTTPModule.dll")
    iisreset
    
  6. In both scripts, edit the 2 lines containing the path to the full path for your new folder then save the scripts.

  7. Run installgac.ps1 to install the dll into the GAC. Keep the uninstallgac.ps1 in case you need to uninstall the dll.

  8. Installing the module in IIS.

    1. Open the IIS Manager then navigate to the server level settings and double-click on the Modules icon.
    2. In the Modules settings, click on the Add Managed Module at the right-hand side.
    3. Key in IP2ProxyHTTPModule for the Name and select IP2Proxy.HTTPModule as the Type.
    4. Click OK then restart IIS to complete the installation.
  9. Open the IP2Proxy-config.xml in your new folder using any text editor. Fill in the tag with the absolute path to your BIN data file and remove the HTTP_X_FORWARDED_FOR if your website is not behind a proxy. Save your changes.

    <?xml version="1.0" encoding="utf-8"?>
    <IP2Proxy_Configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Settings>
        <BIN_File>C:\<new folder>\your_database_file.BIN</BIN_File>
        <Custom_IP_Server_Variable>HTTP_X_FORWARDED_FOR</Custom_IP_Server_Variable>
      </Settings>
    </IP2Proxy_Configuration>
    

Sample Codes

Query geolocation information

You can query the geolocation information by using codes below:

Private Sub ShowServerVariable()
    Response.Write(Request.ServerVariables("REMOTE_ADDR") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_IS_PROXY") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_PROXY_TYPE") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_COUNTRY_SHORT") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_COUNTRY_LONG") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_REGION") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_CITY") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_ISP") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_DOMAIN") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_USAGE_TYPE") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_ASN") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_AS") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_LAST_SEEN") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_THREAT") & "<br>")
    Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_PROVIDER") & "<br>")
End Sub
private void ShowServerVariable()
{
   Response.Write(Request.ServerVariables["REMOTE_ADDR"] + "\n");
   Response.Write(Request.ServerVariables["HTTP_X_IP2PROXY_IS_PROXY"] + "\n");
   Response.Write(Request.ServerVariables["HTTP_X_IP2PROXY_PROXY_TYPE"] + "\n");
   Response.Write(Request.ServerVariables["HTTP_X_IP2PROXY_COUNTRY_SHORT"] + "\n");
   Response.Write(Request.ServerVariables["HTTP_X_IP2PROXY_COUNTRY_LONG"] + "\n");
   Response.Write(Request.ServerVariables["HTTP_X_IP2PROXY_REGION"] + "\n");
   Response.Write(Request.ServerVariables["HTTP_X_IP2PROXY_CITY"] + "\n");
   Response.Write(Request.ServerVariables["HTTP_X_IP2PROXY_ISP"] + "\n");
   Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_DOMAIN") + "\n");
   Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_USAGE_TYPE") + "\n");
   Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_ASN") + "\n");
   Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_AS") + "\n");
   Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_LAST_SEEN") + "\n");
   Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_THREAT") + "\n");
   Response.Write(Request.ServerVariables("HTTP_X_IP2PROXY_PROVIDER") + "\n");
}}
 <%=Request.ServerVariables("REMOTE_ADDR") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_IS_PROXY") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_PROXY_TYPE") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_COUNTRY_SHORT") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_COUNTRY_LONG") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_REGION") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_CITY") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_ISP") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_DOMAIN") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_USAGE_TYPE") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_ASN") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_AS") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_LAST_SEEN") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_THREAT") & "<br>"%>
    <%=Request.ServerVariables("HTTP_X_IP2PROXY_PROVIDER") & "<br>"%>
<?php
    echo $_SERVER['REMOTE_ADDR'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_IS_PROXY'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_PROXY_TYPE'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_COUNTRY_SHORT'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_COUNTRY_LONG'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_REGION'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_CITY'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_ISP'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_DOMAIN'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_USAGE_TYPE'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_ASN'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_AS'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_LAST_SEEN'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_THREAT'] . "<br>";
    echo $_SERVER['HTTP_X_IP2PROXY_PROVIDER'] . "<br>";
?>

IP2Proxy Sample Database (BIN)

Sample Packages - BIN File IPv4 + IPv6
IP2Proxy PX1 Download (391.66 kB)
IP2Proxy PX2 Download (406.53 kB)
IP2Proxy PX3 Download (435.82 kB)
IP2Proxy PX4 Download (471.49 kB)
IP2Proxy PX5 Download (491.37 kB)
IP2Proxy PX6 Download (493.92 kB)
IP2Proxy PX7 Download (534.57 kB)
IP2Proxy PX8 Download (540.70 kB)
IP2Proxy PX9 Download (541.56 kB)
IP2Proxy PX10 Download (677.91 kB)
IP2Proxy PX11 Download (684.40 kB)
IP2Proxy PX12 Download (687.12 kB)

Articles & Tutorials