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

📄 uupdscanthread.~pas

📁 定时扫描局域网络中的电脑的Mac地址情况
💻 ~PAS
字号:
unit UUPDScanThread;

interface

uses
  Classes,SysUtils,Forms;

type
  TUPDScanThread = class(TThread)
  private
    procedure LogToFile;
    procedure Log;
    procedure ShowCount;
  public
    ScanIPs:string;
    DestIP:string;//需要检查的IP地址
    DestMac:string;//Mac地址结果
    constructor Create(const aIP: string;aCreateSuspended:boolean=true;aFreeOnTerminate:boolean=true);
    destructor Destroy; override;

  protected
    procedure Execute; override;

  end;
var ThreadCount:integer=0;
   ThreadStop:boolean=false;

implementation
uses UMacFunction,UIPMacManager,UMainForm;
{ TScanThread }
constructor TUPDScanThread.Create(const aIP: string;aCreateSuspended:boolean=true;aFreeOnTerminate:boolean=true);
begin
   inherited Create(aCreateSuspended);
   ScanIPs:=aIP;
   DestIP:=aIP;
   FreeOnTerminate:=aFreeOnTerminate;
   inc(ThreadCount);
   Resume;
end;
destructor TUPDScanThread.Destroy;
begin
       //dec(ThreadCount);
       inherited Destroy;
end;
function StrToTstr(OriginStr:String;DestTstr:TstringList;Splitter:String =','):Integer;
var
    i,iRet:integer;
    tmpStr:String;
begin
    tmpStr:='';
    iRet:=0;
    DestTStr.Clear;
    for i:=1 to length(OriginStr) do
    begin
        if (OriginStr[i]<>Splitter) then
            tmpStr:=tmpStr+OriginStr[i];
        if OriginStr[i]=Splitter then
            if tmpStr<>'' then
            begin
                DestTStr.Add(tmpStr);
                iRet:=iRet+1;
                tmpStr:='';
            end;
    end;
    if tmpStr<>'' then
    begin
                DestTStr.Add(tmpStr);
                iRet:=iRet+1;
                tmpStr:='';
    end;
    Result:=iRet;
end;

procedure TUPDScanThread.Execute;
var IPList:TstringList;
    Index:integer;
    OnLine:boolean;
begin
  Synchronize(ShowCount);
  IPList:=TstringList.Create;
  StrToTstr(ScanIPs,IPList,',');
  Index:=0;
  try
    while (not ThreadStop and not self.Terminated) and (Index<IPList.Count) do
    begin
      DestIP:=IPList[Index];
      inc(Index);
      if(DestIP='') then    Continue;

      DestMac:=Uppercase(UMacFunction.GetMacByIp(DestIP));
      OnLine:=DestMac<>'';
      IPMacManager.OnLineModify(DestIP,OnLine);
      if(OnLine) then
      begin

        Synchronize(Log);
        Synchronize(LogToFile);
      end;
    end;
  finally
      IPList.free;
      self.Terminate;
      dec(ThreadCount);
      Synchronize(ShowCount);
  end;

end;
procedure TUPDScanThread.LogToFile;
var Mac:string;
begin
    if(IPMacManager=nil) then
       Exit;
    Mac:=Uppercase(IPMacManager.FindByIP(DestIP));
    if Pos(DestMac,Mac)<=0 then
      IPMacManager.AddMac(DestIP,DestMac);
end;
procedure TUPDScanThread.Log;
begin
   MainForm.LogStr('ScanThread ['+DestIP+'] = '+DestMac);
end;
procedure TUPDScanThread.ShowCount;
begin
   MainForm.Caption:='定时检查Mac地址        ThreadCount='+inttostr(ThreadCount);
end;

end.

⌨️ 快捷键说明

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