Esempio n. 1
0
        /// <summary>
        /// 在线批量查询IP地址
        /// </summary>
        /// <param name="ipArr"></param>
        private void OnlineFindIPInfo(object ipArr)
        {
            string[] tempIpArr = (string[])ipArr;
            setBtnEnable(false);
            //onlineSearchProgressBar.Value = 0;
            setProgressBarValue(onlineSearchProgressBar, 0);
            //校验IP列表的合法性
            Regex reg = new Regex(@"((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)");

            //按每一行进行查找
            string resultMsg = "";

            for (int i = 0; i < tempIpArr.Length; i++)
            {
                setProgressBarValue(onlineSearchProgressBar, i + 1);
                log("查询进行中[ " + i + "/" + tempIpArr.Length + " ]...");
                if (tempIpArr[i] != "")
                {
                    try
                    {
                        string ip = reg.Match(tempIpArr[i]).Value;

                        string tempStr = ip + "," + string.Join(",", IP.OnlineFind(ip));
                        for (int __count = Regex.Matches(tempStr, @",").Count; __count < 2; __count++)
                        {
                            tempStr += ",";
                        }
                        tempStr += "\r\n";

                        resultMsg += tempStr;
                    }
                    catch
                    {
                        resultMsg += tempIpArr[i] + ",不合法的IP地址,\r\n";
                    }
                }
                else
                {
                    resultMsg += ",,\r\n";
                }
            }
            addResult(resultMsg);

            setBtnEnable(true);

            setProgressBarValue(onlineSearchProgressBar, 0);
        }
Esempio n. 2
0
        int searchType = 0;//查询类型:0,离线;1,在线(百度);

        /// <summary>
        /// 离线查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnIPSeach_Click(object sender, EventArgs e)
        {
            searchType = 0;
            if (txtIPList.Text == "")
            {
                MessageBox.Show("请输入要查找的IP地址");
                return;
            }

            //校验IP列表的合法性
            Regex reg = new Regex(@"((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)");

            //按每一行进行查找
            IP.EnableFileWatch = true;
            IP.Load("17monipdb.dat");

            string resultMsg = "";

            string[] ipArr = txtIPList.Text.Split('\n');
            for (int i = 0; i < ipArr.Length; i++)
            {
                if (ipArr[i] != "")
                {
                    try
                    {
                        string ip = reg.Match(ipArr[i]).Value;

                        resultMsg += ip + "," + string.Join(",", IP.Find(ip)) + "\r\n";
                    }
                    catch
                    {
                        resultMsg += ipArr[i] + ",不合法的IP地址,,,\r\n";
                    }
                }
                else
                {
                    resultMsg += ",,,,\r\n";
                }
            }
            txtResult.Text = resultMsg;
        }
Esempio n. 3
0
        /// <summary>
        /// 查询本机IP
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLocalIP_Click(object sender, EventArgs e)
        {
            //http://api.ipip.net/api.php?a=ipdb
            //113.119.134.38|20150801|http://s.qdcdn.com/17mon/17monipdb.dat

            IP.EnableFileWatch = true;
            IP.Load("17monipdb.dat");
            string getIPDBUrl = "http://api.ipip.net/api.php?a=ipdb";

            WebRequest  webReq  = WebRequest.Create(getIPDBUrl);
            WebResponse webResp = webReq.GetResponse();
            Stream      stream  = webResp.GetResponseStream();

            StreamReader sr   = new StreamReader(stream, Encoding.UTF8);
            string       html = sr.ReadToEnd();

            sr.Close();
            stream.Close();

            string ip = html.Split('|')[0];

            txtResult.Text = ip + "," + string.Join(",", IP.Find(ip)) + "\r\n";
        }