Exemplo n.º 1
0
        private static List <TCPPortCheck> CheckPorts(List <NetworkAdapterData> IPs, int PortNumber)
        {
            List <TCPPortCheck> IPchecks = new List <TCPPortCheck>();

            foreach (var adapterData in MetaDataGenerator.GetPCMetaData().LanData)
            {
                TCPPortCheck currentPortCheck = new TCPPortCheck();
                try
                {
                    var clientWAN = new TcpClient();
                    var resultWAN = clientWAN.BeginConnect(adapterData.AdapterIP, PortNumber, null, null);

                    resultWAN.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(2));
                    if (!clientWAN.Connected)
                    {
                        currentPortCheck.IPAddress = adapterData.AdapterIP;
                        currentPortCheck.IsOpen    = false;
                        IPchecks.Add(currentPortCheck);
                    }
                    else
                    {
                        currentPortCheck.IPAddress = adapterData.AdapterIP;
                        currentPortCheck.IsOpen    = true;
                        clientWAN.EndConnect(resultWAN);
                        IPchecks.Add(currentPortCheck);
                    }
                }
                catch { }
            }
            return(IPchecks);
        }
Exemplo n.º 2
0
 public static PCMetaData GetPCMetaData()
 {
     return(MetaDataGenerator.GetPCMetaData());
 }