Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Julienl
- * @version 0.2
- * Insert ip and country in database
- */
- //Database information
- $hote='localhost';
- $port='3306';
- $db='database';
- $user='user';
- $password='password';
- //////////////////////
- $c = mysql_connect($hote, $user, $password) or die ("Impossible to connect : " . mysql_error());
- mysql_select_db($db) or die("Impossible to use database");
- function execQuery($query)
- {
- $result = mysql_query($query);
- if(!$result)
- {
- $message = mysql_error();
- die($message);
- }
- }
- if ($argc != 2)
- {
- echo "arguments are missing\n";
- exit(0);
- }
- $ip = $argv[1];
- $sql = "SELECT COUNT(*) FROM ip WHERE ip = '$ip';";
- $res = mysql_query($sql);
- $row = mysql_fetch_row($res);
- if($row[0] == 0)
- {
- $country = exec("whois ". $ip ." | grep country | awk -F \" \" '{print $2}\'");
- if(!isset($country))
- {
- $country = "Unknow";
- }
- $sql = "INSERT INTO ip (ip,country) VALUES ('$ip','$country');";
- execQuery($sql);
- }
- mysql_close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement