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

  • Home
  • SEARCH
  • 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 9017297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:14:09+00:00 2026-06-16T04:14:09+00:00

I have a script that loops through IPs on my local network, checking if

  • 0

I have a script that loops through IPs on my local network, checking if anything is there. Every iteration, I submit an AJAX request to get the HTTP status code using cURL, which is returned to my Javascript. I already have built functions to calculate where the progress bar should be, however it only updates the progress bar when the entire script is finished executing.

Here’s what I have so far (I’m only using 0-23 in this example because I’m on 199.235.130.22 and I return ‘200’)

function updateProgress(percentage){
    document.getElementById('progressBar').style.width = percentage+'%';
    $('#progressText').html(percentage+'%');
}
for(host = 0; host <= 23; host++){
    ipToCheck = network_addr+'130.'+host;
    updateProgress(100/host);
    $.ajax({
        type: 'GET',
        url: 'js/scanhelper.php',
        data: {
            ip: ipToCheck
    }
    }).done(function(msg) {
        updateProgress(100/host);
        if(msg!=0){
            logSuccess(ipToCheck);
        }
    });
    pausecomp(200);  //Just a sleep function to simulate actual processing
}

My Bootstrap HTML is simply

<div class="progress progress-striped active" style="height:44px;">
    <div id="progressBar" class="bar" style="width:1%;"></div>
</div>

And, if it matters, my cURL PHP script is here: http://pastebin.com/JRZckdVb

What this should do is, on every iteration, update the progress bar’s width to 100 (as in 100%) divided by the current iteration. It may not be the correct math, but the point is it’s only updating after all iterations are complete, freezing the page while it’s running.

How can I fix this?

  • 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-06-16T04:14:11+00:00Added an answer on June 16, 2026 at 4:14 am

    aren’t you dividing by zero here when host = 0 in the for loop?

    updateProgress(100/host);
    

    you can use a variable hosts to keep track of the number of hosts you have.Then the progress will be as below.

    var hosts = 23;// total number of hosts
    updateProgress((host/hosts)*100);
    

    The other thing is the ajax you’re firing is asynchronous, so what’s happening is it fires and doesn’t wait for the results. You can either “scan” each host serially one at a time updating the progress bar or scan all of them simultaneously having the progress bar update as the asynch results come back. Can you specify which behavior you’re trying to achieve?

    [UPDATE]
    toggle async flag in the ajax call below for what you want.

    function updateProgress(percentage){
        if(percentage > 100) percentage = 100;
        $('#progressBar').css('width', percentage+'%');
        $('#progressBar').html(percentage+'%');
    }
    
    var hosts = 23;
    var hostsDone = 0;
    for(host = 0; host <= hosts; host++){
        ipToCheck = network_addr+'130.'+host;
        $.ajax({
            type: 'GET',
            url: 'js/scanhelper.php',
            async:true,
            data: {
                ip: ipToCheck
        }
        }).done(function(msg) {
            hostsDone++;
            updateProgress((hostsDone/hosts)*100);
            if(msg!=0){
                logSuccess(ipToCheck);
            }
        });
    }
    

    if you’re looking for visuals you should set the height of ‘#progressBar’ to something non-zero and maybe background green.

    <div class="progress progress-striped active" style="height:44px;">
        <div id="progressBar" class="bar" style="height:44px;width:1%;background-color:green"></div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3rd party script that loops through every returned value and echos
I have a script that recursively loops through all the sub directories and compresses
I have a Python script that for-loops through some objects and fetches data from
I have a script that runs every minute at XX:00. The script loops over
I have a ruby script that loops through a list of shortened urls (around
I have a Bash script that loops through files and masks them. The files
I have a PERL script that loops through and calls a binary with a
I have a script that loops through a list of DOM elements and manipulates
I have a script that loops through a directory and edits all the images
I have a PHP script that loops through some urls. The urls are stored

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.