Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:50:12+00:00 2026-05-27T15:50:12+00:00

So I am trying to build a range pinger which job will be to

  • 0

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;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:50:13+00:00Added an answer on May 27, 2026 at 3:50 pm

    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();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to build a function that will tell me the range of a
I'm trying build a method which returns the shortest path from one node to
I am trying to build a range with an upper bound bigger than limit
I'm currently trying to build a code which is supposed to work on a
We have been trying to use virtual machines for build servers. Our build servers
I am trying to build a Suffix range that is if I have strings
I am trying to build a switch/case structure around a range of integer values.
I am trying to use the API in cutplace to build a custom check
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
Trying to build sslsniff on a RHEL 5.2 system here. When compiling sslsniff on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.