• 大小: 3.66MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-21
  • 语言: C/C++
  • 标签: TcpView  

资源简介

TcpView源代码(MFC VS2005)

资源截图

代码片段和文件信息

// Connection.cpp: implementation of the CConnection class.
//
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “TcpView.h“
#include “Connection.h“
#include “Process.h“
#include 

#pragma  comment(lib“iphlpapi.lib“)

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CConnection::CConnection()
{
m_pView = NULL;
HMODULE hMod = LoadLibrary(“Iphlpapi.dll“);
if(!hMod)
{
AfxMessageBox(“加载Iphlpapi.dll出错“);
return;
}
m_pfnGetTcpTable = (PFNGetExtendedTcpTable)::GetProcAddress(hMod“GetExtendedTcpTable“);
m_pfnGetUdpTable = (PFNGetExtendedUdpTable)::GetProcAddress(hMod“GetExtendedUdpTable“);
m_pfnSetTcpEntry = (PFNSetTcpEntry)CProcess::GetProcTrueAddr(“Iphlpapi.dll““SetTcpEntry“0);
// FreeLibrary(hMod);
bUdp = TRUE;
}

CConnection::~CConnection()
{

}

int CConnection::GetTcpConnect()
{
ConnInfo connInfo;
connInfo.uPro = TCP;
PMIB_TCPTABLE_OWNER_PID pTcpTable = new MIB_TCPTABLE_OWNER_PID;
DWORD dwSize = sizeof(MIB_TCPTABLE_OWNER_PID);
if (m_pfnGetTcpTable(pTcpTable &dwSize TRUEAF_INETTCP_TABLE_OWNER_PID_ALL0) == ERROR_INSUFFICIENT_BUFFER)
{
delete pTcpTable;
pTcpTable = (MIB_TCPTABLE_OWNER_PID *)new char[dwSize];
}
if(m_pfnGetTcpTable(pTcpTable&dwSizeTRUEAF_INETTCP_TABLE_OWNER_PID_ALL0) != NO_ERROR)
{
AfxMessageBox(“获取TCP连接出错“);
delete pTcpTable;
return 0;
}
int nNum = (int) pTcpTable->dwNumEntries;

for(int i=0;i {
if(MIB_TCP_STATE_TIME_WAIT == pTcpTable->table[i].dwState) continue;
connInfo.dwLocalIp   = pTcpTable->table[i].dwLocalAddr;
connInfo.dwRemoteIp  = pTcpTable->table[i].dwRemoteAddr;
connInfo.nLocalPort  = htons(pTcpTable->table[i].dwLocalPort);
connInfo.nRemotePort = htons(pTcpTable->table[i].dwRemotePort);
connInfo.uState = pTcpTable->table[i].dwState;
connInfo.nPId = pTcpTable->table[i].dwOwningPid;

CString strPath = CProcess::GetProcessNameById(pTcpTable->table[i].dwOwningPidTRUE);
// AfxMessageBox(“a“);
HICON hIcon = FindIconList(strPath);
if(hIcon == NULL)
{
hIcon = CProcess::GetExeIcon(strPath);

AddIconList(strPathhIcon);
}

connInfo.hIcon = hIcon;
m_pView->SendMessage(WM_ADDTCPCONN0(LPARAM)&connInfo);
}

delete pTcpTable;
}

void CConnection::SetViewPoint(CView *pView)
{
m_pView = pView;
}

CString CConnection::GetState(int nState)
{
CString strStatus;

switch (nState) 

case MIB_TCP_STATE_CLOSED     : 
strStatus=“CLOSED“; 
break; 
case MIB_TCP_STATE_LISTEN     : 
strStatus=“LISTEN“; 
break; 
case MIB_TCP_STATE_SYN_SENT   : 
strStatus=“SYN_SENT“; 
break; 
case MIB_TCP_STATE_SYN_RCVD   : 
strStatus=“SYN_RCVD“; 
break; 
c

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-04-30 10:48  TcpView\
     文件        6165  2011-03-30 20:05  TcpView\Connection.cpp
     文件        2808  2011-03-29 14:37  TcpView\Connection.h
     文件        2931  2011-03-29 14:38  TcpView\MainFrm.cpp
     文件        1489  2011-03-29 13:19  TcpView\MainFrm.h
     文件       10572  2011-03-30 20:11  TcpView\MyListView.cpp
     文件        1816  2011-03-24 15:30  TcpView\MyListView.h
     文件        9725  2011-03-24 15:55  TcpView\MyListView0.cpp
     文件        4426  2011-04-01 18:14  TcpView\Process.cpp
     文件         705  2011-03-24 22:30  TcpView\Process.h
     文件        1657  2011-03-25 15:10  TcpView\protocol.h
     文件        4019  2011-03-22 20:53  TcpView\ReadMe.txt
     目录           0  2011-03-24 22:22  TcpView\res\
     文件         733  2011-03-30 21:49  TcpView\resource.h
     文件        1078  2011-03-24 22:22  TcpView\res\Icon_3.ico
     文件         524  2011-03-22 21:01  TcpView\res\manifest.xml
     文件        1078  2011-03-22 20:53  TcpView\res\TcpView.ico
     文件         399  2011-03-22 20:53  TcpView\res\TcpView.rc2
     文件        1078  2011-03-22 20:53  TcpView\res\TcpViewDoc.ico
     文件        9022  2008-05-16 02:12  TcpView\SEU_QQwry.cpp
     文件        1707  2008-03-13 19:17  TcpView\SEU_QQwry.h
     文件        8882  2012-03-27 11:46  TcpView\Sniffer.cpp
     文件        1166  2011-03-29 22:16  TcpView\Sniffer.h
     文件         209  2011-03-22 20:53  TcpView\StdAfx.cpp
     文件        1148  2011-03-29 13:06  TcpView\StdAfx.h
     文件       27872  2012-03-27 11:38  TcpView\TcpView.aps
     文件        2141  2012-04-03 16:17  TcpView\TcpView.clw
     文件        5063  2011-03-29 12:37  TcpView\TcpView.cpp
     文件        4040  2011-03-25 16:06  TcpView\TcpView.dsp
     文件        1454  2011-03-28 17:26  TcpView\TcpView.h
     文件    11258880  2012-04-03 16:19  TcpView\TcpView.ncb
............此处省略12个文件信息

评论

共有 条评论

相关资源