Skip to content

Commit

Permalink
11
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Marotco committed Apr 9, 2019
1 parent e3b8f8e commit e27642c
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 99 deletions.
1 change: 1 addition & 0 deletions bulk_ip_lookup/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 67 additions & 86 deletions bulk_ip_lookup/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,26 @@ public void InsertIntoList(ListViewItem item)
{
try
{
if (InvokeRequired)
{
Invoke(new InsertIntoListDelegate(InsertIntoList), item);
}
else
{
listView2.Items.Add(item);
}
if (InvokeRequired) Invoke(new InsertIntoListDelegate(InsertIntoList), item);
else listView2.Items.Add(item);
}
catch(Exception ee) { MessageBox.Show(ee.ToString()); }
catch(Exception ee) { MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "InsertIntoList. Общая ошибка: " + ee.ToString() + Environment.NewLine); }
}

private int progress = 0;
/// <summary>
/// Является ли текст IP адресом
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
private static bool CheckIp(string address)
{
try
{
string[] nums = address.Split('.');
return nums.Length == 4 && nums.All(n => int.TryParse(n, out int useless)) && nums.Select(int.Parse).All(n => n < 256);
}
catch { return false; }
catch { File.AppendAllText("EventLog.txt", "CheckIp. Общая ошибка: " + address.ToString() + Environment.NewLine); return false; }
}

private void Progress_change(int step)
Expand All @@ -54,8 +53,7 @@ private void Progress_change(int step)
{
progress += step;

if (progress > 0)
Invoke((ThreadStart)delegate { progresslabel.Text = progress.ToString(); });
if (progress > 0) Invoke((ThreadStart)delegate { progresslabel.Text = progress.ToString(); });
else Invoke((ThreadStart)delegate { progresslabel.Text = ""; });
}
}
Expand All @@ -65,12 +63,13 @@ private void Progress_change(int step)
/// <param name="IP"></param>
private async void GetHostEntryAsync(object IP)
{
string ip = "";
try
{
string[] y = new string[2]; //bool lookuped = false;
try
{
string ip = (string)IP;
ip = (string)IP;
char[] trimcharachters = { ' ', '\t' };
ip = ip.Trim(trimcharachters);
y[0] = (string)IP;
Expand All @@ -80,25 +79,19 @@ private async void GetHostEntryAsync(object IP)
{
y[1] = Dns.GetHostEntry(ip).HostName;
y[0] = ip;
//lookuped = true;
}
else
{
y[1] = "incorrect IP";
// y[1] = Dns.GetHostAddressesAsync(ip).ToString();
// y[0] = ip;
}
else y[1] = "incorrect IP";
}
catch (Exception ee)
{
y[1] = ee.Message;
y[1] = ee.Message;
}
await Task.Factory.StartNew(() => InsertIntoList(new ListViewItem(y))).ConfigureAwait(false);
}
catch { }
catch { File.AppendAllText("EventLog.txt", "GetHostEntryAsync. Ошибка проверки IP: " + ip + Environment.NewLine); }
Progress_change(-1);
}
catch (Exception ee){ MessageBox.Show(ee.ToString()); }
catch (Exception ee){ MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "GetHostEntryAsync. Общая ошибка: " + ee.ToString() + Environment.NewLine); }
}

private void LinkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Expand All @@ -125,49 +118,48 @@ private void Form1_Load_1(object sender, EventArgs e)
/// <returns></returns>
private int Get_IPs_count_for_mask(int mask)
{
int count = 0;
int max = 0;
switch (mask)
{
case 24:
count = 256;
max = 256;
break;
case 25:
count = 128;
max = 128;
break;
case 26:
count = 64;
max = 64;
break;
case 27:
count = 32;
max = 32;
break;
case 28:
count = 16;
max = 16;
break;
case 29:
count = 8;
max = 8;
break;
case 30:
count = 4;
max = 4;
break;
case 31:
count = 2;
max = 2;
break;
case 32:
count = 1;
max = 1;
break;
default:
count = 0;
max = 0;
break;
}
return count;
return max;
}

