Click here to Skip to main content
Click here to Skip to main content

Enhance netstat

, 16 Nov 2003
Rate this:
Please Sign up or sign in to vote.
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.

Sample Image - enetstat.jpg


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.


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(

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

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

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.


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

Web Developer
Romania Romania
No Biography provided

Comments and Discussions

GeneralRe: Windows 2000 and XP... Pinmembery0da19-Nov-03 0:10 
GeneralRe: Windows 2000 and XP... PinsussAnonymous3-Dec-03 23:54 
GeneralVery good PinmemberDaniel Turini17-Nov-03 11:34 
GeneralRe: Very good Pinmembery0da18-Nov-03 2:46 

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 17 Nov 2003
Article Copyright 2003 by y0da
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid