PHP code newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hooptiempls
Forum Newbie
Posts: 2
Joined: Mon Feb 25, 2013 3:47 pm

PHP code newbie

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP code newbie

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP code newbie

Post by Christopher »

Take a look at the ip2long() and long2ip() functions. They will make it easier to check ranges.
(#10850)
hooptiempls
Forum Newbie
Posts: 2
Joined: Mon Feb 25, 2013 3:47 pm

Re: PHP code newbie

Post by hooptiempls »

Thanks guys, I will look into your suggestions

Alex
Post Reply