/// <summary> /// Determines whether the current request is on localhost. /// </summary> /// <returns> /// <c>true</c> if current request is localhost; otherwise, <c>false</c>. /// </returns> private static bool IsLocalhost() { bool localHost = false; try { System.Net.IPAddress address = System.Net.IPAddress.Parse(HttpContext.Current.Request.UserHostAddress); Debug.WriteLine("IP Address of user: "******"404Handler"); IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); Debug.WriteLine("Host Entry of local computer: " + host.HostName, "404Handler"); localHost = address.Equals(IPAddress.Loopback) || (Array.IndexOf(host.AddressList, address) >= 0); } catch { // localhost is false } return(localHost); }
string FindDevice() { BeginStep("Transmit multicast PROBE message"); LogStepEvent("Retransmit once per 5 seconds until a response is received or timeout (no more than 50 times)"); DeviceFinder finder = new DeviceFinder(_nic.IP, _semaphore.StopEvent); finder.OnProgress += finder_OnProgress; Uri uri = new Uri(_cameraAddress); System.Net.IPAddress ip = System.Net.IPAddress.Parse(uri.Host); DeviceFinder.FindDeviceDelegate del = new DeviceFinder.FindDeviceDelegate(finder.ProbeDevice); IAsyncResult result = del.BeginInvoke(ip, 50, 5000, null, null); WaitHandle[] handles = new WaitHandle[] { _semaphore.StopEvent, result.AsyncWaitHandle }; int handle = WaitHandle.WaitAny(handles); if (handle == 0) { finder.Stop(); throw new StopEventException(); } string data = del.EndInvoke(result); if (!string.IsNullOrEmpty(data)) { LogStepEvent(string.Format("PROBE match message: {0}", data)); } StepPassed(); Assert(data != null, "Device not found", "Check that answer has been received"); return(data); }