function IpAddressToString(Addr: DWORD):
string;
var
InAddr: TInAddr;
begin
InAddr.S_addr := Addr;
Result := inet_ntoa(InAddr);
end;
function TCPStateToStr(status: integer):
string;
begin
status := status - 1;
case status
of
0: result := '
closed';
1: result := '
listen';
2: result := '
SYN_Sent';
3: result := '
SYN_Rcvd';
4: result := '
established';
5: result := '
Fin wait 1';
6: result := '
Fin wait 2';
7: result := '
Close wait';
8: result := '
closing';
9: result := '
last Ack.';
10: result := '
time wait';
11: result := '
delete TCB';
end;
end;
function GetIPInfos: IPInfo;
var
TCPTable: PMibTcpTable;
UDPTable: PMibUdptable;
NumEntriesTCP: DWORD;
NumEntriesUDP: DWORD;
dwSizeTCP: DWORD;
dwSizeUDP: DWORD;
i: Integer;
begin
Setlength(result, 0);
VVGetTcpTable(TCPTable, dwSizeTCP, True);
NumEntriesTCP := TCPTable.dwNumEntries;
if TCPTable <>
nil then
begin
SetLength(result, NumEntriesTCP);
for i := 0
to NumEntriesTCP - 1
do
begin
result[i].Protokoll := '
TCP';
result[i].localIP := IpAddressToString(TCPTable^.table[i].dwLocalAddr);
result[i].localPort := IntToStr(TCPTable^.table[i].dwLocalPort);
result[i].remoteIP := IpAddressToString(TCPTable^.table[i].dwRemoteAddr);
result[i].remotePort := IntToStr(TCPTable^.table[i].dwRemotePort);
result[i].Status := TCPTable^.table[i].dwState;
end;
end;
FreeMem(TCPTable, dwSizeTCP);
VVGetUdpTable(UDPTable, dwSizeUDP, True);
if UDPTable <>
nil then
begin
NumEntriesUDP := UDPTable.dwNumEntries;
SetLength(result, NumEntriesTCP + NumEntriesUDP);
for i := NumEntriesTCP
to NumEntriesTCP + NumEntriesUDP - 1
do
begin
result[i].Protokoll := '
UDP';
result[i].localIP := IpAddressToString(UDPTable^.table[i].dwLocalAddr);
result[i].localPort := IntToStr(UDPTable^.table[i].dwLocalPort);
end;
end;
FreeMem(UDPTable, dwSizeUDP);
end;