Total members 11889 |It is currently Fri Mar 29, 2024 5:54 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Hi, you may lookup IP address in bulk using C-Sharp programming languages and IP2Location MySQL database. In this snippet, we use the IP2Location LITE database to lookup country of origin from the visitor's IP address. Free databases are available for download at IP2Location LITE database.


Code:
/// <summary>
/// IP Address (ipv6) Lookup in Bulk Using C# and MySQL Database
/// Free geolocation database can be downloaded at:
/// http://lite.ip2location.com/
/// </summary>

void DisplayFileContents(HttpPostedFile file)
   {
       Stream theStream = FileUpload1.PostedFile.InputStream;
       StringBuilder display = new StringBuilder();
       using (StreamReader sr = new StreamReader(theStream))
       {
           string line;
           char[] delimiter1 = new char[] { ',' };

           while ((line = sr.ReadLine()) != null)
           {
               string[] iplist = line.Split(delimiter1, StringSplitOptions.None);

               foreach (string IP in iplist)
               {
                   display.Append("IP Address : " + IP.ToString() + "\n");

                   string ip_addr = IP;

                   System.Numerics.BigInteger ip_num = ip_to_number(ip_addr);
                   String ip_no = ip_num.ToString();
                   string query = "SELECT country_code, country_name , city_name , region_name, latitude,longitude,zip_code,time_zone FROM ip2location_db11 WHERE ip_to >= " + ip_no + " order by ip_to limit 1";
                   string[] data = Get_Data(query);

                   string country_code = data[0];
                   string country_name = data[1];
                   string city_name = data[2];
                   string region_name = data[3];
                   string latitude = data[4];
                   string longitude = data[5];
                   string zip_code = data[6];
                   string time_zone = data[7];

                   //Define the result file that you want to output
                   string filePath = Server.MapPath("~") + "result.csv";

                   using (StreamWriter Sw = File.AppendText(filePath))
                   {
                       string output = string.Format("\"" + IP + "\"" + "," + "\"" + country_code + "\"" + "," + "\"" + country_name + "\"" + "," + "\"" + city_name + "\"" + "," + "\"" + region_name + "\"" + "," + "\"" + latitude + "\"" + "," + "\"" + longitude + "\"" + "," + "\"" + zip_code + "\"" + "," + "\"" + time_zone + "\"");

                       Console.WriteLine(output);
                       Sw.WriteLine(output);

                   }
                   Label3.Text = "Result File Path : " + Path.GetFullPath(filePath) + "<br>";
               }
           }
       }

       Label4.Text = "Please DELETE the result file if you want to upload a new file! <br>";

   }





Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : IP Address Lookup in Bulk Using C-Sharp and MySQL Database
 dump Mysql database     -  
 import Mysql database     -  
 Creating a Database in MySQL     -  
 Optimize All Tables In A MySQL Database     -  
 what is MAC address     -  
 Find MAC Address     -  
 Get Server address     -  
 change the MAC address     -  
 Get IP address code     -  
 log visitor IP address.     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com