深圳市众华智联科技有限公司

新闻类别

新闻资讯

#define JUST_CN_JP using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace IP_Analyse { public partial class Form1 : Form { DataSet allData = new DataSet(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //add a datatable to contain all data. DataTable dataT = new DataTable("AllData"); DataColumn country = new DataColumn("Country"); DataColumn ip = new DataColumn("IP"); DataColumn length = new DataColumn("Length"); DataColumn ipStart = new DataColumn("IPStart"); DataColumn ipEnd = new DataColumn("IPEnd"); dataT.Columns.Add(country); dataT.Columns.Add(ip); dataT.Columns.Add(length); dataT.Columns.Add(ipStart); dataT.Columns.Add(ipEnd); allData.Tables.Add(dataT); dataGridView1.DataSource = allData.Tables["AllData"]; //open file OpenFileDialog sourceFileDl = new OpenFileDialog(); sourceFileDl.Filter="文本文件|*.txt"; if (sourceFileDl.ShowDialog() == DialogResult.OK) { string fName = sourceFileDl.FileName; string[] dataRead = File.ReadAllLines(fName); //MessageBox.Show(dataRead.Length.ToString()); for (int i = 0; i < dataRead.Length; i++) { analyseDataLine(dataRead[i]); } } } private void analyseDataLine(string inputStr) { // apnic|AU|ipv4|223.255.248.0|1024|20100730|allocated string[] strSpliter = inputStr.Split('|'); #if JUST_CN_JP if ((strSpliter[1].Trim().ToUpper() == "CN") || (strSpliter[1].Trim().ToUpper() == "usa"))//IP数据。 #endif { DataRow dataToAdd = allData.Tables["AllData"].NewRow(); dataToAdd["country"] = strSpliter[1].Trim(); dataToAdd["IP"] = strSpliter[3].Trim(); dataToAdd["Length"] = strSpliter[4].Trim(); //change IP address to a uint64 string[] ipParts = strSpliter[3].Trim().Split('.'); UInt64 ipStart = (((UInt64.Parse(ipParts[0].Trim())) << 24) & 0xFF000000) | (((UInt64.Parse(ipParts[1].Trim())) << 16) & 0xFF0000) | (((UInt64.Parse(ipParts[2].Trim())) << 8) & 0xFF00) | ((UInt64.Parse(ipParts[3].Trim())) & 0xFF); UInt64 ipEnd = ipStart + UInt64.Parse(strSpliter[4].Trim()); dataToAdd["IPStart"] = ipStart; dataToAdd["ipEnd"] = ipEnd; allData.Tables["AllData"].Rows.Add(dataToAdd); } } private void button2_Click(object sender, EventArgs e) { SaveFileDialog fileSave = new SaveFileDialog(); fileSave.Filter = "XML文件|*.xml"; if (fileSave.ShowDialog() == DialogResult.OK) { allData.WriteXml(fileSave.FileName); } } } }

首页 关于我们  |  产品中心  |  客户服务  |  新闻资讯  |  联系我们                                        电   话: 0755-28392373 (总机)  邮   箱:info@pentasmart.com.cn 

 

友情链接:pentasmart   |  众华智联官方微博   |   众华智联中国官网                          版权所有 © 深圳市众华智联科技有限公司Copy Right © (2016)   |   备案号:粤ICP备16051695号

 


简洁大气设计风格的网页右侧扁平化滑动在线客服代码