Click here to Skip to main content
Licence 
First Posted 16 Nov 2003
Views 96,679
Downloads 2,425
Bookmarked 34 times

Enhance netstat

By y0da | 16 Nov 2003
This article shows an implementation of the main TCP/UDP functions of the IP Helper API that is used to get info about active connections including the process attached to a connection.
1 vote, 10.0%
1

2
1 vote, 10.0%
3
2 votes, 20.0%
4
6 votes, 60.0%
5
3.78/5 - 10 votes
μ 3.78, σa 2.30 [?]

Sample Image - enetstat.jpg

Introduction

The main idea of this project was already implemented and presented by some guys around here: using GetTcpTable and GetUdpTable to read connection states of running processes. Yet another thing that is mentioned in this kind of articles are two undocumented APIs from iphlpapi.dll: AllocateAndGetTcpExTableFromStack and AllocateAndGetUdpExTableFromStack. Using these APIs, we can get access to the name of the process that holds the running connection. Unfortunately it does work only with Win2000, WinXP or newer versions.

Description

First of all, I'd like to mention there is something new regarding this subject. Enetstat will allow the user to close any "established" connection using the following API function:

DWORD SetTcpEntry(
  PMIB_TCPROW pTcpRow
);

Having an established connection, we can close it using the following state: MIB_TCP_STATE_DELETE_TCB.

MIB_TCPROW sKillConn;
sKillConn.dwLocalAddr = (DWORD)ulLocIP; //local ip
sKillConn.dwLocalPort = (DWORD)usLocalPort; //local port
sKillConn.dwRemoteAddr = (DWORD)ulRemIP; //remote ip
sKillConn.dwRemotePort = (DWORD)usRemPort; //remote port
sKillConn.dwState = MIB_TCP_STATE_DELETE_TCB;

DWORD dwRez = SetTcpEntry(&sKillConn);

That's all about it. My piece of code is not described in detail and I suppose there is no need for that as long as we already have a cool and detailed description made by Axel Charpentier.

Well, if you need any good reference about this subject you'll find it here:

Getting active TCP/UDP connections on a box, by Axel Charpentier.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

y0da

Web Developer

Romania Romania

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionAlways 87!!! PinmembereRRaTuM5:18 16 Mar '08  
GeneralNot in 2000, deprecated in Vista Pinmemberldsandon1:44 6 Dec '06  
GeneralRe: Not in 2000, deprecated in Vista Pinmembery0da2:01 6 Dec '06  
GeneralRe: Not in 2000, deprecated in Vista PinmemberLeo Davidson2:48 28 Mar '09  
Generalprinter PinmemberKutti Ra16:59 30 Sep '05  
GeneralMonitoring Internet client PinmemberKutti Ra16:56 30 Sep '05  
GeneralTcpTable does not return all connections Pinmemberbigga5:16 16 Sep '05  
GeneralRe: TcpTable does not return all connections Pinmembery0da5:32 16 Sep '05  
QuestionWhat about speed ? PinmemberSmart K822:29 5 Feb '05  
AnswerRe: What about speed ? Pinmembery0da23:25 5 Feb '05  
GeneralRe: What about speed ? PinmemberSmart K823:18 6 Feb '05  
Generalstack Memory Leak Pinmembermervick16:43 26 Jan '05  
GeneralRe: stack Memory Leak Pinmembery0da21:22 26 Jan '05  
GeneralRe: stack Memory Leak Pinmembermervick16:17 27 Jan '05  
GeneralRe: stack Memory Leak Pinmembery0da21:19 27 Jan '05  
Generalenetstat on winnt and Win2k and NT4 Pinmembery0da21:25 27 Apr '04  
GeneralAllocateAndGetTcpExTableFromStack for Windows 2000 Pinmemberblakeo239:39 14 Apr '04  
GeneralRe: AllocateAndGetTcpExTableFromStack for Windows 2000 PinsussAnonymous21:01 14 Apr '04  
GeneralRe: AllocateAndGetTcpExTableFromStack for Windows 2000 Pinmemberblakeo231:10 15 Apr '04  
QuestionHow to close UDP ports ? Pinmembermarcosvelasco6:21 16 Dec '03  
AnswerRe: How to close UDP ports ? PinsussAnonymous11:29 19 Dec '03  
GeneralA free tool called Active Ports can work under Windows 2K PinmemberJohannowic20:25 19 Nov '03  
GeneralRe: A free tool called Active Ports can work under Windows 2K Pinmembery0da1:30 20 Nov '03  
GeneralWindows 2000 and XP... Pinmembermarcosvelasco8:00 18 Nov '03  
GeneralRe: Windows 2000 and XP... Pinmembery0da1:10 19 Nov '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120209.1 | Last Updated 17 Nov 2003
Article Copyright 2003 by y0da
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid