JS to get the website status code, if there is a write file

Time:2021-7-20

JS get the site status code, if the site exists, write to the txt file, applicable to ie.

<script>
//Writing documents     
function writeFile(filename,filecontent) {     
    var fso, f, s ;     
    fso = new ActiveXObject("Scripting.FileSystemObject");        
    f = fso.OpenTextFile(filename,8,true);     
    f.WriteLine(filecontent);       
    f.Close();          
}

//Judge whether the website can be opened
function http_go(URL) {
    var http_c= new ActiveXObject("microsoft.xmlhttp");
    http_c.Open("GET",URL,false);
    try {
        http_c.Send();
    }
    catch(e) {}
    finally {
        var result = http_c.responseText;
        if(result) {
            if(http_c.Status==200) {
                return(true);
            } else {
                return(false);
            }
        } else {
            return(false);
        }
    }
}

var q = ['bj','sh','sz','gz','tj','hz','nj'];
var c = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z'];
for(var x=0;x<q.length;x++) {
    for(var i=0;i<c.length;i++)  {
        for(var j=0;j<c.length;j++) {
            for(var k=0;k<c.length;k++) {  
                var domain_m =q[x]+c[i]+c[j]+c[k]+'.com';
                var domain_m1 ='http://'+domain_m;
                var domain_m2 ='http://www'+domain_m;
                if(http_go(domain_m1)||http_go(domain_m2)){
                    writeFile('D:/WORK/domain/domain_qc.txt',domain_m);
                }
            }
        }
    }
}
</script>

When a browser visits a web page, the browser will send a request to the server where the web page is located. Before the browser receives and displays the web page, the server where the web page is located will return a server header containing HTTP status code in response to the browser’s request. The English of HTTP status code is HTTP status code.

Here are the common HTTP status codes:

  • 200 – Request successful
  • 301 – resources (web pages, etc.) are permanently transferred to other URLs
  • 404 – the requested resource (web page, etc.) does not exist
  • 500 – internal server error

Appendix:

Read the original:https://blog.mazey.net/1931.html