comparison doc/ucis.ano/bgp_graph/bgp_path_list_xml.php @ 28:4dbe5bf653bb draft

Added bgp graph scripts
author ivo <ivo@UFO-Net.nl>
date Thu, 10 Jun 2010 00:15:51 +0200
parents
children 77b07c336f91
comparison
equal deleted inserted replaced
27:26b849b22eaa 28:4dbe5bf653bb
1 #!/usr/bin/php
2 <?php
3 $mynode = 0;
4
5 $file = STDIN;
6 $paths = array();
7
8 while (!feof($file)) {
9 if (seekto($file, '<as-path>') === FALSE) break;
10 seekto($file, '<segment');
11 seekto($file, '>');
12 $endofsection = FALSE;
13 $path = $mynode;
14 while (!feof($file)) {
15 if (seekto($file, '<') === FALSE) break;
16 switch (fread($file, 4)) {
17 case 'asn>': break;
18 case '/seg': $endofsection = TRUE; break;
19 default: die('unknown tag at '.(ftell($file)-4));
20 }
21 if ($endofsection) break;
22 $asn = seekto($file, '</asn>');
23 $path .= ' '.$asn;
24 }
25 if (in_array($path, $paths)) continue;
26 $paths[] = $path;
27 print($path."\n");
28 }
29
30 function seekto($f, $str) {
31 $part = '';
32 $i = 0;
33 $len = strlen($str);
34 while ($i < $len && !feof($f)) {
35 $c = fgetc($f);
36 if ($c === FALSE) return FALSE;
37 if ($c == $str[$i]) {
38 $i++;
39 } else {
40 if ($i) {
41 $i = 0;
42 $part = '';
43 }
44 $part .= $c;
45 }
46 }
47 return $part;
48 }