Advertisement
John4711

fgdns_sync1.js

Nov 11th, 2022 (edited)
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const https=require("https");
  2. var fetch=require("node-fetch");
  3. //var fetch=require("fetch-h2").fetch;
  4. //const fs =require('fs');fn="c:/temp/gn_"+ (Math.floor(new Date().valueOf()/60000) ).toString(32)+".txt";
  5. var sqlite3 = require('sqlite3'); var db = new sqlite3.cached.Database('c:/temp/fgsdns.db3');
  6. const httpsAgent = new https.Agent({
  7.       rejectUnauthorized: false,
  8.       keepAlive: true
  9.     });
  10.  
  11. process.stdin._readableState.highWaterMark=8e6;
  12. var i=0,s='';
  13. if (! process.stdin.isTTY) {
  14. process.stdin.on('readable',()=>{
  15.     if(data=process.stdin.read()) {
  16.         i+=data.length;
  17.         s=s.concat(data.toString('ascii'));
  18.     };
  19. })
  20.  
  21. process.stdin.on('end',()=>{
  22.     console.error("done",i,s.length);
  23.     list1=[... new Set(s.match(/([a-z0-9_-]+\.){1,}[a-z0-9]{2,64}/gim))];
  24.     //list1=list1.filter(v=>!/^(10|127|224|255|192\.168|172\.(1[6-9]|2[0-9]|3[0-1])\.)/.test(v));
  25.     console.error(list1.length);
  26.     caller2();
  27. })
  28.  
  29. }
  30.  
  31. function caller2(){
  32.  
  33. function aa(){
  34.     var x=list1.shift();if(!x)return false;
  35.     var t1=new Date();
  36.     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=>{
  37.         if (d.found) {
  38.             var xx={};xx.domain=x;xx.category=d.dns.categoryname;xx.rating=d.dns.rating;d=xx,d.elapsed=new Date-t1;
  39.            
  40.             db.run("REPLACE INTO cache2(q,category,rating) VALUES(?,?,?)",
  41.         [d.domain,d.category,d.rating],
  42.         function(err, row){
  43.             if (err) console.error(err);
  44.         })
  45.    
  46.    
  47.            
  48.            
  49.             };
  50.         if (d.rating) {console.log(JSON.stringify(d))}else {console.error('NOT FOUND',x)};
  51.         aa();
  52.     })
  53. };
  54. for (var i=0;i<20;i++) aa();
  55.  
  56.    
  57.  
  58. }
  59.  
  60. // CREATE TABLE cache2(q varchar(256) primary key,category varchar(256),rating int,ts datetime default current_timestamp);
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement