note 39573 added to function.preg-match
| From: | mark at portinc dot net | Date: | Mon, 02 Feb 2004 23:30:33 +0000 |
| Subject: | note 39573 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64570@lists.php.net to get a copy of this message | ||
<?php // some may find this usefull... :)
$iptables = file ('/proc/net/ip_conntrack');
$services = file ('/etc/services');
$GREP = '!([a-z]+) ' .// [1] protocol
'\\s*([^ ]+) ' .// [2] protocl in decimal
'([^ ]+) ' .// [3] time-to-live
'?([A-Z_]|[^ ]+)?'.// [4] state
' src=(.*?) ' .// [5] source address
'dst=(.*?) ' .// [6] destination address
'sport=(\\d{1,5}) '.// [7] source port
'dport=(\\d{1,5}) '.// [8] destination port
'src=(.*?) ' .// [9] reversed source
'dst=(.*?) ' .//[10] reversed destination
'sport=(\\d{1,5}) './/[11] reversed source port
'dport=(\\d{1,5}) './/[12] reversed destination port
'\\[([^]]+)\\] ' .//[13] status
'use=([0-9]+)!'; //[14] use
$ports = array();
foreach($services as $s) {
if (preg_match ("/^([a-zA-Z-]+)\\s*([0-9]{1,5})\\//",$s,$x)) {
$ports[ $x[2] ] = $x[1];
} }
for($i=0;$i <= count($iptables);$i++) {
if ( preg_match ($GREP, $iptables[$i], $x) ) {
// translate known ports... . .
$x[7] =(array_key_exists($x[7],$ports))?$ports[$x[7]]:$x[7];
$x[8] =(array_key_exists($x[8],$ports))?$ports[$x[8]]:$x[8];
print_r($x);
} // on a nice sortable-table... bon appetite!
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39573
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39573&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39573&report=yes
Search -- http://master.php.net/manage/user-notes.php