Guest User

Guest User

  • Tech Writer
  • 3
  • 573

convert ipnumber

Jun 30 2018 4:15 AM
I have 2 datagridview(same). I want to transform 2.datagridview to ipnumber from ipadress with this code piece;

long result = 0;

if (!string.IsNullOrWhiteSpace(ip))

{

string[] temp = ip.Trim().Split('.');

if (temp != null && temp.Count() > 3)

{

string[] lastPart = temp[3].Split(':', ',', ' ');//Port verisinin gelmesi durumunda portu ayirmak için kullaniyoruz

result = long.Parse(temp[0]) * 256 * 256 * 256 +

long.Parse(temp[1]) * 256 * 256 +

long.Parse(temp[2]) * 256 +

//long.Parse(temp[3]);

long.Parse(lastPart[0]);

}

}


 

and my both 2 datagirdview is now:

0.0.0.0 / 0.0.255.255 /    usa ......(600.000 row) 3column

this my project s code

sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.ShowDialog();
textBox1.Text = op.FileName;
}

private void button2_Click(object sender, EventArgs e)
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("IPStart");
dataTable.Columns.Add("IPEnd");
dataTable.Columns.Add("Country");
string Filepath = textBox1.Text;
StreamReader streamreader = new StreamReader(Filepath);
string[] totalData = new string[File.ReadAllLines(Filepath).Length];
totalData = streamreader.ReadLine().Split(',');
while (!streamreader.EndOfStream)
{
totalData = streamreader.ReadLine().Split(',');
dataTable.Rows.Add(totalData[0],totalData[1],totalData[2]);

}
dataGridView1.DataSource = dataTable;
}

private void button3_Click(object sender, EventArgs e)
{

DataTable dataTable = new DataTable();
dataTable.Columns.Add("IPStart");
dataTable.Columns.Add("IPEnd");
dataTable.Columns.Add("Country");
string Filepath = textBox1.Text;
StreamReader streamreader = new StreamReader(Filepath);
string[] totalData = new string[File.ReadAllLines(Filepath).Length];
totalData = streamreader.ReadLine().Split(',');
while (!streamreader.EndOfStream)
{
totalData = streamreader.ReadLine().Split(',');
dataTable.Rows.Add(totalData[0], totalData[1], totalData[2]);

}
dataGridView2.DataSource = dataTable;
}
}
} 

Answers (1)