Panabit Support Board!

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11119|回复: 6

贡献个PHP小程序,统计内网使用P2P下载和视频的IP

[复制链接]
发表于 2008-4-8 14:10:46 | 显示全部楼层 |阅读模式
  1. <?
  2. // p2p traffic analysis
  3. $p2p_down = array("Bittorrent", "eDonkey", "Poco", "迅雷",
  4.                   "Gnutella", "Fasttrack", "DirectConnect",
  5.                   "AppleJuice", "百度下吧", "百宝", "酷狗",
  6.                   "Vagaa", "Ares", "Napster", "Mute",
  7.                   "iMesh", "SoulSeek", "脱兔", "PPGou",
  8.                   "天网Maze", "超级旋风", "酷我音乐盒", "BT扩展协议",
  9.                   "搜娱",
  10.                   );
  11. $p2p_tv = array("PPStream", "PPLive", "沸点", "乐酷",
  12.                 "QQ直播", "CCIPTV", "TVAnts", "TVKoo",
  13.                 "PPMate", "MySee", "悠视TV", "SopCast",
  14.                 "VJBase", "Jeboo", "风行", "迅雷看看",
  15.                 "PPFilm",
  16.                 );
  17. $badguy = array();
  18. $badip = array();

  19. exec("/usr/panabit/bin/floweye flow list", $flowlist);
  20. foreach ($flowlist as $line) {
  21.     // get the internal ip
  22.     if (preg_match("/192\.168\.(\d+)\.(\d+)/", $line, $out)) {
  23.         $proto = explode(" ", $line);
  24.         //echo $out[0]." ".$proto[1]."\n";exit;
  25.         if (in_array($proto[1], $p2p_down) || in_array($proto[1], $p2p_tv)) {
  26.             $badguy[ $proto[1] ][ $out[0] ] += 1;
  27.             if (!in_array($out[0], $badip)) {
  28.                 array_push($badip, $out[0]);
  29.             }
  30.         }
  31.     }
  32. }

  33. $down_rows = "";
  34. foreach ($p2p_down as $p) {
  35.     if (array_key_exists($p, $badguy)) {
  36.         foreach ($badguy[$p] as $ip => $n) {
  37.             if ($ip == $_SERVER['REMOTE_ADDR']) {
  38.                 $ip = "<font color='red'>".$ip."</font>";
  39.             }
  40.             $down_rows .= "<tr align='center'><td>$ip</td><td>$p</td><td>$n</td></tr>";
  41.         }
  42.     }
  43. }
  44. $tv_rows = "";
  45. foreach ($p2p_tv as $p) {
  46.     if (array_key_exists($p, $badguy)) {
  47.         foreach ($badguy[$p] as $ip => $n) {
  48.             if ($ip == $_SERVER['REMOTE_ADDR']) {
  49.                 $ip = "<font color='red'>".$ip."</font>";
  50.             }
  51.             $tv_rows .= "<tr align='center'><td>$ip</td><td>$p</td><td>$n</td></tr>";
  52.         }
  53.     }
  54. }
  55. ?>
  56. <div style="margin:auto; text-align:center; height:30px"><?if(in_array($_SERVER['REMOTE_ADDR'], $badip)){echo "[<font color='red'>{$_SERVER['REMOTE_ADDR']}</font>] 我们是害虫,我们是害虫,上班在用P2P!";}else{echo "[<font color='green'>{$_SERVER['REMOTE_ADDR']}</font>] 我们都是好孩子,上班不用P2P。";}?></div>
  57. <table bordercolor="#000000" cellspacing="0" cellpadding="5" width="750" align="center" bgcolor="#ffffcc" border="1">
  58.   <tr bgcolor="#ffcc66" align="center">
  59.     <td width="40%">坏蛋IP</td>
  60.     <td width="30%">协议</td>
  61.     <td width="30%">会话数</td>
  62.   </tr>
  63. <?
  64. if ("" == $down_rows && "" == $tv_rows) {
  65.     echo "<tr bgcolor='#66ffff'><td colspan='3' align='center'>今天没人使用P2P :-)</td></tr>";
  66. }
  67. else {
  68. if ("" != $down_rows) {
  69. ?>
  70.   <tr bgcolor='#66ffff'><td colspan='3' align='center'>P2P下载</td></tr>
  71. <?
  72.     echo $down_rows;
  73. }
  74. if ("" != $tv_rows) {
  75. ?>
  76.   <tr bgcolor='#66ffff'><td colspan='3' align='center'>P2P视频</td></tr>
  77. <?
  78.     echo $tv_rows;
  79. }
  80. }
  81. ?>
  82. </table>
复制代码
 楼主| 发表于 2008-4-8 14:15:53 | 显示全部楼层
一般员工看到这个列表也就不好意思再使用P2P下载了,内网状况就能大为改善。
{FC0CC2AC-3C5E-4429-AE4D-CEC1291EA89A}.JPG
发表于 2008-4-8 14:30:57 | 显示全部楼层
好东东,把源码放在哪里呢?如何去访问?
发表于 2008-4-8 14:45:37 | 显示全部楼层
原帖由 faint 于 2008-4-8 14:10 发表


Very good!
 楼主| 发表于 2008-4-8 14:56:05 | 显示全部楼层
原帖由 panabit 于 2008-4-8 14:45 发表
Very good!


还望版主加强panabit针对IP的流量统计功能,现在我还得用ntop去做统计。而且加载了panabit内核模块后无法sniff数据采集网卡,所以只能再加块网卡,交换机上也得另外再做一个镜像端口。
发表于 2008-4-9 14:22:07 | 显示全部楼层
还是没有搞懂怎么使用,是否要freebsd安装appche才行?
发表于 2008-4-9 15:43:04 | 显示全部楼层
肯定的否则无法运行php
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|北京派网软件有限公司 ( ICP备案序号:京ICP备14008283号 )

GMT+8, 2024-5-17 13:08 , Processed in 0.073271 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表