private void Form1_DragEnter(object sender, DragEventArgs e)
{
try
{
if (listView2.Items != null && listView2.Items.Count != 0)
listView2.Items.Clear();
if (listView2.Items != null && listView2.Items.Count != 0) listView2.Items.Clear();
if (e.Data.GetData("FileName") is Array data1)
{
if ((data1.Length == 1) && (data1.GetValue(0) is String))
Expand All @@ -176,16 +168,14 @@ private void Form1_DragEnter(object sender, DragEventArgs e)
try
{
if (new FileInfo(filename).Length < 3000)
{
GET_DNS_NAME(File.ReadAllText(filename));
}
GET_DNS_NAME(File.ReadAllText(filename));
}
catch (Exception ee){ MessageBox.Show(ee.ToString()); }
}
}
listView2.Refresh();
}
catch(Exception ee) { MessageBox.Show(ee.ToString()); }
catch(Exception ee) { MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "Form1_DragEnter. Общая ошибка: " + ee.ToString() + Environment.NewLine); }
}

private void ListView2_MouseClick(object sender, MouseEventArgs e)
Expand All @@ -205,11 +195,6 @@ private void ОтменаToolStripMenuItem_Click(object sender, EventArgs e)
contextMenuStrip1.Hide();
}

private void PictureBox5_Click(object sender, EventArgs e)
{
//listView2.select
}


private void PictureBox1_Click(object sender, EventArgs e)
{
Expand All @@ -221,24 +206,20 @@ private void PictureBox1_Click(object sender, EventArgs e)
if (listView2.SelectedItems.Count != 0)
{
for (int i = 0; i < listView2.SelectedItems.Count; i++)
{
lines[i] += listView2.SelectedItems[i].SubItems[0].Text + "," + listView2.SelectedItems[i].SubItems[1].Text;
}
lines[i] += listView2.SelectedItems[i].SubItems[0].Text + "," + listView2.SelectedItems[i].SubItems[1].Text;
}
else
{
for (int i = 0; i < listView2.Items.Count; i++)
{
lines[i] += listView2.Items[i].SubItems[0].Text + "," + listView2.Items[i].SubItems[1].Text;
}
lines[i] += listView2.Items[i].SubItems[0].Text + "," + listView2.Items[i].SubItems[1].Text;
}
DateTime D = DateTime.Now;
string filename = "nslookup " + D.Year + "." + D.Month + "." + D.Day + " " + D.Hour + "-" + D.Minute + "-" + D.Second + ".txt";
File.WriteAllLines(filename, lines);
System.Diagnostics.Process.Start("explorer.exe", "/select, " + filename);
}
}
catch(Exception ee) { MessageBox.Show(ee.ToString()); }
catch(Exception ee) { MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "PictureBox1_Click. Общая ошибка: " + ee.ToString() + Environment.NewLine); }
}

/// <summary>
Expand All @@ -251,14 +232,12 @@ private void CopyFromView()
if (listView2.Items != null && listView2.Items.Count != 0)
{
string lines = string.Empty;
for (int i = 0; i < listView2.SelectedItems.Count; i++)
{
lines += listView2.SelectedItems[i].SubItems[0].Text + Environment.NewLine;
}
for (int i = 0; i < listView2.SelectedItems.Count; i++)
lines += listView2.SelectedItems[i].SubItems[0].Text + Environment.NewLine;
Clipboard.SetText(lines);
}
}
catch(Exception ee) { MessageBox.Show(ee.ToString()); }
catch(Exception ee) { MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "CopyFromView. Общая ошибка: " + ee.ToString() + Environment.NewLine); }
}

private void СкопироватьToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -290,11 +269,11 @@ private async void GET_DNS_NAME(string lines)
y[0] = address.ToString();
await Task.Factory.StartNew(() => InsertIntoList(new ListViewItem(y))).ConfigureAwait(false);
Progress_change(-1);
}
}
}
catch (Exception ee)
{
y[0] = ee.Message;
y[0] = ee.Message; File.AppendAllText("EventLog.txt", "GET_DNS_NAME. Ошибка поиска IP: " + ee.ToString() + Environment.NewLine);
}
await Task.Factory.StartNew(() => InsertIntoList(new ListViewItem(y))).ConfigureAwait(false);
}
Expand All @@ -303,41 +282,43 @@ private async void GET_DNS_NAME(string lines)
Regex ip_pattern = new Regex(@"\d+\.\d+\.\d+\.\d+\/\d+|\d+\.\d+\.\d+\.\d+");
MatchCollection ip_finded = ip_pattern.Matches(lines);
Invoke((ThreadStart)delegate { progresslabel.Text = ip_finded.Count.ToString(); });

