private void Start(object o) { try { Station station = (Station)o; WebClient client = new WebClient(); Stream openRead = client.OpenRead(String.Format(ConfigurationService.ShoutcastPlaylistURL, station.ID)); StreamReader reader = new StreamReader(openRead); bool foundIP = false; while (!reader.EndOfStream && !foundIP) { string line = reader.ReadLine(); Regex regex = new Regex(@"(?<ip>[0-9]+.[0-9]+.[0-9]+.[0-9]+):(?<port>[0-9]+)"); Match match = regex.Match(line); if (match.Success) { String IP = match.Groups["ip"].Value; int port = Int32.Parse(match.Groups["port"].Value); IPAddress parsedIPAddress = IPAddress.Parse(IP); if (parsedIPAddress != null) { IPEndPoint endPoint = new IPEndPoint(parsedIPAddress, port); PortProber prober = new PortProber(endPoint); station.IsAlive = prober.ProbeMachine(); foundIP = true; } } } } catch (Exception e) { } }
private void Start(object o) { KeyValuePair<IPEndPoint, int> pair = (KeyValuePair<IPEndPoint, int>) o; PortProber prober = new PortProber(pair.Key); bool success = prober.ProbeMachine(); results.Add(new KeyValuePair<int, bool>(pair.Value, success)); }
public void ProbePort_WithValidExternalAddressAndValidPort_ReturnsTrue() { PortProber prober = new PortProber(new IPAddress(new byte[] { 216, 239, 59, 104 }), 80); Assert.IsTrue(prober.ProbeMachine(), "Should have succeeded."); }
public void ProbePort_WithValidAddressAndValidPort_ReturnsTrue() { PortProber prober = new PortProber(new IPAddress(new byte[]{160,79,128,242}), 8004); Assert.IsTrue(prober.ProbeMachine(), "Should have succeeded."); }
public void ProbePort_WithInvalidAddress_ReturnsFalse() { PortProber prober = new PortProber(new IPAddress(new byte[]{23,43,54,23}), 32); Assert.IsFalse(prober.ProbeMachine(), "Should have failed."); }
public void PortProber_Initialise_IsNotNull() { PortProber prober = new PortProber(new IPAddress(new byte[] {21, 12, 43, 54}), 23); Assert.IsNotNull(prober, "Failed to initialise."); }