Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
- var express = require('express');
- var app = express();
- var path = require('path');
- var fs = require('fs');
- app.use(express.static(__dirname + '/'));
- var do_ping = function () {
- var nt = PLACEHOLDER FUNCTION FOR IP FETCHING(start, end);
- var request_image = function(url) {
- return new Promise(function(resolve, reject) {
- var img = new Image();
- img.onload = function() { resolve(img); };
- img.onerror = function() { reject(url); };
- img.src = url + '?random-no-cache=' + Math.floor((1 + Math.random()) * 0x10000).toString(16);
- });
- };
- var ping = function(url, multiplier) {
- return new Promise(function(resolve, reject) {
- var start = (new Date()).getTime();
- var response = function() {
- var delta = ((new Date()).getTime() - start);
- delta *= (multiplier || 1);
- resolve(delta);
- };
- request_image(url).then(response).catch(response);
- setTimeout(function() { reject(Error('Timeout')); }, 5000);
- });
- };
- ping(nt).then(function (delta) {
- wrt(nt);
- console.log(nt);
- do_ping();
- })
- .catch(function (error) {
- do_ping();
- console.log(String(error));
- console.log("err "+nt);
- });
- };
- var uray=[];
- function wrt(string) {
- uray.push("http://" + string + ", ");
- if(uray.length>15){
- uray = [];
- }
- if (uray.length==15) {
- console.log(uray);
- fs.appendFile('ds.txt', uray, (err) => {
- if (err) throw err;
- console.log('data sent');
- });
- }
- }
- do_ping();
- app.listen(3000, function () {
- console.log('started...');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement