public void SetHostDetailsAsync() { _look4HostDetails = new Thread(() => { _isLooking4HostDetails = true; HostDetailsBeforeChanged(IPAddress, new EventArgs()); try { HostName = Dns.GetHostEntry(IPTools.UInt322IPAddress(IPAddress)).HostName; } catch (Exception) { //Debug.WriteLine(IPAddress.ToString() + ": " + ex.Message); HostName = string.Empty; } try { HostMac = IPTools.GetMACFromNetworkComputer(IPTools.UInt322IPAddress(IPAddress)); } catch (Exception) { //Debug.WriteLine(IPAddress.ToString() + ": " + ex.Message); HostMac = null; } _isLooking4HostDetails = false; HostDetailsAfterChanged(IPAddress, new EventArgs()); }); _look4HostDetails.Start(); }
private void ScanPortUDP(int currentHostPort) { try { UdpClient udpClient = new UdpClient(11000); Socket socket = udpClient.Client; socket.ExclusiveAddressUse = true; socket.ReceiveTimeout = (int)(RoundtripTime * 1.1 + 1); socket.ReceiveTimeout = (int)(RoundtripTime * 1.1 + 1); socket.BeginConnect(new IPEndPoint(IPTools.UInt322IPAddress(IPAddress), currentHostPort), (IAsyncResult asyncResult) => { try { /* * Socket socketResult = asyncResult.AsyncState as Socket; * socketResult.EndConnect(asyncResult); * if (socketResult.Connected) * { * try * { * Ports.Add(new PortInfo * ( * int.Parse(socketResult.RemoteEndPoint.ToString().Split(':')[1]), * socketResult.ProtocolType, * true * ) * ); * } * catch (Exception ex) * { * Debug.WriteLine(ex.StackTrace); * } * } */ } catch (Exception) { } finally { Interlocked.Decrement(ref waitingForResponses); } }, socket ); Interlocked.Increment(ref waitingForResponses); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private void ScanPortTCP(int currentHostPort) { try { Socket socket; socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); socket.ReceiveTimeout = (int)(RoundtripTime * 1.1 + 1); socket.BeginConnect(new IPEndPoint(IPTools.UInt322IPAddress(IPAddress), currentHostPort), (IAsyncResult asyncResult) => { try { Socket socketResult = asyncResult.AsyncState as Socket; socketResult.EndConnect(asyncResult); if (socketResult.Connected) { try { Ports.Add(new PortInfo ( int.Parse(socketResult.RemoteEndPoint.ToString().Split(':')[1]), socketResult.ProtocolType, true ) ); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } } } catch { } finally { Interlocked.Decrement(ref waitingForResponses); } }, socket ); Interlocked.Increment(ref waitingForResponses); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }