wants to implement the function of port scanning, such as 192.168.1.666
- 192.168.1.666
uses nodejs + express + cheerio
personal idea: circular port, use superagent
to grab the port of ip between 80-10000, if the port does not exist, then jump out of this loop, then execute next time, declare data
variable, if there is content in the port and grab website title, push
to data
,
finally when executing to the maximum interface, res.send (data)
problem encountered: keep going in circles, turning the loop down is the same, I don"t know what the problem is, whether it needs to be asynchronous or there is something wrong with the code?
Code:
const express = require("express");
var cheerio = require("cheerio");
const superagent = require("superagent");
const app = express();
/ / crawl address
var url = "http://47.74.xxx.xxx";
var maxport = 8085;
var data = [];
for(let port = 8082; port < maxport ; portPP){
app.get("/", function (req, res, next) {
superagent.get( url + ":" + port )
.end(function (err, sres) {
if (err) {
return next(err);
}
const $ = cheerio.load(sres.text);
let items = $("title").text();
data.push(items)
if(port >= maxport){
res.send(data);
}
})
});
}
app.listen(3000, function () {
console.log("app is listening at port 3000");
});
it is better to provide the code