您的位置:首页 > 理论基础 > 计算机网络

获取系统系统所有TCP以及UDP端口使用情况

2009-06-19 12:50 579 查看
GetTcpTable


GetTcpTable

The GetTcpTable
function retrieves the TCP connection table.

DWORD
GetTcpTable(

PMIB_TCPTABLE
pTcpTable

,
// buffer for the connection table
PDWORD
pdwSize

,
// size of the buffer
BOOL
bOrder

// sort the table?
);

Parameters

pTcpTable

[out] Pointer to a buffer that receives the TCP connection table as a MIB_TCPTABLE

structure.

pdwSize

[in, out] On input, specifies the size of the buffer pointed to by the
pTcpTable
parameter.
On output, if the buffer is not large enough to hold the returned connection
table, the function sets this parameter equal to the required buffer size.

bOrder

[in] Specifies whether the connection table should be sorted. If this
parameter is TRUE, the table is sorted in the order of:

Local IP address

Local port

Remote IP address

Remote port

Return Values

If the function succeeds, the return value is NO_ERROR.

If the function fails, use FormatMessage

to obtain the message
string for the returned error.

Requirements

Windows NT/2000 or later:
Requires Windows NT 4.0 SP4 or
later.

Windows 95/98/Me:
Requires Windows 98 or
later.

Header:
Declared in Iphlpapi.h.

Library:
Use
Iphlpapi.lib.

MIB_TCPTABLE


MIB_TCPTABLE

The MIB_TCPTABLE
structure contains a table of TCP connections.

typedef struct _MIB_TCPTABLE {
DWORD      dwNumEntries
;    // number of entries in the table
MIB_TCPROW table
[ANY_SIZE]; // array of TCP connections
} MIB_TCPTABLE, *PMIB_TCPTABLE;

Members

dwNumEntries

Specifies the number of entries in the table.

table[ANY_SIZE]

Pointer to a table of TCP connections implemented as an array of MIB_TCPROW

structures.

MIB_TCPROW


MIB_TCPROW

The MIB_TCPROW
structure contains information for a TCP
connection.

typedef struct _MIB_TCPROW {
DWORD   dwState
;        // state of the connection
DWORD   dwLocalAddr
;    // address on local computer
DWORD   dwLocalPort
;    // port number on local computer
DWORD   dwRemoteAddr
;   // address on remote computer
DWORD   dwRemotePort
;   // port number on remote computer
} MIB_TCPROW, *PMIB_TCPROW;

Members

dwState

Specifies the state of the TCP connection. This member can have one of the
following values.
ValueDescription
MIB_TCP_STATE_CLOSEDTo be determined.
MIB_TCP_STATE_LISTENTo be determined.
MIB_TCP_STATE_SYN_SENTTo be determined.
MIB_TCP_STATE_SYN_RCVDTo be determined.
MIB_TCP_STATE_ESTABTo be determined.
MIB_TCP_STATE_FIN_WAIT1To be determined.
MIB_TCP_STATE_FIN_WAIT2To be determined.
MIB_TCP_STATE_CLOSE_WAITTo be determined.
MIB_TCP_STATE_CLOSINGTo be determined.
MIB_TCP_STATE_LAST_ACKTo be determined.
MIB_TCP_STATE_TIME_WAITTo be determined.
MIB_TCP_STATE_DELETE_TCBTransmission Control Block (TCB)
deleted.
dwLocalAddr

Specifies the address for the connection on the local computer.

dwLocalPort

Specifies the port number for the connection on the local computer.

dwRemoteAddr

Specifies the address for the connection on the remote computer.

dwRemotePort

Specifies the port number the connection on the remote computer.

GetUdpTable


GetUdpTable

The GetUdpTable
function retrieves the User Datagram Protocol (UDP)
listener table.

DWORD
GetUdpTable(

PMIB_UDPTABLE
pUdpTable

,
// buffer for the listener table
PDWORD
pdwSize

,
// size of buffer
BOOL
bOrder

// sort the table?
);

Parameters

pUdpTable

[out] Pointer to a buffer that receives the UDP listener table as a MIB_UDPTABLE

structure.

pdwSize

[in, out] On input, specifies the size of the buffer pointed to by the
pUdpTable
parameter.
On output, if the buffer is not large enough to hold the returned listener
table, the function sets this parameter equal to the required buffer size.

bOrder

[in] Specifies whether the returned table should be sorted. If this
parameter is TRUE, the table is sorted in the order of:

IP address

Port

Return Values

If the function succeeds, the return value is NO_ERROR.

If the function fails, use FormatMessage

to obtain the message
string for the returned error.

Requirements

Windows NT/2000 or later:
Requires Windows NT 4.0 SP4 or
later.

Windows 95/98/Me:
Requires Windows 98 or
later.

Header:
Declared in Iphlpapi.h.

Library:
Use
Iphlpapi.lib.

MIB_UDPTABLE


MIB_UDPTABLE

The MIB_UDPTABLE
structure contains a table of MIB_UDPROW

structures.

typedef struct _MIB_UDPTABLE {
DWORD       dwNumEntries
;    // number of entries in the table
MIB_UDPROW  table
[ANY_SIZE]; // table of MIB_UDPROW structs
} MIB_UDPTABLE, *PMIB_UDPTABLE;

Members

dwNumEntries

Specifies the number of entries in the table.

table[ANY_SIZE]

Pointer to an array of MIB_UDPROW

structures.

MIB_UDPROW


MIB_UDPROW

The MIB_UDPROW
structure contains address information for sending and
receiving User Datagram Protocol (UDP) datagrams.

typedef struct _MIB_UDPROW {
DWORD   dwLocalAddr
;    // IP address on local computer
DWORD   dwLocalPort
;    // port number on local computer
} MIB_UDPROW, *PMIB_UDPROW;

Members

dwLocalAddr

Specifies the IP address on the local computer.

dwLocalPort

Specifies the port number on the local computer.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