So I am trying to build a range pinger which job will be to use 2 IP addresses and then compare each to calculate which addresses must be pinged.
The problem is that after whole day of thinking of how to create code which would check for range I came up with nothing, so I came here.
Example, I am having an address range from: 192.168.0.1 to: 192.168.1.1 which means I want to ping 254 IP addresses.
How to make this happend?
What I must check in my IF statements?
As of right now I have this:
public partial class PingIPRange : Form
{
public PingIPRange()
{
InitializeComponent();
txtFrom.Text = "74.125.225.20";
txtTo.Text = "74.125.225.30";
}
private void btnPing_Click(object sender, EventArgs e)
{
//for (int i = 0; i < int.Parse(txtRepeat.Text); i++)
//{
CalculateRange(txtFrom.Text, txtTo.Text);
//}
}
private void CalculateRange(string addressFrom, string addressTo)
{
int max = 10;
int min = 0;
int from1 = 0;
int from2 = 0;
int from3 = 0;
int from4 = 0;
int to1 = 0;
int to2 = 0;
int to3 = 0;
int to4 = 0;
var from = txtFrom.Text.Split('.');
var to = txtTo.Text.Split('.');
if (from.Length == 4)
{
from1 = int.Parse(from[0]);
from2 = int.Parse(from[1]);
from3 = int.Parse(from[2]);
from4 = int.Parse(from[3]);
}
if (to.Length == 4)
{
to1 = int.Parse(to[0]);
to2 = int.Parse(to[1]);
to3 = int.Parse(to[2]);
to4 = int.Parse(to[3]);
}
if (from1 == to1 && from2 == to2 && from3 == to3 && from4 == to4)
{
Ping(string.Format("{0}.{1}.{2}.{3}", from1, from2, from3, from4));
}
else
{
}
}
private void Ping(string address)
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
try
{
PingReply reply = pingSender.Send(address, timeout, buffer, options) ;
if (reply.Status == IPStatus.Success)
{
/*PingReply replyy = pingSender.Send(address, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
txtDisplay.Text += "IP: " + replyy.Address.ToString() + ". "
+ "Round Trip: " + replyy.RoundtripTime + ". "
+ "TTL: " + replyy.Options.Ttl + ". "
+ "Don't Fragment: " + replyy.Options.DontFragment + ". "
+ "Buffer Size: " + replyy.Buffer.Length + ". ";
}*/
txtDisplay.Text += "Host " + address + " is open." + Environment.NewLine;
}
else
{
txtDisplay.Text += "Host " + address + " is closed." + Environment.NewLine;
}
}
catch (Exception ex)
{
txtDisplay.SelectedText += Environment.NewLine + ex.Message;
}
}
}
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)