I'm working on a small project and I'm having an issue. I have it set up so a user can paste a series of IP Addresses into a multiline textbox and ping each IP. I'm currently taking each value that's entered into the input box and adding it to a string array. The problem I'm having is converting each value in that array to an IP using the IPAddress.Parse method. Any tips would be greatly appriciated. It's in c#
using System;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Net;
namespace MultiPing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pingBtn_Click(object sender, EventArgs e)
{
try
{
int i;
string[] allLines = inputBox.Text.Split('\n');
Ping pingSender = new Ping();
for (i = 0; i < allLines.Length; i++)
{
try
{
IPAddress address = IPAddress.Parse(allLines[]);
PingReply reply = pingSender.Send(address);
if (reply.Status == IPStatus.Success)
{
outputBox.Text = address + " is up \n";
}
else
{
outputBox.Text = address + " is down \n";
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
IPAddress address = IPAddress.Parse(allLines[]);<-- supposed to beallLines[i]?forloop. Cant see why you wouldnt use aforeachhere.