This is the answer to my questions.
How to list binded/used TCP port in C#. Used modified code from jro
static void ListUsedTCPPort(ref ArrayList usedPort)
{
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpListeners();
IEnumerator myEnum = tcpConnInfoArray.GetEnumerator();
while (myEnum.MoveNext())
{
IPEndPoint TCPInfo = (IPEndPoint)myEnum.Current;
usedPort.Add(TCPInfo.Port);
}
}
Original questions. This is how i list TCP port using C#. It is modified code i found in this forum(forgot exactly where i got it. If you are the original developer, notify me and ill put credits where due.)
//List used tcp port
static void ListUsedTCPPort(ref ArrayList usedPort)
{
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
IEnumerator myEnum = tcpConnInfoArray.GetEnumerator();
while (myEnum.MoveNext())
{
TcpConnectionInformation TCPInfo = (TcpConnectionInformation)myEnum.Current;
usedPort.Add(TCPInfo.LocalEndPoint.Port);
}
}
Problem is, the results is different from used tcp port listed in TCPview(Protocol-TCP, Local port). By the way, i do know that this list used TCP port at the EXACT time its called. What did i did wrong?