⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iprelation.pas

📁 这是一个用VC++编写的网络嗅探器
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{===================Unit IpRelation Edit by Oldseven 12.3.2003=================}
{==============================================================================}
unit IpRelation;

interface
uses
   Windows,
   SysUtils,
   Classes,
   Dialogs,
   Variants,
   Chart,
   Registry,
   IPExport,
   IPHlpApi,
   Iprtrmib,
   IpTypes,
   IpFunctions;

type  TiFaceInfo = Record
      CardIndex      : DWORD;  // iface索引
      BIn            : DWORD;  // 进入的字节数
      BOut           : DWORD;  // 出去的字节数

      pBin           : DWORD;  // 进入的广播包
      pubIn          : DWORD;  // 进入的非广播包
      pbOut          : DWORD;  // 发出的广播包
      pubOut         : DWORD;  // 发出的非广播包

      nSpeed         : DWORD;  // 网络波特率 公式:

      inNetUseRate   : Double;   // 进入的网络负载率 公式:bIn*8 div nSpeed
      outNetUseRate  : Double;   // 发出的网络负载率 公式:bOut*8 div nSpeed
      netUseRate     : Double;   // 综合网络负载率   公式:(bIn+bOut)*8 div (nSpeed*2)

      inBroastRate   : Double;   // 进入广播带宽负载率 公司:pubIn div (pbIn+pubIn)
      outBroastRate  : Double;   // 发出广播带宽负载率 公司:pubOut div (pbOut+pubOut)
end;


procedure getIfaceTableInfo(var TifaceIndexs:TStrings);
procedure getIfaceIfRowInfo(CardIndex:LongInt;var iFaceInfo:TiFaceInfo);

procedure getMAXpackInout(ifaceInfo:TiFaceInfo;TypeI:integer;ChartTag:integer;var packetsIn ,packetsOut,packetsFL:Double);
procedure TimerOnTime(iFaceInfo:TiFaceInfo;Typei:integer;var Chart1:TChart);
procedure beginGetTheGrp(iFaceInfo:TiFaceInfo;Typei:integer;var Chart1: TChart);
procedure initTempStru(CardI,TypeI:Integer);
function  newGetIfaceInfo(StrID:String):String;
Function getNetCardIndex(StrNetID:String):String;
implementation

CONST
  MaxTime =60; // 1 minutes
  MaxVal  = MaxTime;  // two reads per second

  MAXChartN = 20;

  //临时存放数据的结构
  type TTempInfo = Record
      tmpIn     : Array[1..MAXChartN,0..2] of Double;
      tmpOut    : Array[1..MAXChartN,0..2] of Double;
      tmpFL     : Array[1..MAXChartN,0..2] of Double;

      tmpPBin   : Array[1..MAXChartN,0..2] of Double;
      tmpPubIn  : Array[1..MAXChartN,0..2] of Double;
      tmpPbOut  : Array[1..MAXChartN,0..2] of Double;
      tmpPubOut : Array[1..MAXChartN,0..2] of Double;
  end;

  var
   P            : Array[1..MAXChartN] of Integer;
   indexN       : Integer;
   Times        : Integer;
   TempInfo     : TTempInfo;
   dataIn, dataOut,dataFL : Array[0..MAXChartN,0..MaxVal+1] of Double;

//----------------------By 12.10 oldseven --------------------------------------
// Get iface Index Like as 1,2666359 of the netCark index in the ifaceTable
// Param StrNetID : like as {1233323-122asdf-23232323} in the Registry
//------------------------------------------------------------------------------
Function getNetCardIndex(StrNetID:String):String;
var
  PAdapter, PMem: PipAdapterInfo;
  pPerAdapter: PIpPerAdapterInfo;
  OutBufLen: ULONG;
begin
  VVGetAdaptersInfo(PAdapter, OutBufLen);
  PMem := PAdapter;

  try
    while PAdapter <> nil do
    begin
      if  CompareText(String(Padapter.AdapterName),StrNetID)=0 then
          Result:=FloatToStr(Padapter.Index);
      PAdapter := PAdapter.Next;
    end;
  finally
    if PAdapter <> nil then
      Freemem(PMem, OutBufLen);
  end;
end;

//==============================================================================
//  得到 ifaceTable中的各个接口的索引号,以字符串保存到参数 TifaceIndexs 中
//==============================================================================

procedure getIfaceTableInfo(var TifaceIndexs:TStrings);
var
  PAdapter, PMem: PipAdapterInfo;
  pPerAdapter: PIpPerAdapterInfo;
  OutBufLen: ULONG;
  ConnName:String;
