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 6708171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:43:37+00:00 2026-05-26T07:43:37+00:00

I am not a professional java script programmer. I hope you can help me.

  • 0

I am not a professional java script programmer. I hope you can help me.

I wrote a code to list port status using ajax. for example site:google.com ports: from 24 to 80 . But it is not working while I try to use a Javascript For Loop to list the output.
code is[index.php]:

<div id="inputform"><span>Enter URL or IP</span>
  <input type="text" name="urladress" id="urladress" size=25 maxlength=100 value="<?php if (isset($_POST['urladress'])){echo $_POST['urladress'];}; ?>"></br>
  from port
  <input type="text" name="fromport" id="fromport" size=5 maxlength=6 value="<?php if (isset($_POST['fromport'])){echo $_POST['fromport'];}else{echo "1";} ; ?>">
  to:
  <input type="text" name="toport" id="toport" size=5 maxlength=6 value="<?php if (isset($_POST['toport'])){echo $_POST['toport'];}else{echo "24";} ;; ?>">
  <input type="button" value="submit" onClick="getresults();" class="btn">
</div>
<div id="result" name="result"> </div>
<script language="javascript" type="text/javascript">
    // Get the HTTP Object
    function getHTTPObject(){
        if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
            else if (window.XMLHttpRequest) return new XMLHttpRequest();
        else {
            alert("Ajax not supported.");
            return null;
        }
    }
    // Change the value of the outputText field
    function setOutput(){

        document.getElementById('result').innerHTML += httpObject.responseText;

    }
    // Implement business logic
    function getresults(){
        document.getElementById('result').innerHTML = "calculating</br>"
        httpObject = getHTTPObject();
        if (httpObject != null) 
        {
            var fromport = document.getElementById('fromport').value;
            var toport = document.getElementById('toport').value;
            if (fromport>toport || toport=='' || fromport==''){alert('wrong values');return 0;}

            for(var i=fromport;i<=toport;i++){
                httpObject.open("GET", "portscanner.php?inputText="+document.getElementById('urladress').value+"&port="+i, true);
                httpObject.send(null);
                httpObject.onreadystatechange = setOutput;
            }

        }
    }
    var httpObject = null;
    </script>
</div>

server side[portscan.php]:

<?php
if (isset($_GET['inputText'])){
    $url=$_GET['inputText'];
    $url = str_replace("http://","",$url);
    $url = str_replace("www.","",$url);
    $port=$_GET['port'];
    $fp = @fsockopen($url,$port,$errno,$errstr,2);
    if(!$fp)
    {
        echo "port #". $port . "is closed</br>";
    }
    else
    {
        echo "Port #".$port."is open.</br>";
        fclose($fp);
    }
};
?>

it just shows last port’s result:
for example site:http://stackoverflow.com ports: from 70 to 80 shows:

calculating
Port #80is open.
Port #80is open.

it should look like:

calculating
Port #70is closed.
Port #71is closed.
Port #72is closed.
...
Port #79is closed.
Port #80is open.
  • 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-26T07:43:38+00:00Added an answer on May 26, 2026 at 7:43 am

    httpObject will be overridden each time your loop executes. You probably need an array of httpObjects to handle this.

    OnReadyStateChange is not a blocking command so the FOR loop will continue until the last time.

    Change functions like this :

    // Change the value of the outputText field
    function setOutput(index){
        if(this.readyState == 4) // Done
        {
            if(this.status == 200)
                document.getElementById('result').innerHTML += this.responseText;
            else
                document.getElementById('result').innerHTML += "Error occured : " + this.status + "<br>";
        }
    }
    // Implement business logic
    function getresults(){
        document.getElementById('result').innerHTML = "calculating</br>";
        var fromport = document.getElementById('fromport').value;
        var toport = document.getElementById('toport').value;
        if (fromport>toport || toport=='' || fromport==''){alert('wrong values');return 0;}
    
        for(var i=fromport;i<=toport;i++){
            var index = httpObject.push(getHTTPObject()) - 1;
            httpObject[index].open("GET", "test.php?inputText="+document.getElementById('urladress').value+"&port="+i, true);
            httpObject[index].send(null);
            httpObject[index].onreadystatechange = setOutput;
        }
    }
    var httpObject = new Array();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not professional programmer so i can not be sure about this.How many
I'm not a javascript professional so I can't solve the following code alone. I
First, let me say I'm not a professional programmer, but an engineer who had
I am not a professional programmer (my area is medical research), but I am
Im having an issue using Java script to create a table that displays an
I'm currently developing for a handheld device running Windows XP Professional (not Tablet PC
I'm talking about VS 2010 Professional/Ultimate RTM (not express versions). Google doesn't show much
I have searched around a bit, and have not really found a professional type
Not really getting the point of the map function. Can anyone explain with examples
As a non-professional programmer, I'm trying to self teach myself a little HTML and

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.