mirror of
https://github.com/manuelkasper/AS-Stats.git
synced 2025-02-20 11:44:12 +08:00
Add feature to inspect all ASes in an AS-SET (automatic whois lookup).
(contributed by Nicolas Debrigode) Updated asinfo.txt with data from whois.cymru.com.
This commit is contained in:
parent
ece9fbd841
commit
2dcff2f621
13
README
13
README
@ -1,13 +1,19 @@
|
||||
AS-Stats v1.35 (2012-04-19)
|
||||
AS-Stats v1.36 (2012-07-25)
|
||||
a simple tool to generate per-AS traffic graphs from NetFlow/sFlow records
|
||||
by Manuel Kasper, Monzoon Networks AG <mkasper@monzoon.net>
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Changes
|
||||
-------
|
||||
vx.x Fix creation of new RRDs when multiple entries with the same
|
||||
v1.36 Fix creation of new RRDs when multiple entries with the same
|
||||
tag are present in the known links file
|
||||
(spotted by Michel Moriniaux)
|
||||
|
||||
Add feature to inspect all ASes in an AS-SET (automatic whois
|
||||
lookup).
|
||||
(contributed by Nicolas Debrigode)
|
||||
|
||||
Updated asinfo.txt with data from whois.cymru.com.
|
||||
|
||||
|
||||
v1.35 Allow hyphens in link names.
|
||||
@ -235,6 +241,9 @@ sFlow data.
|
||||
- Copy the contents of the "www" directory to somewhere within your web
|
||||
server's document root and change file paths in config.inc as necessary.
|
||||
|
||||
- Make the directory "asset" within www writable by the web server (this
|
||||
is used to cache AS-SETs and avoid having to query whois for every request).
|
||||
|
||||
- Wait a few hours for data to accumulate. :)
|
||||
|
||||
- Access the provided PHP scripts via your web server and marvel at the
|
||||
|
36856
www/asinfo.txt
36856
www/asinfo.txt
File diff suppressed because it is too large
Load Diff
168
www/asset.php
Normal file
168
www/asset.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/*
|
||||
* written by Nicolas Debrigode, Hexanet SAS
|
||||
*/
|
||||
|
||||
error_reporting(0);
|
||||
|
||||
require_once('func.inc');
|
||||
|
||||
$asset = strtoupper($_GET['asset']);
|
||||
|
||||
$action = $_GET['action'];
|
||||
if ( $action == "clearall" ) {
|
||||
clearCacheFileASSET("all");
|
||||
header("Location: asset.php");
|
||||
} else if ( $action == "clear" and $asset ) {
|
||||
clearCacheFileASSET($asset);
|
||||
header("Location: asset.php?asset=".$asset."");
|
||||
} else {
|
||||
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Refresh" content="300" />
|
||||
|
||||
<?php if ($asset): ?>
|
||||
<title>History for AS-SET: <?php echo $asset; ?></title>
|
||||
<?php else: ?>
|
||||
<title>History for AS-SET</title>
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="nav"><a href="top.php">Top AS</a> | <a href="history.php">View an AS</a> | View an AS-SET | <a href="linkusage.php">Link usage</a></div>
|
||||
|
||||
<?php if ($asset): ?>
|
||||
<div class="pgtitle">History for AS-SET: <?php echo $asset; ?></div>
|
||||
<?php else: ?>
|
||||
<div class="pgtitle">View history for an AS-SET</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if ($asset): ?>
|
||||
<div id="nav"><a href="asset.php?asset=<?php echo $asset ?>&action=clear">Remove AS-SET cache file for <?php echo $asset ?>.</a></div>
|
||||
<?php
|
||||
$aslist = getASSET($asset);
|
||||
|
||||
if ($aslist[0]):
|
||||
foreach( $aslist as $as ):
|
||||
$as_tmp = substr($as, 2);
|
||||
if (is_numeric($as_tmp)):
|
||||
$as_num[]=$as_tmp;
|
||||
else:
|
||||
$as_other[]=$as;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
if ($as_other[0]) :
|
||||
?>
|
||||
|
||||
<div class="title">Other AS-SETs:</div>
|
||||
|
||||
<ul style="margin-bottom: 2.5em">
|
||||
<?php
|
||||
foreach( $as_other as $as ):
|
||||
?>
|
||||
<li><a href="asset.php?asset=<?php echo $as; ?>"><?php echo $as; ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
<div class="title" style="margin-bottom: 0.5em">This AS-SET:</div>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
|
||||
$i = 0;
|
||||
?>
|
||||
|
||||
<table class="astable">
|
||||
<?php
|
||||
foreach( $as_num as $as ):
|
||||
$asinfo = getASInfo($as);$class = (($i % 2) == 0) ? "even" : "odd";
|
||||
?>
|
||||
<tr class="<?php echo $class; ?>">
|
||||
<th>
|
||||
<div class="title">
|
||||
<?php
|
||||
$flagfile = "flags/" . strtolower($asinfo['country']) . ".gif";
|
||||
if (file_exists($flagfile)):
|
||||
$is = getimagesize($flagfile);
|
||||
?>
|
||||
<img src="<?php echo $flagfile; ?>" <?php echo $is[3]; ?>>
|
||||
<?php endif; ?>
|
||||
AS<?php echo $as; ?>: <?php echo $asinfo['descr']; ?>
|
||||
</div>
|
||||
|
||||
<div class="rank">
|
||||
#<?php echo ($i+1); ?>
|
||||
</div>
|
||||
</th>
|
||||
<td>
|
||||
<?php
|
||||
$rrdfile = getRRDFileForAS($as);
|
||||
|
||||
if (file_exists($rrdfile)): ?>
|
||||
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&width=500&height=150&nolegend=1" width="581" height="204" border="0" /></a>
|
||||
<?php else: ?>
|
||||
<p><center>No data found for AS<?php echo $as; ?></center></p>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
?>
|
||||
|
||||
</table>
|
||||
|
||||
<div id="legend">
|
||||
<table>
|
||||
<?php
|
||||
$knownlinks = getknownlinks();
|
||||
foreach ($knownlinks as $link) {
|
||||
echo "<tr><td style=\"border: 4px solid #fff;\">";
|
||||
|
||||
echo "<table style=\"border-collapse: collapse; margin: 0; padding: 0\"><tr>";
|
||||
echo "<td width=\"9\" height=\"18\" style=\"background-color: #{$link['color']}\"> </td>";
|
||||
echo "<td width=\"9\" height=\"18\" style=\"opacity: 0.73; background-color: #{$link['color']}\"> </td>";
|
||||
echo "</tr></table>";
|
||||
|
||||
echo "</td><td> " . $link['descr'] . "</td></tr>\n";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
else:
|
||||
echo "No data found for AS-SET: ".$asset;
|
||||
endif;
|
||||
else:
|
||||
?>
|
||||
<div id="nav"><a href="asset.php?action=clearall">Remove all AS-SET cache files.</a></div>
|
||||
<form action="" method="get">
|
||||
AS-SET: <input type="text" name="asset" size="20" />
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<div id="footer">
|
||||
AS-Stats v1.36 written by Manuel Kasper, Monzoon Networks AG.<br/>
|
||||
<?php if ($outispositive): ?>
|
||||
Outbound traffic: positive / Inbound traffic: negative
|
||||
<?php else: ?>
|
||||
Inbound traffic: positive / Outbound traffic: negative
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php } ?>
|
@ -12,4 +12,7 @@ $outispositive = true;
|
||||
|
||||
$ntop = 20;
|
||||
|
||||
$whois = "/usr/bin/whois";
|
||||
$assetpath = "asset";
|
||||
$asset_cache_life ="604800"; # 604800 seconds = 7 days
|
||||
?>
|
||||
|
55
www/func.inc
55
www/func.inc
@ -149,4 +149,59 @@ function getRRDFileForAS($as) {
|
||||
return "$rrdpath/" . sprintf("%02x", $as % 256) . "/$as.rrd";
|
||||
}
|
||||
|
||||
function getASSET($asset) {
|
||||
global $whois, $assetpath, $asset_cache_life;
|
||||
|
||||
/* sanity check */
|
||||
if (!preg_match("/^[a-zA-Z0-9:_-]+$/", $asset))
|
||||
return null;
|
||||
|
||||
$assetfile = $assetpath."/".$asset.".txt";
|
||||
|
||||
# check if file exist and cache
|
||||
$filemtime = @filemtime($assetfile);
|
||||
if (!$filemtime or (time() - $filemtime >= $asset_cache_life)) {
|
||||
$cmd = $whois ." -h whois.radb.net '!i".$asset."'";
|
||||
|
||||
$return_aslist = explode("\n",shell_exec($cmd));
|
||||
$aslist = explode(" ",$return_aslist[1]);
|
||||
|
||||
$f = fopen($assetfile,"w");
|
||||
foreach ($aslist as $as) {
|
||||
fputs($f,$as."\n");
|
||||
}
|
||||
fclose($f);
|
||||
# else read cache file
|
||||
} else {
|
||||
$f = fopen($assetfile, "r");
|
||||
$aslist = array();
|
||||
|
||||
while (!feof($f)) {
|
||||
$line = trim(fgets($f));
|
||||
if (!empty($line))
|
||||
$aslist[] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
return $aslist;
|
||||
}
|
||||
|
||||
function clearCacheFileASSET($asset) {
|
||||
global $assetpath;
|
||||
|
||||
/* sanity check */
|
||||
if (!preg_match("/^[a-zA-Z0-9:_-]+$/", $asset))
|
||||
return;
|
||||
|
||||
if ( $asset == "all" ) {
|
||||
$files = glob($assetpath."/*.txt");
|
||||
foreach($files as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
} else {
|
||||
$file = $assetpath."/".$asset.".txt";
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -28,7 +28,7 @@ $rrdfile = getRRDFileForAS($as);
|
||||
|
||||
<body>
|
||||
|
||||
<div id="nav"><a href="top.php">Top AS</a> | View an AS | <a href="linkusage.php">Link usage</a></div>
|
||||
<div id="nav"><a href="top.php">Top AS</a> | View an AS | <a href="asset.php">View an AS-SET</a> | <a href="linkusage.php">Link usage</a></div>
|
||||
|
||||
<?php if ($as): ?>
|
||||
<div class="pgtitle">History for AS<?php echo $as; ?>: <?php echo $asinfo['descr']; ?></div>
|
||||
@ -59,7 +59,7 @@ AS: <input type="text" name="as" size="6" />
|
||||
<?php endif; ?>
|
||||
|
||||
<div id="footer">
|
||||
AS-Stats v1.35 written by Manuel Kasper, Monzoon Networks AG.<br/>
|
||||
AS-Stats v1.36 written by Manuel Kasper, Monzoon Networks AG.<br/>
|
||||
<?php if ($outispositive): ?>
|
||||
Outbound traffic: positive / Inbound traffic: negative
|
||||
<?php else: ?>
|
||||
|
@ -22,7 +22,7 @@ $knownlinks = getknownlinks();
|
||||
|
||||
<body>
|
||||
|
||||
<div id="nav"><a href="top.php">Top AS</a> | <a href="history.php">View an AS</a> | Link usage</div>
|
||||
<div id="nav"><a href="top.php">Top AS</a> | <a href="history.php">View an AS</a> | <a href="asset.php">View an AS-SET</a> | Link usage</div>
|
||||
<div class="pgtitle">Link usage - top 10 AS per link</div>
|
||||
|
||||
<table class="astable">
|
||||
@ -45,7 +45,7 @@ $class = (($i % 2) == 0) ? "even" : "odd";
|
||||
</table>
|
||||
|
||||
<div id="footer">
|
||||
AS-Stats v1.35 written by Manuel Kasper, Monzoon Networks AG.<br/>
|
||||
AS-Stats v1.36 written by Manuel Kasper, Monzoon Networks AG.<br/>
|
||||
<?php if ($outispositive): ?>
|
||||
Outbound traffic: positive / Inbound traffic: negative
|
||||
<?php else: ?>
|
||||
|
@ -32,7 +32,7 @@ $topas = getasstats_top($ntop);
|
||||
Number of AS:
|
||||
<input type="text" name="n" size="4" value="<?php echo $ntop; ?>" />
|
||||
<input type="submit" value="Go" style="margin-right: 2em" />
|
||||
Top AS | <a href="history.php">View an AS</a> | <a href="linkusage.php">Link usage</a></form>
|
||||
Top AS | <a href="history.php">View an AS</a> | <a href="asset.php">View an AS-SET</a> | <a href="linkusage.php">Link usage</a></form>
|
||||
</div>
|
||||
<div class="pgtitle">Top <?php echo $ntop; ?> AS</div>
|
||||
|
||||
@ -88,7 +88,7 @@ foreach ($knownlinks as $link) {
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
AS-Stats v1.35 written by Manuel Kasper, Monzoon Networks AG.<br/>
|
||||
AS-Stats v1.36 written by Manuel Kasper, Monzoon Networks AG.<br/>
|
||||
<?php if ($outispositive): ?>
|
||||
Outbound traffic: positive / Inbound traffic: negative
|
||||
<?php else: ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user