begin
  VVGetAdaptersInfo(PAdapter, OutBufLen);
  PMem := PAdapter;
  TifaceIndexs.Clear;
  try
    while PAdapter <> nil do
    begin
      Case PAdapter.Type_  of
          23:TifaceIndexs.Add(FloatToStr(PAdapter.Index)+'='+'其他网络接口');
          24:;
           6:begin
              ConnName:=newGetIfaceInfo(PAdapter.AdapterName);
              TifaceIndexs.Add(FloatToStr(PAdapter.Index)+'='+ConnName);
            end;
      else
          TifaceIndexs.Add(FloatToStr(PAdapter.Index)+'='+'其他网络接口');
      end;

      PAdapter := PAdapter.Next;
    end;
  finally
    if PAdapter <> nil then
      Freemem(PMem, OutBufLen);
  end;
end;

{procedure getIfaceTableInfo(var TifaceIndexs:TStrings);
var
  p: PMibIfTable;
  Size: Cardinal;
  i,j: integer;
  s: string;
begin
  try

    VVGetIfTable(p,Size,True);
    if p <> nil then
    try
      J:=p^.dwNumEntries;

      for i := 0 to J-1 do
      with p^.table[i] do
      begin
        if dwType<>24 then  // 非回路   接口索引           接口名称
           TifaceIndexs.Add(FloatTostr(dwIndex)+'='+String(wszName));
      end;
    except

    end;
  finally
      FreeMem(p, size);
  end;
end; }
//==============================================================================
// 根据参数 CardIndex 得到此 cardIndex索引号的接口详细信息,传到结构 iFaceInfo中
//==============================================================================
procedure getIfaceIfRowInfo(CardIndex:LongInt;var iFaceInfo:TiFaceInfo);
var
  IfRow: TMibIfRow;
  j: integer;
  tmpD:Double;
begin
  FillChar(IfRow,sizeof(IfRow),#0);
  IfRow.dwIndex := CardIndex;
  VVGetIfEntry(@IfRow);

  ifaceInfo.CardIndex := CardIndex;
  iFaceInfo.BIn := IfRow.dwInOctets ;
  ifaceInfo.BOut := ifRow.dwOutOctets ;

  ifaceInfo.pBin := ifRow.dwInUcastPkts;
  ifaceInfo.pubIn :=ifRow.dwInNUcastPkts;
  ifaceInfo.pbOut := ifRow.dwOutUcastPkts;
  ifaceInfo.pubOut :=ifRow.dwOutNUcastPkts;
  ifaceInfo.nSpeed :=ifRow.dwSpeed;

  {ifaceInfo.inNetUseRate :=  ifaceInfo.Bin * (8 / ifaceInfo.nSpeed);//bIn*8 div nSpeed
  ifaceInfo.outNetUseRate:= ifaceInfo.BOut *(8 / ifaceInfo.nSpeed) ;// 发出的网络负载率 公式:bOut*8 div nSpeed
  tmpD:= (ifaceInfo.BIn + IfaceInfo.BOut)*(4 / (ifaceInfo.nSpeed));
  ifaceInfo.netUseRate:=tmpD; // 综合网络负载率   公式:(bIn+bOut)*8 div (nSpeed*2)
  //ifaceInfo.netUseRate:=(ifaceInfo.inNetUseRate+ifaceInfo.outNetUseRate)/2;
  ifaceInfo.inBroastRate   :=1000*(ifaceInfo.pubIn / (IfaceInfo.pBin + ifaceInfo.pubIn));   // 进入广播带宽负载率 公司:pubIn div (pbIn+pubIn)
  ifaceInfo.outBroastRate  :=1000*(ifaceInfo.pubOut / (IfaceInfo.pbOut +IfaceInfo.pubOut));   //pubOut div (pbOut+pubOut)
   }
end;
//==============================================================================
//  (外部程序入口)    //此过程后调用:Timer1.Enabled := true;
//  开始对Chart进行描绘   beginGetTheGrp;
//  参数:     iFaceInfo:TiFaceInfo; -- 传入的结构(接口信息)
//             Typei:integer; 0 : outIn 2条Seiros(曲线)    //FormIndex : 窗体的索引号
//                            1 : Borst 2条Seiros(曲线)    //ChartIndex:Chart在窗体的索引号
//                            2 : netFL 3条Seiros(曲线)
//             Chart1:        传入的,传出的 TChart
//==============================================================================
procedure beginGetTheGrp(iFaceInfo:TiFaceInfo;Typei:integer;var Chart1: TChart);
var i:integer;
   x:double;
begin
   // initialize temp Stru
   initTempStru(Chart1.Tag,TypeI);
   // initialize packet counts
   getMAXpackInout(iFaceInfo,TypeI,Chart1.Tag,dataIn[Chart1.Tag,P[Chart1.Tag]], dataOut[Chart1.Tag,P[Chart1.Tag]],dataFL[Chart1.Tag,p[Chart1.Tag]]);

   if ((Chart1.Tag mod 3) =1) then
   begin
      x:= (IfaceInfo.nSpeed/8000);

      Chart1.LeftAxis.Minimum := 0;
      Chart1.LeftAxis.MAximum := x;
   end;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -