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

📄 thread_scan.cpp

📁 VC++编写的类似Sniffer的网络数据包监听程序
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "thread_scan.h"
#include "function_1.h"
#include "main.h"
#include "syncobjs.hpp"
#pragma package(smart_init)

extern unsigned long ping_ip_start;
extern unsigned long ping_ip_stop;//开始,结束的ip
extern int cur_ip;//已工作的ip数
extern int ping_thread_no;//已工作的ip数
extern boolean thread_run;//已工作的ip数
extern int share_thread_no;//share线程数量
extern int share_ip_no;//share工作的位置指示

extern TCriticalSection *ping_CriticalSection;//全局临界变量

//---------------------------------------------------------------------------

//PING线程的结束处理事件
void __fastcall Tmy_thread1::ThreadDone(TObject * Sender)
{
  ((Tmy_thread1*)Sender)->FPing->Free();
  ping_thread_no--;
  main_f->Edit14->Text=IntToStr(ping_thread_no);
  if (ping_thread_no==0)
   { main_f->Edit7->Text="查找完成...";
     main_f->Bar->Max=main_f->ListBox1->Items->Count;
     if (share_thread_no>0)
       main_f->Bar->Position=share_ip_no;
      else
       main_f->Bar->Position=0;
   }
}

__fastcall Tmy_thread1::Tmy_thread1(TPing *thread_Ping,bool CreateSuspended)
        : TThread(CreateSuspended)
{
  FPing=thread_Ping;
  OnTerminate =ThreadDone;
  FreeOnTerminate = True;
  FPing->OnEchoReply=PingEchoReply;
  ping_thread_no++;
  main_f->Edit14->Text=IntToStr(ping_thread_no);
}
//---------------------------------------------------------------------------
void __fastcall Tmy_thread1::Execute()
{
   ping_CriticalSection->Enter();//进入临界状态
   int no=cur_ip;
       cur_ip++;
   ping_CriticalSection->Leave();//析放临界状态

   if ((ping_ip_start+no)<ping_ip_stop)
    {
      FPing->Address=iptostr(ping_ip_start+no);
      FPing->Ping();
    }
}
void __fastcall Tmy_thread1::PingEchoReply(TObject *Sender, TObject *Icmp,
      int Error)
{
   ping_CriticalSection->Enter();//进入临界状态
    int no=cur_ip;
    cur_ip++;
   ping_CriticalSection->Leave();//析放临界状态

  Synchronize(set_bar);
  if (Error==1) Synchronize(set_str);
  if (!thread_run) return;

  if ((ping_ip_start+no)<=ping_ip_stop)
    {
     ((TPing*)Sender)->Address=iptostr(ping_ip_start+no);
     ((TPing*)Sender)->Ping();
    }
}

//---------------------------------------------------------------------------


void __fastcall Tmy_thread1::set_bar()
{
  main_f->Edit7->Text=FPing->Address;
  main_f->Bar->Position=cur_ip;
}

void __fastcall Tmy_thread1::set_str()
{
  main_f->ListBox1->Items->Add(FPing->Address);
  main_f->Edit9->Text=IntToStr(StrToInt(main_f->Edit9->Text)+1);
  if (main_f->share_check->Checked) creat_share();//自动找共享资料
}

⌨️ 快捷键说明

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