Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const https=require("https");
- var fetch=require("node-fetch");
- //var fetch=require("fetch-h2").fetch;
- //const fs =require('fs');fn="c:/temp/gn_"+ (Math.floor(new Date().valueOf()/60000) ).toString(32)+".txt";
- var sqlite3 = require('sqlite3'); var db = new sqlite3.cached.Database('c:/temp/fgsdns.db3');
- const httpsAgent = new https.Agent({
- rejectUnauthorized: false,
- keepAlive: true
- });
- process.stdin._readableState.highWaterMark=8e6;
- var i=0,s='';
- if (! process.stdin.isTTY) {
- process.stdin.on('readable',()=>{
- if(data=process.stdin.read()) {
- i+=data.length;
- s=s.concat(data.toString('ascii'));
- };
- })
- process.stdin.on('end',()=>{
- console.error("done",i,s.length);
- list1=[... new Set(s.match(/([a-z0-9_-]+\.){1,}[a-z0-9]{2,64}/gim))];
- //list1=list1.filter(v=>!/^(10|127|224|255|192\.168|172\.(1[6-9]|2[0-9]|3[0-1])\.)/.test(v));
- console.error(list1.length);
- caller2();
- })
- }
- function caller2(){
- function aa(){
- var x=list1.shift();if(!x)return false;
- var t1=new Date();
- fetch("https://www.fortiguard.com/learnmore/dns", {agent: httpsAgent, "headers": {"content-type": "application/json;charset=UTF-8"},"body": "{\"value\":\""+x+"\",\"version\":9}","method": "POST"}).then(r=>r.json()).then(d=>{
- if (d.found) {
- var xx={};xx.domain=x;xx.category=d.dns.categoryname;xx.rating=d.dns.rating;d=xx,d.elapsed=new Date-t1;
- db.run("REPLACE INTO cache2(q,category,rating) VALUES(?,?,?)",
- [d.domain,d.category,d.rating],
- function(err, row){
- if (err) console.error(err);
- })
- };
- if (d.rating) {console.log(JSON.stringify(d))}else {console.error('NOT FOUND',x)};
- aa();
- })
- };
- for (var i=0;i<20;i++) aa();
- }
- // CREATE TABLE cache2(q varchar(256) primary key,category varchar(256),rating int,ts datetime default current_timestamp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement