Usually some times we may get some information about the website from their comments. Some developers may left few information knowingly or unknowingly, mainly hackers first look into the websites comments and try get some idea or information. Hackers will try some attacks based on the information they got. Sometimes developers may left some authentication information unknowingly, this will be used by hackers. Here is the simple NodeJS code, which will display the given webpage comments.
var http = require('http'); var readline = require('readline'); var input = readline.createInterface({ input: process.stdin, output: process.stdout }); // getting input from user input.question("Enter the Hostname to fetch comments: ", function(host) { var options = { hostname: host, port: 80, path: '/', method: 'GET' }; var req = http.request(options, function(res) { res.setEncoding('utf8'); console.log('\n********* HTML Comments from: '+ options.hostname +' **************\n'); res.on('data', function (resBody) { if(resBody.indexOf('<!--') > 0) { openTag = resBody.indexOf('<!--'); // getting the position of first comment opening tag while(openTag > 0){ endTag = resBody.indexOf('-->', openTag); // end tag position console.log('\t'+resBody.substr(openTag,endTag-openTag+3)+'\n'); // printing the sub string between the comments opening and ending tag. openTag = resBody.indexOf('<!--',endTag); // again geting(searching) the next comment opening tag starting from the end of the previous end tag. } } }); }); req.on('error', function(e) { console.log('Problem with request: '+ e.message); }); req.end(); });
That’s it. When you run the above program, by inputting the url you will get the HTML comments from the webpage.