Jump to content



  • Please log in to reply
2 replies to this topic

#1 akwirefree

  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationWasilla,AK

Posted 15 October 2006 - 03:54 AM

I've got a linux box logging (ulogd) firewall dropped packets to a mysql database for research. I'm writing a script to show the top 25 daily udp hits from ip addresses. For some reason, when I open this query in a web browser, all I get is a blank page.  I tried the sql query from the command line in mysql and it returned what I was looking for, but putting it in php is returning nothing. I have a similar script with the same connection details, and everything works fine. Any help would be greatly appreciated! Script is below:
//database name
$db_name = "ulogd";
//connection string
$connection = @mysql_connect("localhost", "****", "****")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
//starting time and ending time for query
$timea = "2006-09-30 00:00:01";  //temporary entry for testing
$timeb = "2006-09-30 23:59:59";  //temporary entry for testing
//$date1 = date("Y-m-d");  // Should give the format of yyyy-mm-dd, will be used for future dynamic use
//Actual MySQL query
$sql = "SELECT COUNT(inet_ntoa(ip_saddr)), inet_ntoa(ip_saddr), MID(raw_mac,19,17),
inet_ntoa(ip_daddr), udp_sport, udp_dport

FROM ulog

WHERE (pkt_time > '$timea' AND pkt_time < '$timeb')
GROUP BY inet_ntoa(ip_saddr)

ORDER BY COUNT(inet_ntoa(ip_saddr)) DESC LIMIT 25";
//Process the actual query
$result = mysql_query($sql, $connection) or die(mysql_error());
// Loop through the results returned from the query
while ($row = mysql_fetch_array($result))  {
$count = $row['count(inet_ntoa(ip_saddr))'];
$saddr = $row['inet_ntoa(ip_saddr)'];
$mac = $row['mid(raw_mac,19,17)'];
$daddr = $row['inet_ntoa(ip_daddr)'];
$sport = $row['udp_sport'];
$dport = $row['udp_dport'];
//Results that will be displayed in html table
$display_block .= "<td>$count</td>
<Title> Today's UDP Heavy Hitters</Title>
<? echo "<table><table border = \"1\" cellspacing = \"0\" cellpadding = \"0\" width = \"350\"><tbody align = \"center\" style = \"font-family:arial\"><tr>
<th>Msg Count</th>
<th>Source IP</th>
<th>Source MAC Address</th>
<th>Destination IP</th>
<th>UDP Source Port</th>
<th>UDP Destination Port</th></tr>"; ?>
<? echo "$display_block"; ?>
<? echo "</tbody></table>"; ?>

#2 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 15 October 2006 - 08:52 AM

first guess is to use <?php instead of <? down there at the bottom.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 akwirefree

  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationWasilla,AK

Posted 15 October 2006 - 06:55 PM

Got it! I learned two lessons from this:
1. While debugging and testing, error reporting turned to "on" in the php.ini file is a really,really, really good idea ( that was my blank page issue!  :o)
2. Use the appropriate editor. I was using gedit. Yes it's pretty and nice. But it'll also leave extra characters in the code (as found while reading file using vi! >:( ). After removing extra characters in vi, script ran fine.
Thanks again for the input. Has anyone used Bluefish from OpenOffice to write any php scripts? If so, how's it working out for you?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users