获取TCP,UDP服务端口号.rar

时间:2023-01-31 10:27:00
【文件属性】:

文件名称:获取TCP,UDP服务端口号.rar

文件大小:351KB

文件格式:RAR

更新时间:2023-01-31 10:27:00

TCP UDP服务端口

TCP,UDP服务端口,HMODULE hIpDLL = LoadLibrary( "iphlpapi.dll"); if ( !hIpDLL) return; PMIB_TCPTABLE_OWNER_PID pTcpTable(NULL); DWORD dwSize(0); PGet_Extended_TcpTable pGetExtendedTcpTable = NULL; pGetExtendedTcpTable = (PGet_Extended_TcpTable) GetProcAddress(hIpDLL, "GetExtendedTcpTable"); if(pGetExtendedTcpTable==NULL) { FreeLibrary(hIpDLL); return; } if(pGetExtendedTcpTable(pTcpTable, &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0) == ERROR_INSUFFICIENT_BUFFER) pTcpTable = (MIB_TCPTABLE_OWNER_PID *)new char[dwSize];//重新分配缓冲区 if (pGetExtendedTcpTable(pTcpTable, &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0) != NO_ERROR) { delete pTcpTable; return; } CString sTemp; m_PortList.DeleteAllItems(); int nNum = (int)pTcpTable->dwNumEntries; //TCP连接的数目 // nNum = 0; for (int i = 0; itable[i].dwLocalAddr))); sTemp.Format("%u",htons((WORD)pTcpTable->table[i].dwLocalPort)); m_PortList.SetItemText(i,4,sTemp); m_PortList.SetItemBgColor(i,4,RGB(210,0,0)); m_PortList.SetItemText(i,5,FormatNumToIpv4(htonl(pTcpTable->table[i].dwRemoteAddr))); sTemp.Format("%u",htons((WORD) pTcpTable->table[i].dwRemotePort)); m_PortList.SetItemText(i,6,sTemp); sTemp.Format("%u",pTcpTable->table[i].dwOwningPid); m_PortList.SetItemText(i,8,sTemp); //ProcessPidToName(pTcpTable->table[i].dwOwningPid,i); ProcessPidToNameX(pTcpTable->table[i].dwOwningPid,i); switch (pTcpTable->table[i].dwState) { case MIB_TCP_STATE_CLOSED: m_PortList.SetItemText(i,2,"CLOSED"); break; case MIB_TCP_STATE_LISTEN: m_PortList.SetItemText(i,2,"LISTEN"); break; case MIB_TCP_STATE_SYN_SENT: m_PortList.SetItemText(i,2,"SYN-SENT"); break; case MIB_TCP_STATE_SYN_RCVD: m_PortList.SetItemText(i,2,"SYN-RECEIVED"); break; case MIB_TCP_STATE_ESTAB: m_PortList.SetItemText(i,2,"ESTABLISHED"); break; case MIB_TCP_STATE_FIN_WAIT1: m_PortList.SetItemText(i,2,"FIN-WAIT-1"); break; case MIB_TCP_STATE_FIN_WAIT2: m_PortList.SetItemText(i,2,"FIN-WAIT-2"); break; case MIB_TCP_STATE_CLOSE_WAIT: m_PortList.SetItemText(i,2,"CLOSE-WAIT"); break; case MIB_TCP_STATE_CLOSING: m_PortList.SetItemText(i,2,"CLOSING"); break; case MIB_TCP_STATE_LAST_ACK: m_PortList.SetItemText(i,2,"LAST-ACK"); break; case MIB_TCP_STATE_TIME_WAIT: m_PortList.SetItemText(i,2,"TIME-WAIT"); break; case MIB_TCP_STATE_DELETE_TCB: m_PortList.SetItemText(i,2,"DELETE-TCB"); break; default: m_PortList.SetItemText(i,2,"UNKNOWN"); break; } } delete pTcpTable; FreeLibrary(hIpDLL);


【文件预览】:
ListPort
----psapi.lib(7KB)
----ListPort.dsw(539B)
----ListPort.ncb(81KB)
----resource.h(731B)
----ListPort.plg(250B)
----ListPort.cpp(2KB)
----Debug()
----BitMapMem.h(2KB)
----ListPort.opt(807KB)
----ListPort.aps(56KB)
----ListPortDlg.cpp(31KB)
----ListPortDlg.h(2KB)
----ReadMe.txt(4KB)
----Psapi.h(6KB)
----SimpleListCtrl.cpp(21KB)
----res()
--------ListPort.ico(21KB)
--------ListPort.rc2(400B)
--------greengrid.bmp(198B)
--------head.ico(1KB)
----ListPort.clw(774B)
----IPHLPAPI.LIB(83KB)
----IPEXPORT.H(9KB)
----ListPort.rc(5KB)
----ListPort.h(1KB)
----Release()
----ListCtrlHeader.h(2KB)
----IPTYPES.H(7KB)
----StdAfx.cpp(210B)
----Iphlpapi.h(16KB)
----ListPort.dsp(5KB)
----StdAfx.h(1KB)
----SimpleListCtrl.h(3KB)
----ListCtrlHeader.cpp(8KB)

网友评论