in Education by
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)

1 Answer

0 votes
by
I'd make two functions which convert an IP address to a number and vice-versa: static uint str2ip(string ip) { string[] numbers = ip.Split('.'); uint x1 = (uint)(Convert.ToByte(numbers[0]) << 24); uint x2 = (uint)(Convert.ToByte(numbers[1]) << 16); uint x3 = (uint)(Convert.ToByte(numbers[2]) << 8); uint x4 = (uint)(Convert.ToByte(numbers[3])); return x1 + x2 + x3 + x4; } and static string ip2str(uint ip) { string s1 = ((ip & 0xff000000) >> 24).ToString() + "."; string s2 = ((ip & 0x00ff0000) >> 16).ToString() + "."; string s3 = ((ip & 0x0000ff00) >> 8).ToString() + "."; string s4 = (ip & 0x000000ff).ToString(); string ip2 = s1 + s2 + s3 + s4; return ip2; } This way you can easily iterate through all the IPs. Here's a sample program: static void Main(string[] args) { uint startIP = str2ip("250.255.255.100"); uint endIP = str2ip("255.0.1.255"); for(uint currentIP = startIP; currentIP <= endIP; currentIP++) { string thisIP = ip2str(currentIP); Console.WriteLine(thisIP); } Console.ReadKey(); }

Related questions

0 votes
    Which of the following input control is used for input fields that should contain a value from a range of numbers in Web Form 2.0? A - week B - time C - number D - range...
asked Dec 2, 2020 in Technology by JackTerrance
0 votes
    Which of the following is not a proper aspect of user integration? (a) Employee's authentication (b) Physical ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 3, 2021 in Education by JackTerrance
0 votes
    What happens when an application takes user inputted data and sends it to a web browser without proper validation ... 2. Insecure direct object reference 3. Cross Site Scripting...
asked Mar 20, 2021 in Technology by JackTerrance
0 votes
    Write an algorithm to accept radius of a circle from user, and display area of the circle using the formula: area ... x radius x radius Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    Let a(l), b(l) represent in input-output pairs, where l varies in natural range of no.s, then if ... heteroassociation (d) none of the mentioned Please answer the above question....
asked Sep 3, 2022 in Education by JackTerrance
0 votes
    Just started working with Python and I would like to know how to create a set only from user input ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have an XML file which is structured as follows: place1 location1 place2 location2 place3 location3 These ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    How can we take input text from user in HTML page? (a) input tag (b) inoutBufferedReader tag (c) meta ... & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    WAP in java to input 3 numbers from user and print the largest no. among them using nested if. Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    WAP in java to input 2 numbers from user and print their difference (Always Positive). Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    How can we take input text from user in HTML page? (a) input tag (b) inoutBufferedReader tag (c) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    Which algorithm takes two sentences as input and returns a Unifier? Inference Hill-Climbing Unify algorithm Depth-first search...
asked Mar 8, 2021 in Technology by JackTerrance
0 votes
    2 Write an algorithm to input two numbers and find their sum and difference Select the correct answer from above options...
asked Nov 28, 2021 in Education by JackTerrance
0 votes
    Which of the following attack-based checks WebInspect cannot do? (a) cross-site scripting (b) directory traversal (c ... questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 3, 2021 in Education by JackTerrance
...