private static int GetChromeListeningPortWithInterOp(int pid) { int port = 0; if (pid > 0) { port = TcpConnectionInfo.GetChromeListeningPortWithInterOp(pid); } return(port); }
public static int GetChromeListeningPortWithInterOp(int pid) { int port = 0; try { TcpConnectionInfo.MIB_TCPROW_OWNER_PID[] tcpConnections = TcpConnectionInfo.GetAllTcpConnections(); for (int i = 0; i < tcpConnections.Length; i++) { TcpConnectionInfo.MIB_TCPROW_OWNER_PID mIB_TCPROW_OWNER_PID = tcpConnections[i]; if (mIB_TCPROW_OWNER_PID.localAddr == 16777343u && mIB_TCPROW_OWNER_PID.owningPid == pid) { port = (int)mIB_TCPROW_OWNER_PID.LocalPort; break; } } } catch (Exception ex) { Trace.Assert(false, ex.Message); } return(port); }