Page 1 of 1

PHP code newbie

Posted: Wed Feb 27, 2013 10:24 am
by hooptiempls
HI all
I am trying to figure out how to modify an existing script I have to enter in multiple numbers.
I currently have a page that I can enter a spammers IP address, My address as the submitter, attack notes field, selection for blacklist or whitelist, and date added.
Here is my code

Code: Select all

<?php 
echo "attacknotes:".$_POST['attacknotes']."<br>";
echo "b_or_w:".$_POST['b_or_w']."<br>";

$con = mysql_connect("localhost","user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("rbldns", $con);

$dateadd = date("Y-m-d H:i:s");
$dateupdated = date("Y-m-d H:i:s");

$sql="INSERT INTO ips (ipaddress, reportedby, attacknotes, b_or_w, dateadded, updated)
VALUES
('$_POST[ipaddress]','$_POST[reportedby]','$_POST[attacknotes]','$_POST[b_or_w]','$dateadd','$dateadd')";

echo $sql;
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);
?>
What I need to do is in the ipaddress field is instead of submitting just 1 singular ip, I would like to add a whole c class to insert into the database.
So say some spammer is connecting via 192.168.1.6 30 minutes later he will usually send out a message from 192.168.1.78 and another hour later change his ip yet again to another one within his subnet.
So I need to figure out what I need to do to do either an auto increment adding type code to enter say 192.168.1.* to enter all 254 addresses.
The database field is currently set to 15 char to accommodate a normal looking ip address.

If I am posting this in the wrong section I am truly sorry

Thanks for any suggestions

Alex

Re: PHP code newbie

Posted: Wed Feb 27, 2013 12:43 pm
by requinix
hooptiempls wrote:So I need to figure out what I need to do to do either an auto increment adding type code to enter say 192.168.1.* to enter all 254 addresses.
It would be much better to change the system to support IP ranges and/or CIDR notation. That could be as easy as adding a second column and entering starting and ending IP addresses, then checking for whether a match is between them.

Re: PHP code newbie

Posted: Wed Feb 27, 2013 9:59 pm
by Christopher
Take a look at the ip2long() and long2ip() functions. They will make it easier to check ranges.

Re: PHP code newbie

Posted: Sun Mar 03, 2013 11:29 pm
by hooptiempls
Thanks guys, I will look into your suggestions

Alex