namespace AOConfig
{
public partial class MassScript : Form
{
public MassScript()
{
InitializeComponent();
}
private void OpenFileBtn_Click(object sender, EventArgs e)
{
SourceList.Items.Clear();
using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Text Documents(*.txt)|*.txt", ValidateNames = true, Multiselect = false })
{
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] lines = System.IO.File.ReadAllLines(ofd.FileName);
List<string> list = new List<string>();
foreach(string IPAddr in lines)
{
list.Add(IPAddr);
SourceList.Items.Add(IPAddr);
Count_label.Text = SourceList.Items.Count.ToString();
}
}
}
}
private void CheckBtn_Click(object sender, EventArgs e)
{
Ping ping = new Ping();
}
}
}
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;
using System.Net.NetworkInformation;
namespace AOConfig
{
public partial class MassScript : Form
{
public MassScript()
{
InitializeComponent();
}
private void OpenFileBtn_Click(object sender, EventArgs e)
{
SourceList.Items.Clear();
using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Text Documents(*.txt)|*.txt", ValidateNames = true, Multiselect = false })
{
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] switchList = System.IO.File.ReadAllLines(ofd.FileName,Encoding.UTF8);
SourceList.Items.AddRange(switchList);
TotalCount_label.Text = SourceList.Items.Count.ToString();
}
}
}
private void StartPingBtn_Click(object sender, EventArgs e)
{
Ping switchPing = new Ping();
PingReply pingReply = null;
PingOptions options = new PingOptions();
options.DontFragment = true;
// options.Ttl = 64;
int timeout = 1000;
foreach (var Item in SourceList.Items)
{
string Host = SourceList.GetItemText(Item);
byte[] buffer = Encoding.ASCII.GetBytes(Host);
pingReply = switchPing.Send(Host, timeout, buffer, options);
if (pingReply.Status == IPStatus.Success)
{
LiveList.Items.Add(Host);
LiveCount_label.Text = LiveList.Items.Count.ToString();
}
else
{
continue;
}
}
}
}
}
namespace TestWindowsForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SourceList.Items.Clear();
using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Text Documents(*.txt)|*.txt", ValidateNames = true, Multiselect = false })
{
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] lines = { "sdfs", "sdfesd", "dfefgse" };
// Если List<string> не используешь убери
List<string> list = new List<string>();
list.AddRange(lines);
SourceList.Items.AddRange(lines);
Count_label.Text = SourceList.Items.Count.ToString();
// Избавляемся от не нужноно нам цикла
//foreach (string IPAddr in lines)
//{
// list.Add(IPAddr);
// SourceList.Items.Add(IPAddr);
// Count_label.Text = SourceList.Items.Count.ToString();
//}
}
}
}
public void TestingIp()
{
object delItem = null;
foreach (var item in SourceList.Items)
{
// Тут делаешь всё что тебе вздумается
// Получаем текст элемента
string textItem = SourceList.GetItemText(item);
// Хотим удалить определённый элемент
if (textItem == "sdfs")
delItem = item;
}
// Удаляем
SourceList.Items.Remove(delItem);
}
private void button_Click(object sender, EventArgs e)
{
TestingIp();
}
}
}