public GeoIpEntry Lookup(IPAddress ipAddress)
        {
            while (InProgressCache.ContainsKey(ipAddress))
            {
                //Debug.WriteLine("GEO: entry already being looked up {0}", ipAddress);
                Thread.Sleep(50);
            }

            GeoIpEntry existing;

            if (GeoCache.TryGetValue(ipAddress, out existing))
            {
                //Debug.WriteLine("GEO: found in cache {0}", ipAddress);
                return(existing);
            }
            else
            {
                //Debug.WriteLine("GEO: NOT found in cache {0}", ipAddress);
            }

            InProgressCache.TryAdd(ipAddress, null);

            GeoIpEntry result;

            if (Ip.Instance.IsLocal(ipAddress))
            {
                result = new GeoIpEntry()
                {
                    Ip = ipAddress.ToString(), Country = "localhost", Isp = "localhost"
                }
            }
            ;
            else // TODO: else if is on local subnet
            {
                result = LookupFromWeb(ipAddress);
            }

            GeoCache.TryAdd(ipAddress, result);

            string bleh;

            InProgressCache.TryRemove(ipAddress, out bleh);

            return(result);
        }
Esempio n. 2
0
        public TcpConnection(ushort localPort,
                             string localAddress,
                             ushort remotePort,
                             string remoteAddress,
                             int processId,
                             TcpState state,
                             string pendingText,
                             string loadingText)
        {
            this.LocalPort     = localPort;
            this.LocalAddress  = localAddress;
            this.RemotePort    = remotePort;
            this.RemoteAddress = remoteAddress;
            this.ProcessId     = processId;
            this.State         = state;
            this.PendingText   = pendingText;
            this.LoadingText   = loadingText;

            RemoteMacAddressAsync             = PendingText;
            RemoteMacAddressManufacturerAsync = CreatePendingInstance <KnownMacManufacturer>();
            Task.Factory.StartNew(() =>
            {
                RemoteMacAddressAsync = LoadingText;
                var remoteMacAddress  = IpHlpApi.ResolvePhysicalAddress(RemoteAddress);
                RemoteMacAddressAsync = remoteMacAddress != null && !string.IsNullOrWhiteSpace(remoteMacAddress.ToString()) ? remoteMacAddress.ToString() : null;

                RemoteMacAddressManufacturerAsync = CreateLoadingInstance <KnownMacManufacturer>();
                RemoteMacAddressManufacturerAsync = KnownMacManufacturers.Instance.Lookup(RemoteMacAddressAsync);
            });

            LocalPortCommonServiceAsync = CreatePendingInstance <CommonService>();
            Task.Factory.StartNew(() =>
            {
                LocalPortCommonServiceAsync = CreateLoadingInstance <CommonService>();
                LocalPortCommonServiceAsync = CommonTcpServices.Instance.Lookup(LocalPort);
            });

            RemotePortCommonServiceAsync = CreatePendingInstance <CommonService>();
            Task.Factory.StartNew(() =>
            {
                RemotePortCommonServiceAsync = CreateLoadingInstance <CommonService>();
                RemotePortCommonServiceAsync = CommonTcpServices.Instance.Lookup(RemotePort);
            });

            RunningProcessAsync = CreatePendingInstance <RunningProcess>();
            Task.Factory.StartNew(() =>
            {
                RunningProcessAsync = CreateLoadingInstance <RunningProcess>();
                RunningProcessAsync = ProcessMonitor.Instance.GetProcessInfo(ProcessId);
            });

            RemoteHostnameAsync = PendingText;
            Task.Factory.StartNew(() =>
            {
                RemoteHostnameAsync = LoadingText;
                RemoteHostnameAsync = DnsHostCache.Instance.Resolve(IPAddress.Parse(RemoteAddress));
            });

            LocalHostnameAsync = PendingText;
            Task.Factory.StartNew(() =>
            {
                LocalHostnameAsync = LoadingText;
                LocalHostnameAsync = DnsHostCache.Instance.Resolve(IPAddress.Parse(LocalAddress));
            });

            RemoteGeoAsync = CreatePendingInstance <GeoIpEntry>();
            Task.Factory.StartNew(() =>
            {
                RemoteGeoAsync = CreateLoadingInstance <GeoIpEntry>();
                RemoteGeoAsync = GeoIpCache.Instance.Lookup(IPAddress.Parse(RemoteAddress));
            });
        }