Exemple #1
0
        private void pushPipeLine(ProcessIPInfo proc)
        {
            //remote IP is already logged
            //publish update
            if (netStatDict.ContainsKey(proc.RemoteIp))
            {
                var er = netStatDict[proc.RemoteIp];
                er.ProcessInfo = proc;

                if (er.IpInfo is null)
                {
                    // er.IpInfo = ips.GetIPInfo(proc).Result;
                }

                ea.GetEvent <ConnectionUpdateEvent>().Publish(er);
            }

            //new remote IP
            //get IP info and update current view of connections
            else
            {
                ips.GetIPInfo(proc.RemoteIp, (error, ipInfo) =>
                {
                    if (error == null)
                    {
                        var netstat = new NetStatItemViewModel(proc)
                        {
                            IpInfo = ipInfo, Host = GetHostByAddress(proc.RemoteIp)
                        };

                        netStatDict.Add(proc.RemoteIp, netstat);
                        ea.GetEvent <ConnectionUpdateEvent>().Publish(netstat);
                    }
                });
            }
        }
Exemple #2
0
 public NetStatItemViewModel(ProcessIPInfo proc)
 {
     ProcessInfo = proc;
     RemoteIp    = proc.RemoteIp;
 }
        public void DoWork()
        {
            var netStatOutput = NetStatService.GetNetStatOutput();


            foreach (string row in netStatOutput)
            {
                //Split it baby
                string[] tokens = Regex.Split(row, "\\s+");

                if (tokens.Length > 4 && (tokens[1].Equals("UDP") || tokens[1].Equals("TCP")))
                {
                    IPAddress ip;

                    // we only care about remote IP
                    if (tokens[3].Contains(":") && IPAddress.TryParse(tokens[3].Split(':')[0], out ip) && !tokens[3].Split(':')[0].StartsWith("192"))
                    {
                        if (!IPAddress.IsLoopback(ip))
                        {
                            var addressFamily = ip.AddressFamily;

                            if (!NetStatRegistry.ContainsKey(ip))
                            {
                                int port;
                                int pid;

                                ProcessIPInfo pinfo;



                                if (int.TryParse(tokens[5], out pid))
                                {
                                    pinfo             = new ProcessIPInfo(pid);
                                    pinfo.PID         = pid;
                                    pinfo.ProcessName = LookupProcess(pid);

                                    if (icons.ContainsKey(pinfo.ProcessName))
                                    {
                                        if (icons[pinfo.ProcessName] == null)
                                        {
                                            icons[pinfo.ProcessName] = GetProcessIcon(pid);
                                        }
                                    }
                                    else
                                    {
                                        icons.Add(pinfo.ProcessName, GetProcessIcon(pid));
                                    }

                                    pinfo.Icon = icons[pinfo.ProcessName];

                                    if (int.TryParse(tokens[3].Split(':')[1], out port))
                                    {
                                        pinfo.Port = port;
                                    }

                                    pinfo.RemoteIp         = ip.ToString();
                                    pinfo.ConnectionStatus = tokens[4];
                                    pinfo.Protocol         = tokens[1];
                                    NetStatRegistry.Add(ip, pinfo);

                                    _ea.GetEvent <NetStatReadEvent>().Publish(pinfo);
                                }
                            }
                            else
                            {
                                var knownRecord = NetStatRegistry[ip];
                                knownRecord.ConnectionStatus = tokens[4];
                                _ea.GetEvent <NetStatReadEvent>().Publish(knownRecord);
                            }
                        }
                    }
                }
            }
        }