for (int i = 0; i < ip_finded.Count; i++)
try
{
string fgdf = ip_finded[i].ToString();
if (fgdf.Contains("/"))
for (int i = 0; i < ip_finded.Count; i++)
{
string[] masksize = fgdf.Split('/');
string[] oktets = masksize[0].Split('.');
int masksize_int = Convert.ToInt32(masksize[1]);
if (masksize_int >= 24)
string fgdf = ip_finded[i].ToString();
if (fgdf.Contains("/"))
{
if (masksize_int <= 32)
string[] masksize = fgdf.Split('/');
string[] oktets = masksize[0].Split('.');
int masksize_int = Convert.ToInt32(masksize[1]);
if (masksize_int >= 24)
{
int ip_max = Get_IPs_count_for_mask(masksize_int);
if (ip_max > 256) ip_max = 256;
Progress_change(ip_max);
for (int j = 0; j < ip_max; j++)
if (masksize_int <= 32)
{
Thread myThread = new Thread(new ParameterizedThreadStart(GetHostEntryAsync));
myThread.Start(oktets[0] + "." + oktets[1] + "." + oktets[2] + "." + (Convert.ToInt32(oktets[3]) + j));
Progress_change(-1);
int ip_max = Get_IPs_count_for_mask(masksize_int);
if (ip_max > 255) ip_max = 255;
Progress_change(ip_max);

for (int j = 0; j < ip_max; j++)
{
Thread myThread = new Thread(new ParameterizedThreadStart(GetHostEntryAsync));
myThread.Start(oktets[0] + "." + oktets[1] + "." + oktets[2] + "." + (Convert.ToInt32(oktets[3]) + j));
Progress_change(-1);
}
}
}
}
else
{
Thread myThread = new Thread(new ParameterizedThreadStart(GetHostEntryAsync));
myThread.Start(fgdf);
}
}
else
{
Thread myThread = new Thread(new ParameterizedThreadStart(GetHostEntryAsync));
myThread.Start(fgdf);
}
}
}
catch (Exception ee){
MessageBox.Show(ee.ToString());
}
catch (Exception ee) { MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "GET_DNS_NAME. Ошибка поиска IP: " + ee.ToString() + Environment.NewLine); }
}
catch (Exception ee){MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "GET_DNS_NAME. Общая ошибка: " + ee.ToString() + Environment.NewLine); }
try { Invoke((ThreadStart)delegate { RemoveDuplicates_In_ListView(listView2); }); } catch { }//удаляем дубликаты
}
/// <summary>
Expand Down Expand Up @@ -368,7 +349,7 @@ public void RemoveDuplicates_In_ListView(ListView ListView)
}
catch (Exception ee)
{
MessageBox.Show(ee.ToString());
MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "GetHostEntryAsync. Общая ошибка: " + ee.ToString() + Environment.NewLine);
}
}
private void PictureBox2_Click(object sender, EventArgs e)
Expand Down
5 changes: 5 additions & 0 deletions bulk_ip_lookup/IP_Bulk_lookup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,15 @@
<None Include="bin\Debug\export.png" />
</ItemGroup>
<ItemGroup>
<None Include="upload.png" />
<None Include="bin\Debug\Clipboard.png" />
<None Include="bin\Debug\Clipboard_Paste.png" />
<None Include="bin\Debug\Clipboard_Copy.png" />
<None Include="bin\Debug\Folder.png" />
<None Include="Folder.png" />
<None Include="Clipboard_Copy.png" />
<None Include="Clipboard_Paste.png" />
<None Include="export.png" />
<Content Include="Icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
11 changes: 8 additions & 3 deletions bulk_ip_lookup/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Windows.Forms;

namespace IP_Bulk_lookup
Expand All @@ -11,9 +12,13 @@ internal static class Program
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
catch (Exception ee) { MessageBox.Show(ee.ToString()); File.AppendAllText("EventLog.txt", "Program.cs Общая ошибка: " + ee.ToString() + Environment.NewLine); }
}
}
}
12 changes: 11 additions & 1 deletion bulk_ip_lookup/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e27642c

Please sign in to comment.