Check if a port is open

前端 未结 10 924
萌比男神i
萌比男神i 2020-12-08 10:37

I can\'t seem to find anything that tells me if a port in my router is open or not. Is this even possible?

The code I have right now doesn\'t really seem to work...<

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 11:10

    public string GetAvailablePort()
            {int startingPort=1000;
                string portnumberinformation = string.Empty;
                IPEndPoint[] endPoints;
                List portArray = new List();
                IPGlobalPr`enter code here`operties properties = IPGlobalProperties.GetIPGlobalProperties();`enter code here`
    
    
                //getting active tcp listners 
                endPoints = properties.GetActiveTcpListeners();
                portArray.AddRange(from n in endPoints
                                   where n.Port >= startingPort
                                   select n.Port);    
    
                portArray.Sort();
    
                for (int i = 0; i < portArray.Count; i++)
                {
                    if (check condition)
                    {
                        do somting
                    }
                }
    
                return portnumberinformation;
            }
    

提交回复
热议问题