Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use DBI;
- open(IN,"< ips2.txt") || die "Can not open file : $!";
- $db ="test";
- $user = "root";
- $pass = "";
- ## user hostname : This should be "localhost" but it can be diffrent too
- $host="localhost";
- $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
- #select name from countries where id = (select country from ip4_61 where b=143 && c=178)
- while(<IN>){
- @ipParts = split('[.]', $_);
- if($_ =~ /(\d+)(\.\d+){3}/)
- {
- $query = "select name from countries where id = (select country from ip4_".$ipParts[0]." where b=".$ipParts[1]." && c=".$ipParts[2].")";
- $sqlQuery = $dbh->prepare($query)
- or die "Can't prepare $query: $dbh->errstr\n";
- $rv = $sqlQuery->execute
- or die "can't execute the query: $sqlQuery->errstr";
- while (@row= $sqlQuery->fetchrow_array())
- {
- my $tables = $row[0];
- $_ =~ s/\n/ /g;
- print "$_- $tables\n";
- }
- $rc = $sqlQuery->finish;
- }
- }
- close IN;
- exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement