Fri Jan 30, 2015 9:44 am
/// <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>";
}
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
Powered by phpBB © phpBB Group.