Frage

I have following table in my MySQL databse :

CREATE  TABLE IF NOT EXISTS `virt100706_wie`.`banned_ips` (
  `idbanned_ips` INT NOT NULL AUTO_INCREMENT ,
  `ip` TEXT NOT NULL ,
  `date` DATE NOT NULL ,
  `reason` TEXT NULL ,
  PRIMARY KEY (`idbanned_ips`) )
ENGINE = InnoDB

I wanna to add to it the list of IPs, which are sending spams, belong to hackers, botnets, etc. etc. and permanently block access for it to my website.

I have found a good list here, but it is published in CSV format and I need that in SQL format (INSERT statements).

My question is : Is there any list of spam IPs publihsed in SQL format ? or Is there any tool to convert CSV to SQL INSERT format ?

Thanks in advance !

War es hilfreich?

Lösung 2

I have to do this sort of thing sometimes. It's right on the borderline of being a task worth writing a script for. Usually I don't write a script - I'll use an emacs keyboard macro, but if your editor doesn't support keyboard macros, here's another way:

  • Open the CSV in a spreadsheet program
  • Write a formula column that substitutes in the values in the correct places (this assumes IP addresses are in column A)

    ="INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ('" & A1 & "',NOW());"

  • fill down the formula

Then copy and paste the result into the editor and save as a .sql file.

Andere Tipps

You can create SQL INSERT statements yourself from downloaded csv file. Pipe your file through proper 'awk' command and write the output to a file - see below. Than use the file as your SQL INSERT feed.

This command will create SQL you need:

$ tail -n+2 spam-ip.com_10-28-2013.csv | awk 'BEGIN { FS = ", " } ; {print "INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES (\"" $2 "\",now());"}' > spam-ip.com_10-28-2013.sql

Example pipe output:

$ tail spam-ip.com_10-28-2013.sql
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("61.191.191.154",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("95.79.195.2",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("194.8.75.54",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("218.247.161.37",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("94.75.193.168",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("94.142.128.220",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("212.157.248.198",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("99.228.96.58",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("92.112.40.145",now());
INSERT INTO virt100706_wie.banned_ips (ip,date) VALUES ("118.35.46.144",now());
$

Than something like:

$ mysql -u XXX -p virt100706_wie < spam-ip.com_10-28-2013.sql
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top