note 39573 deleted from function.preg-match by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 22:53:09 +0000 |
| Subject: | note 39573 deleted from function.preg-match by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137364@lists.php.net to get a copy of this message | ||
Note Submitter: mark at portinc dot net
----
<?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!
}
?>