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 Mar 29, 2024 5:17 am

All times are UTC + 10 hours




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
PostPosted: Sat Feb 14, 2009 6:35 am 
Offline
Newbie

Joined: Wed Sep 05, 2007 1:20 am
Posts: 23
openaudit for some reason lists IP's with a leading zero. Whatever the reason for this, it doesn't help in any way.

Example:

192.168.143.048

Should be:

192.168.143.48

I often copy paste the lists to use with psexec, I then have to additionally reformat the IP address (sed s/"\.0"/"."/g). At least when used with psexec, .048 is not the same as .48.


Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 26, 2009 6:24 pm 
Offline
Newbie

Joined: Wed Mar 25, 2009 6:55 pm
Posts: 12
i agree. It would also be easier to read. Possibly it could become an option?


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 29, 2009 1:41 pm 
Offline
Newbie

Joined: Sun Mar 05, 2006 8:45 am
Posts: 14
there is probably a better way to do this or maybe add some recursion, but it's late and i'm tired:

[code]
function format_ip($myip) {
$newip1 = preg_replace('/\.0/', '.', $myip); //first pass
$newip2 = preg_replace('/\.0/', '.', $newip1); //second pass
if (ord($newip2) == 48) { //48 = ascii value for 0
$newip = ltrim ($newip2, "0");
}
if (ord($newip) == 48) { //48 = ascii value for 0
$newip = ltrim ($newip, "0");
}
return $newip;
}
[/code]


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 30, 2009 12:19 am 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
Strictly speaking we should store all IP addresses and subnet mask in the same format, and if I am being particularly pedantic they should be stored as ling int, 'cos that is what they are (4 bytes) (http://en.wikipedia.org/wiki/Long_int) this would require a little bit of a re-write, but would also cut down on the size of the database.

Perhaps this should be a consideration for OAv2 (whatever that might be :twisted: )

_________________
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: Mon Mar 30, 2009 3:34 am 
As you say both subnet and ip address should be in the same format. Both PHP and MYSQL provide functions for converting between IP address strings and integers, but storing them as strings makes it more readable when looking at the tables themselves. The device location add on I wrote stores them as varchar(20), although 15 would be enough, and then uses the MYSQL funtions to manipulate them.


Top
  
Reply with quote  
PostPosted: Mon Mar 30, 2009 3:53 am 
Offline
Newbie

Joined: Sun Mar 05, 2006 8:45 am
Posts: 14
i tried using the php ip2long with an IP with leading zeros. Then converted it back using long2ip and it gave me a different IP. (ie: 010.002.002.102). that is why i ended up making that convoluted function. But then I went into the audit.vbs script and commented out the sections where it adds the leading zero's. Now the IP is stored properly. I prefer that method. I realize the zero's were added to make sorting work better, but I find IPs with leading zeros very difficult to read and I have to reformat it for display anyway - which breaks sorting too.

here are my changes to the VBS- starting at line 788:
[code]
' IP Address are padded with zeros so they sort properly
'MyIP = Split(net_ip(0), ".", -1, 1)
'if MyIP(0) <> "169" AND MyIP(1) <> "254" then
' MyIP(0) = right("000" & MyIP(0),3)
' MyIP(1) = right("000" & MyIP(1),3)
' MyIP(2) = right("000" & MyIP(2),3)
' MyIP(3) = right("000" & MyIP(3),3)
' net_ip(0) = MyIP(0) & "." & MyIP(1) & "." & MyIP(2) & "." & MyIP(3)
' The first detected IP address / Subnet mask become the system IP/Mask
if (net_ip(0) <> "0.0.0.0" and net_ip_address = "") then
net_ip_address = net_ip(0)
net_ip_mask = net_ip_subnet(0)
elseif net_ip(0) = "0.0.0.0" then net_ip(0) = "none" end if
'WCS - changed 000s to just 0
'end if
' MyIP = Split(net_ip(1), ".", -1, 1)
' if MyIP(0) <> "169" AND MyIP(1) <> "254" then
' MyIP(0) = right("000" & MyIP(0),3)
' MyIP(1) = right("000" & MyIP(1),3)
' MyIP(2) = right("000" & MyIP(2),3)
' MyIP(3) = right("000" & MyIP(3),3)
' net_ip(1) = MyIP(0) & "." & MyIP(1) & "." & MyIP(2) & "." & MyIP(3)
if net_ip(1) = "0.0.0.0" then net_ip(1) = "none" end if
'WCS - changed 000s to just 0
' end if
' MyIP = Split(net_ip(2), ".", -1, 1)
' if MyIP(0) <> "169" AND MyIP(1) <> "254" then
' MyIP(0) = right("000" & MyIP(0),3)
' MyIP(1) = right("000" & MyIP(1),3)
' MyIP(2) = right("000" & MyIP(2),3)
' MyIP(3) = right("000" & MyIP(3),3)
' net_ip(2) = MyIP(0) & "." & MyIP(1) & "." & MyIP(2) & "." & MyIP(3)
if net_ip(2) = "0.0.0.0" then net_ip(2) = "none" end if
'WCS - changed 000s to just 0
' end if
[/code]


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 30, 2009 4:39 am 
I suspect the php function actually did the correct thing, according to
http://tools.ietf.org/id/draft-main-ipa ... rep-01.txt
the address should not have leading zeros, therefore it is an invalid format.
It looks like several implementations of IP treat any octet with leading zeros as an octal number, so at best the leading zero format is ambiguous, at worst wrong, although it probably depends whch specification you read.
Sorting is easy without leading zeros, MYSQL will do it for you with "ORDER BY inet_aton(<ip_address>)"


Top
  
Reply with quote  
PostPosted: Mon Mar 30, 2009 8:42 am 
Offline
Site Admin
User avatar

Joined: Mon Jun 07, 2004 11:48 am
Posts: 1964
Location: Brisbane, Australia
Just an FYI.
OAv2 will store all IPs in the database with leading zero's, and show without leading zero's.
Yes, this is mainly for sorting.
I have a couple of functions (from Open-AudIT) that I use for this - they are loaded and ready to go in CodeIgniter.
The only problem I now have is the javascript table sorting... Javascript sorts the columns fine, but does the sorting based on "non-leading" zero IPAddresses. So it doesn't come out in the order you would expect. Sigh, just another bridge to cross...

_________________
Support and Development hours available from [url=https://opmantek.com]Opmantek[/url].
Please consider a purchase to help make Open-AudIT better for everyone.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 30, 2009 10:11 am 
Offline
Newbie

Joined: Sun Mar 05, 2006 8:45 am
Posts: 14
are you writing OAv2 in CodeIgniter? I have been working on a new frontend for OA that integrates a few other things as well using CI. Maybe we should work together on this?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 30, 2009 1:48 pm 
Offline
Site Admin
User avatar

Joined: Mon Jun 07, 2004 11:48 am
Posts: 1964
Location: Brisbane, Australia
Yep, OAv2 == CodeIgniter.
Am still bedding down the fundamentals, but nearly there.
What I'd give for a week off work to work on it !!!
I reackon I'd have an alhpa release if I had a week... sigh.
Will ask for help when the alpha is done - thanks in advance.

_________________
Support and Development hours available from [url=https://opmantek.com]Opmantek[/url].
Please consider a purchase to help make Open-AudIT better for everyone.


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.  [ 10 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:  
Powered by phpBB® Forum Software © phpBB Group