In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to quickly scan the port in Node.JS and find the address of the Web server in the local area network. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
It is quite convenient to scan ports in Node.JS. Generally, there are two ways: broadcast and polling. Even with broadcasting and scanning, messages sent using broadcasts are sometimes blocked by routers, so they are not reliable.
Using the net module in node.js, you can try to connect directly to a port on the directory host, and if a connection can be established, there is a server at that address.
Var socket = new Socket () socket.connect (port, host) socket.on ('connect', function () {/ / find port and host addresses})
So all the Web servers in the same network segment can be found by doing 255 scans. The complete sample code is as follows. Scanning with Node.JS is extremely fast and can be completed in a few seconds.
Var net = require ('net') var Socket = net.Socket// start segment to be scanned Replace it with 192.168.0var ip = '10.0.0'var port = 80var scan = function (host, cb) {var socket = new Socket () var status = null socket.setTimeout (1500) socket.on (' connect', function () {socket.end () cb & & cb (null, host)}) socket.on ('timeout', function () {socket.destroy () cb & & cb (new Error (' timeout'), host)}) socket.on ('error') Function (err) {cb & & cb (err, host)}) socket.on ('close', function (err) {}) socket.connect (port, host)} for (var I = 1 I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.