Open-AudIT

What's on your network?
It is currently Wed Jan 24, 2018 7:29 pm

All times are UTC + 10 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu May 06, 2010 8:49 pm 
Offline
Site Admin
User avatar

Joined: Mon Jun 07, 2004 11:48 am
Posts: 1935
Location: Brisbane, Australia
I have replaced all the ereg functions with preg_match functions - except the one below. Can anyone that's a regex guru work this out for me ?

Code:
   if (! preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}(( ([0-9]{1,3}\.){3}[0-9]{1,3})|(/[0-9]{1,2}))$/',$my_net_info))
   {
      $details->error = "Error - invalid input";
      return($details);
   }


$mynetinfo should be an IP Address and subnet, seperated by a space. Like
$mynetinfo = "192.168.0.1 255.255.255.0";

FYI - it should also valide against IP & CIDR Netmask: 10.0.0.1/22 and IP & Wildcard Mask: 10.0.0.1 0.0.3.255 type addresses.


When I keep this code in, I get a PHP error such

Code:
A PHP Error was encountered
Severity: Warning
Message: preg_match() [function.preg-match]: Unknown modifier '['
Filename: helpers/network_helper.php
Line Number: 37


With line number 37 being the if (! preg_match('/^([....... line.

Any help much appreciated.
I think this is the last stumbling block to getting OAv2 working on PHP5.3.
I could simply comment out this function and it should still work fine. We should only be inputting valid IP Addresses anyway - but that's not the point.

BTW - the original code is here
http://moggert.net/subnetcalc.php.txt and also referenced here http://meta.wikimedia.org/wiki/User:Oblivious/SubnetCalc.

_________________
Support and Development hours available from Opmantek.
Please consider a purchase to help make Open-AudIT better for everyone.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 07, 2010 3:09 am 
Offline
Moderator

Joined: Fri Jul 20, 2007 8:27 am
Posts: 1229
My guess would be that you need to escape the "/" in the middle.
So
Code:
if (! preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}(( ([0-9]{1,3}\.){3}[0-9]{1,3})|(/[0-9]{1,2}))$/',$my_net_info))


becomes
Code:
if (! preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}(( ([0-9]{1,3}\.){3}[0-9]{1,3})|(\/[0-9]{1,2}))$/',$my_net_info))


Top
 Profile  
Reply with quote  
PostPosted: Mon May 24, 2010 3:08 am 
Offline
Newbie

Joined: Thu Feb 11, 2010 2:41 am
Posts: 19
Mark,

You said you wanted to match
    192.168.0.1 255.255.255.0
    10.0.0.1 0.0.3.255
    10.0.0.1/22

Here is what I've come up with
Code:
/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b\W\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b|\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b\W[0-9]{2}\b/

Here is a screen shot of it matching
http://gyazo.com/07909bb45772713fe2c843c3fe90b7c9.png


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 10 hours


Who is online

Users browsing this forum: No registered users and 4 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