Registrations to Open-AudIT forums are now closed. To ask any new questions please visit Opmantek Community Questions.

Open-AudIT

What's on your network?
It is currently Fri Apr 19, 2024 5:18 pm

All times are UTC + 10 hours




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Search for IP address
PostPosted: Sat Oct 20, 2007 8:56 pm 
Offline
Open-AudIT Fellow

Joined: Thu May 17, 2007 5:47 pm
Posts: 568
Location: Italy
Search.php doesn't retrieve IP addresses from the "other" table (only from the "system" one).
Also, it retrieves IPs only if they are padded with '0' (010.099.003.123, instead of 10.99.3.123).
I fixed it with the following changes:
1. In the include_functions.php page, replace the function ip_trans_to($ip) with the following:
[code]
function ip_trans_to($ip)
{
if (($ip <> "") AND (!(is_null($ip)))){
$myip = explode(".",$ip);
$ip = substr("000" . $myip[0], -3);
if(isset($myip[1])){
$myip[1] = substr("000" . $myip[1], -3);
$ip = $ip . "." . $myip[1];}
if(isset($myip[2])){
$myip[2] = substr("000" . $myip[2], -3);
$ip = $ip . "." . $myip[2];}
if(isset($myip[3])){
$myip[3] = substr("000" . $myip[3], -3);
$ip = $ip . "." . $myip[3];}
} else {
$ip = " Not-Networked";
}
return $ip;
}
[/code]
2. In the search.php page, comment line 65
[code]
//$sql .= "net_ip_address LIKE '%$search%' OR ";
[/code]
comment line 87
[code]
//if (strpos(strtoupper($myrow["net_ip_address"]), $search) !== false){$search_field = "IP Address"; $search_result = $myrow["net_ip_address"];}
[/code]
add at line 199
[code]
// Search for IP address into "system" table

$search_padded = ip_trans_to($search);

$sql = "SELECT DISTINCT system_name, system_uuid, net_ip_address ";
$sql .= "FROM system WHERE ";
$sql .= "net_ip_address LIKE '%$search%' OR ";
$sql .= "net_ip_address LIKE '%$search_padded%'";

$result = mysql_query($sql, $db);
if ($myrow = mysql_fetch_array($result)){
do {
if (strpos(strtoupper($myrow["net_ip_address"]), $search) !== false)
{$search_field = "IP Address"; $search_result = $myrow["net_ip_address"];}
else
{if (strpos(strtoupper($myrow["net_ip_address"]), $search_padded) !== false)
{$search_field = "IP Address"; $search_result = ip_trans($myrow["net_ip_address"]);}
}
$bgcolor = change_row_color($bgcolor,$bg1,$bg2);
$result_set[] = array($myrow["system_name"], $myrow["system_uuid"], ip_trans($myrow["net_ip_address"]), $search_field, $search_result);
} while ($myrow = mysql_fetch_array($result));

} else {}

// Search for IP address into "other" table

$search_padded = ip_trans_to($search);

$sql = "SELECT DISTINCT other_network_name, other_id, other_ip_address ";
$sql .= "FROM other WHERE ";
$sql .= "other_ip_address LIKE '%$search%' OR ";
$sql .= "other_ip_address LIKE '%$search_padded%'";

$result = mysql_query($sql, $db);
if ($myrow = mysql_fetch_array($result)){
do {
if (strpos(strtoupper($myrow["other_ip_address"]), $search) !== false)
{$search_field = "Device IP Address"; $search_result = $myrow["other_ip_address"];}
else
{if (strpos(strtoupper($myrow["other_ip_address"]), $search_padded) !== false)
{$search_field = "Device IP Address"; $search_result = ip_trans($myrow["other_ip_address"]);}
}
$bgcolor = change_row_color($bgcolor,$bg1,$bg2);
$result_set[] = array($myrow["other_network_name"], $myrow["other_id"], ip_trans($myrow["other_ip_address"]), $search_field, $search_result);
} while ($myrow = mysql_fetch_array($result));

} else {}

[/code]

_________________
Edoardo


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 21, 2007 3:03 am 
I think it would be better to first change how IP addresses are stored in the db. The recommended way appears to be using an int(11) and storing it by calling [url=http://us2.php.net/ip2long]ip2long[/url]. This would allow easy sorting by ip without having to add padding. I didn't bother to check how they are stored currently, but I grep'd for ip2long and got nothing. Thoughts?


Top
  
Reply with quote  
PostPosted: Thu Oct 25, 2007 9:09 pm 
Offline
Open-AudIT Fellow

Joined: Thu May 17, 2007 5:47 pm
Posts: 568
Location: Italy
[quote="mikeyrb"]I think it would be better to first change how IP addresses are stored in the db. The recommended way appears to be using an int(11) and storing it by calling [url=http://us2.php.net/ip2long]ip2long[/url]. This would allow easy sorting by ip without having to add padding. I didn't bother to check how they are stored currently, but I grep'd for ip2long and got nothing. Thoughts?

I agree with you that queries for integers are faster than string compares, but is someone working on this? Until what you proposed is done, I think this fix could be added, if approved as valid. For me it's working fine: now I can search for IPs, padded or not, in both "system" and "other" tables. Thank you

_________________
Edoardo


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2007 10:40 pm 
Offline
Open-AudIT Fellow

Joined: Thu May 17, 2007 5:47 pm
Posts: 568
Location: Italy
Hi, did developers try if this fix is OK?

_________________
Edoardo


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2007 11:01 pm 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
Added at SVN 874. Thanks for that. 8)

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 31, 2007 5:50 pm 
Offline
Open-AudIT Fellow

Joined: Thu May 17, 2007 5:47 pm
Posts: 568
Location: Italy
Thank you very much, Andrew.

_________________
Edoardo


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC + 10 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group