Exemplo n.º 1
0
        /// <summary>
        /// 单次异步Ping完成事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ping_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            // 实例化新节点
            Hop newHop = new Hop();

            newHop.Distance = nowDist.ToString();
            newHop.IP       = e.Reply.Address.ToString();
            newHop.Delay    = e.Reply.RoundtripTime.ToString();
            SetHopDetails(newHop);
            HopList.Add(newHop);
            // 设置列表显示
            TraceGrid.ItemsSource = HopList;
            // 地图页面新增节点数据
            if (newHop.Lon != null &&
                newHop.Lat != null)
            {
                traceMap.InvokeScript("AddNode", new object[] { newHop.Lon, newHop.Lat });
            }
            // 尚未跟踪到目标主机
            if (e.Reply.Address.ToString().Equals(DestIP) != true)
            {
                ++nowDist;
                Ping        ping    = new Ping();
                PingOptions options = new PingOptions(nowDist, true);
                ping.PingCompleted += Ping_PingCompleted;
                byte[] buf = new byte[256];
                ping.SendAsync(DestIP, 1000, buf, options, null);
            }
            else
            {
                EndTraceRT(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取新的字符串行动作
        /// </summary>
        /// <param name="result"></param>
        private void ReadCMDLineAction(string line)
        {
            // 跳数(距离)
            int dist = 0;

            string[] items = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (items.Length >= 5 && Int32.TryParse(items[0], out dist) == true)
            {
                // 时延数量
                int num_delay = 0;
                // 实例化新节点
                Hop newHop = new Hop();
                newHop.Distance = items[0];
                int index_items = 1;
                for (; index_items < items.Length && num_delay < 3; index_items++)
                {
                    if (items[index_items].Equals("ms") == false &&
                        items[index_items].Equals("毫秒") == false)
                    {
                        newHop.Delay += items[index_items];
                        if (++num_delay != 3)
                        {
                            newHop.Delay += " / ";
                        }
                    }
                }
                while (items[index_items].Equals("ms") == true ||
                       items[index_items].Equals("毫秒") == true)
                {
                    ++index_items;
                }
                newHop.IP = items[index_items];
                SetHopDetails(newHop);
                HopList.Add(newHop);
                TraceGrid.ItemsSource = HopList;
                if (newHop.Lon != null &&
                    newHop.Lat != null)
                {
                    traceMap.InvokeScript("AddNode", new object[] { newHop.Lon, newHop.Lat });
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取单跳的详细数据
        /// </summary>
        /// <param name="node">单跳节点</param>
        private void SetHopDetails(Hop node)
        {
            WebRequest   request  = WebRequest.Create("http://ip-api.com/line/" + node.IP + "?lang=zh-CN");
            WebResponse  response = request.GetResponse();
            Stream       s        = response.GetResponseStream();
            StreamReader sr       = new StreamReader(s);
            // IP地址数据是否有效
            string str_status = sr.ReadLine();

            if (str_status.Equals("success") == true)
            {
                // 设置地理位置
                node.Geo = sr.ReadLine();
                // 国家编号
                sr.ReadLine();
                // 区域编号
                sr.ReadLine();
                // 设置地理位置(区域名称)
                node.Geo += " " + sr.ReadLine();
                // 设置地理位置(城市名称)
                node.Geo += " " + sr.ReadLine();
                // 邮政编码
                sr.ReadLine();
                // 设置纬度
                node.Lat = sr.ReadLine();
                // 设置经度
                node.Lon = sr.ReadLine();
                // 时区
                sr.ReadLine();
                // 设置互联网服务提供商
                node.ISP = sr.ReadLine();
                // 设置组织机构
                node.Org = sr.ReadLine();
                // 设置自治系统
                node.AS = sr.ReadLine();
            }
            sr.Dispose();
            sr.Close();
            s.Dispose();
            s.Close();
        }