Archive for the ‘MSSQL’ Category

31
May

Free, large scale GEO IP mapping.

   Posted by: admin

There is a site that has an open source database of IP ranges to geographic info called hostip.info. They alow you to download the database in several different formats. I chose MySQL. However, I don’t care much for the way that they structured the database because it’s divided into 255 tables that each represent the first octet of an IP. So I moved them all into a single table.

Here is some PHP code to generate the SQL script for combining all of the tables and dropping the old ones. I will also included the resulting file.

<?php
for ($i = 0; $i <= 255; $i++)
{
  $query = "Insert into ip4_all(a,b,c,country,city,cron) Select ".$i.", b, c, country, city, cron From ip4_".$i.";";
  $HTMLOutput = $HTMLOutput . $query . "<br><br>";
}
for ($i = 0; $i <= 255; $i++)
{
  $query = "Drop Table ip4_".$i.";";
  $HTMLOutput = $HTMLOutput . $query . "<br><br>";
}
echo $HTMLOutput;
?>
 

There are also daily updates to the database which would need to be obtained using scripts and then converted into this new data structure.

Powered by ScribeFire.

13
Apr

Logparser: I know SQL and I have flat files.

   Posted by: admin

Microsoft has a tool that should be in every DBA’s toolbox. Even if you aren’t running MSSQL on a Windows server it’s very handy to run on your windows desktop to get info out of flat files very quickly.

This can be used as a great alternative to DTS because you can insert the records into the DB that you want instead of inserting all records and then filtering.

http://www.logparser.com/

This is a utility that allows you to run a SQL query against a directory of flat files in various formats as if they were in a database. Most of the functions you can think of which are in SQL and are not in many other command line tools for parseing flat files are availabel such as Distinct, group by, order by, count, max, min, avg, etc. There are 3 main parts to it: the input format, the query and the output format. There are many different input formats, I most commonly use IISLog directories as an input, and it automically knows how to recognize it. One awesome thing is that it keeps track of which files it’s been through so it can be setup to only process deltas.

The Queries use a limitied set of SQL syntax.

The outputs can display on the screen, another file, or direct into a database.

here’s an example of a logparser query that will give you a count of how many hits occured on a file in a specified timeframe from all of the IISLogs:
Logparser -i:IISW3C "Select count(*) from f:\IISlogs\*.log where cs-uri-stem like '%%PAGEYOUARELOOKINGFOR'and TO_TIME(time) BETWEEN TIMESTAMP('15:45:48', 'hh:mm:ss') AND TIMESTAMP('21:03:48', 'hh:mm:ss')"