@stacksjs/whois 0.75.734 → 0.75.755

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -48,17 +48,6 @@ export declare function getWhoIsServer(tld: keyof typeof SERVERS): string | unde
48
48
  export declare function getTLD(domain: string): keyof typeof SERVERS;
49
49
  // get whois query parameters if exist on parameters.json for whois server
50
50
  export declare function getParameters(server: string): string | undefined;
51
- /**
52
- * Connects to the provided {@link server}:{@link port} through TCP (through a proxy if a proxy is given), run the WhoIs query and returns the response
53
- *
54
- * @param domain Domain name
55
- * @param queryOptions Query options which can be used with the specific WhoIs server to get the complete response
56
- * @param server WhoIs server
57
- * @param port WhoIs server port
58
- * @param encoding Encoding used by the WhoIs server
59
- * @param proxy {@link ProxyData}
60
- * @returns The {string} WhoIs response for the query. Empty string is returned for errors
61
- */
62
51
  export declare function tcpWhois(domain: string, queryOptions: string, server: string, port: number, encoding: string, proxy: ProxyData | null): Promise<string>;
63
52
  /**
64
53
  * Collect WhoIs data for the mentioned {@link domain}. Parse the received response if {@link parse} is true, accordingly.
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
1
  // @bun
2
- import z from"net";import{log as f}from"@stacksjs/logging";var y="https://www.iana.org/whois?q=",b={"whois.denic.de":"-T dn,ace","whois.nic.fr":"-V Md5.2"},p={"br.com":"whois.centralnic.net","cn.com":"whois.centralnic.net","de.com":"whois.centralnic.net","eu.com":"whois.centralnic.net","gb.com":"whois.centralnic.net","gb.net":"whois.centralnic.net","gr.com":"whois.centralnic.net","hu.com":"whois.centralnic.net","in.net":"whois.centralnic.net","no.com":"whois.centralnic.net","qc.com":"whois.centralnic.net","ru.com":"whois.centralnic.net","sa.com":"whois.centralnic.net","se.com":"whois.centralnic.net","se.net":"whois.centralnic.net","uk.com":"whois.centralnic.net","uk.net":"whois.centralnic.net","us.com":"whois.centralnic.net","uy.com":"whois.centralnic.net","za.com":"whois.centralnic.net","jpn.com":"whois.centralnic.ne","web.com":"whois.centralnic.ne",com:"whois.verisign-grs.com","za.net":"whois.za.net",net:"whois.verisign-grs.com","eu.org":"whois.eu.org","za.org":"whois.za.org",org:"whois.pir.org","llyw.cymru":"whois.nic.llyw.cymru","gov.scot":"whois.nic.gov.scot","gov.wales":"whois.nic.gov.wales",edu:"whois.educause.edu",gov:"whois.dotgov.gov",int:"whois.iana.org","e164.arpa":"whois.ripe.net",arpa:"whois.iana.org",aero:"whois.aero",asia:"whois.nic.asia",biz:"whois.nic.biz",cat:"whois.nic.cat",coop:"whois.nic.coop",info:"whois.afilias.net",jobs:"whois.nic.jobs",mobi:"whois.afilias.net",museum:"whois.nic.museum",name:"whois.nic.name",post:"whois.dotpostregistry.net",pro:"whois.nic.pro",tel:"whois.nic.tel",travel:"whois.nic.travel",xxx:"whois.nic.xxx",ac:"whois.nic.ac",ae:"whois.aeda.net.ae",af:"whois.nic.af",ag:"whois.nic.ag",ai:"whois.nic.ai",am:"whois.amnic.net",ar:"whois.nic.ar",as:"whois.nic.as","priv.at":"whois.nic.priv.at",at:"whois.nic.at",au:"whois.auda.org.au",aw:"whois.nic.aw",ax:"whois.ax",be:"whois.dns.be",bf:"whois.registre.bf",bg:"whois.register.bg",bh:"whois.nic.bh",bi:"whois1.nic.bi",bj:"whois.nic.bj",bm:"whois.afilias-srs.net",bn:"whois.bnnic.bn",bo:"whois.nic.bo",br:"whois.registro.br",by:"whois.cctld.by",bw:"whois.nic.net.bw",bz:"whois.afilias-grs.info","co.ca":"whois.co.ca",ca:"whois.cira.ca",cc:"ccwhois.verisign-grs.com",cd:"whois.nic.cd",ch:"whois.nic.ch",ci:"whois.nic.ci",cl:"whois.nic.cl",cm:"whois.netcom.cm","edu.cn":"whois.edu.cn",cn:"whois.cnnic.cn","uk.co":"whois.uk.co",co:"whois.nic.co",cr:"whois.nic.cr",cx:"whois.nic.cx",cz:"whois.nic.cz",de:"whois.denic.de",dk:"whois.dk-hostmaster.dk",dm:"whois.dmdomains.dm",do:"whois.nic.do",dz:"whois.nic.dz",ec:"whois.nic.ec",ee:"whois.tld.ee",eu:"whois.eu",fi:"whois.fi",fj:"www.whois.fj",fm:"whois.nic.fm",fo:"whois.nic.fo",fr:"whois.nic.fr",gd:"whois.nic.gd",ge:"whois.nic.ge",gf:"whois.mediaserv.net",gg:"whois.gg",gh:"whois.nic.gh",gi:"whois2.afilias-grs.net",gl:"whois.nic.gl",gp:"whois.nic.gp",gq:"whois.dominio.gq",gs:"whois.nic.gs",gy:"whois.registry.gy",hk:"whois.hkirc.hk",hm:"whois.registry.hm",hn:"whois.nic.hn",hr:"whois.dns.hr",ht:"whois.nic.ht",hu:"whois.nic.hu",id:"whois.id",ie:"whois.weare.ie",il:"whois.isoc.org.il",im:"whois.nic.im",in:"whois.registry.in",io:"whois.nic.io",iq:"whois.cmc.iq",ir:"whois.nic.ir",is:"whois.isnic.is",it:"whois.nic.it",je:"whois.je",jp:"whois.jprs.jp",ke:"whois.kenic.or.ke",kg:"whois.kg",ki:"whois.nic.ki",kn:"whois.nic.kn",kr:"whois.kr",kw:"whois.nic.kw",ky:"whois.kyregistry.ky",kz:"whois.nic.kz",la:"whois.nic.la",lb:"whois.lbdr.org.lb",lc:"whois2.afilias-grs.net",li:"whois.nic.li",lk:"whois.nic.lk",ls:"whois.nic.ls",lt:"whois.domreg.lt",lu:"whois.dns.lu",lv:"whois.nic.lv",ly:"whois.nic.ly",ma:"whois.registre.ma",md:"whois.nic.md",me:"whois.nic.me",mg:"whois.nic.mg",mk:"whois.marnet.mk",ml:"whois.dot.ml",mm:"whois.registry.gov.mm",mn:"whois.nic.mn",mq:"whois.mediaserv.net",mr:"whois.nic.mr",ms:"whois.nic.ms",mt:"whois.nic.org.mt",mu:"whois.nic.mu",mw:"whois.nic.mw",mx:"whois.mx",my:"whois.mynic.my",mz:"whois.nic.mz",na:"whois.na-nic.com.na",nc:"whois.nc",nf:"whois.nic.nf",ng:"whois.nic.net.ng",nl:"whois.domain-registry.nl",no:"whois.norid.no",nu:"whois.iis.nu",nz:"whois.irs.net.nz",om:"whois.registry.om",pe:"kero.yachay.pe",pf:"whois.registry.pf",pk:"whois.pknic.net.pk","co.pl":"whois.co.pl",pl:"whois.dns.pl",pm:"whois.nic.pm",pr:"whois.afilias-srs.net",ps:"whois.pnina.ps",pt:"whois.dns.pt",pw:"whois.nic.pw",qa:"whois.registry.qa",re:"whois.nic.re",ro:"whois.rotld.ro",rs:"whois.rnids.rs","ac.ru":"whois.free.net","edu.ru":"whois.informika.ru","com.ru":"whois.flexireg.net","msk.ru":"whois.flexireg.net","net.ru":"whois.nic.net.ru","nov.ru":"whois.flexireg.net","org.ru":"whois.nic.net.ru","pp.ru":"whois.nic.net.ru","spb.ru":"whois.flexireg.net",ru:"whois.tcinet.ru",rw:"whois.ricta.org.rw",sa:"whois.nic.net.sa",sb:"whois.nic.net.sb",sc:"whois2.afilias-grs.net",sd:"whois.sdnic.sd",se:"whois.iis.se",sg:"whois.sgnic.sg",sh:"whois.nic.sh",si:"whois.register.si",sk:"whois.sk-nic.sk",sl:"whois.nic.sl",sm:"whois.nic.sm",sn:"whois.nic.sn",so:"whois.nic.so",ss:"whois.nic.ss",st:"whois.nic.st","msk.su":"whois.flexireg.net","nov.su":"whois.flexireg.net","spb.su":"whois.flexireg.net",su:"whois.tcinet.ru",sx:"whois.sx",sy:"whois.tld.sy",tc:"whois.nic.tc",td:"whois.nic.td",tf:"whois.nic.tf",tg:"whois.nic.tg",th:"whois.thnic.co.th",tk:"whois.dot.tk",tl:"whois.nic.tl",tm:"whois.nic.tm",tn:"whois.ati.tn",to:"whois.tonic.to",tr:"whois.trabis.gov.tr",tv:"whois.nic.tv",tw:"whois.twnic.net.tw",tz:"whois.tznic.or.tz","biz.ua":"whois.biz.ua","co.ua":"whois.co.ua","pp.ua":"whois.pp.ua",ua:"whois.ua",ug:"whois.co.ug","ac.uk":"whois.nic.ac.uk","gov.uk":"whois.gov.uk",uk:"whois.nic.uk","fed.us":"whois.nic.gov",us:"whois.nic.us",uy:"whois.nic.org.uy",uz:"whois.cctld.uz",vc:"whois2.afilias-grs.net",ve:"whois.nic.ve",vg:"whois.nic.vg",vu:"whois.dnrs.vu",wf:"whois.nic.wf",ws:"whois.website.ws",yt:"whois.nic.yt","ac.za":"whois.ac.za","co.za":"whois.registry.net.za","gov.za":"whois.gov.za","net.za":"net-whois.registry.net.za","org.za":"org-whois.registry.net.za","web.za":"web-whois.registry.net.za",zm:"whois.zicta.zm","xn--2scrj9c":"whois.registry.in","xn--3e0b707e":"whois.kr","xn--3hcrj9c":"whois.registry.in","xn--45br5cyl":"whois.registry.in","xn--45brj9c":"whois.registry.in","xn--4dbrk0ce":"whois.isoc.org.il","xn--80ao21a":"whois.nic.kz","xn--90a3ac":"whois.rnids.rs","xn--90ae":"whois.imena.bg","xn--90ais":"whois.cctld.by","xn--clchc0ea0b2g2a9gcd":"whois.sgnic.sg","xn--d1alf":"whois.marnet.mk","xn--e1a4c":"whois.eu","xn--fiqs8s":"cwhois.cnnic.cn","xn--fiqz9s":"cwhois.cnnic.cn","xn--fpcrj9c3d":"whois.registry.in","xn--fzc2c9e2c":"whois.nic.lk","xn--gecrj9c":"whois.registry.in","xn--h2breg3eve":"whois.registry.in","xn--h2brj9c8c":"whois.registry.in","xn--h2brj9c":"whois.registry.in","xn--j1amh":"whois.dotukr.com","xn--j6w193g":"whois.hkirc.hk","xn--kprw13d":"whois.twnic.net.tw","xn--kpry57d":"whois.twnic.net.tw","xn--lgbbat1ad8j":"whois.nic.dz","xn--mgb9awbf":"whois.registry.om","xn--mgba3a4f16a":"whois.nic.ir","xn--mgbaam7a8h":"whois.aeda.net.ae","xn--mgbah1a3hjkrd":"whois.nic.mr","xn--mgbbh1a71e":"whois.registry.in","xn--mgbbh1a":"whois.registry.in","xn--mgberp4a5d4ar":"whois.nic.net.sa","xn--mgbgu82a":"whois.registry.in","xn--mgbtx2b":"whois.cmc.iq","xn--mgbx4cd0ab":"whois.mynic.my","xn--node":"whois.itdc.ge","xn--o3cw4h":"whois.thnic.co.th","xn--ogbpf8fl":"whois.tld.sy","xn--p1ai":"whois.tcinet.ru","xn--pgbs0dh":"whois.ati.tn","xn--q7ce6a":"whois.nic.la","xn--qxa6a":"whois.eu","xn--rvc1e0am3e":"whois.registry.in","xn--s9brj9c":"whois.registry.in","xn--wgbh1c":"whois.dotmasr.eg","xn--wgbl6a":"whois.registry.qa","xn--xkc2al3hye2a":"whois.nic.lk","xn--xkc2dl3a5ee0h":"whois.registry.in","xn--y9a3aq":"whois.amnic.net","xn--yfro4i67o":"whois.sgnic.sg","xn--ygbi2ammx":"whois.pnina.ps"};import S from"net";class g{options;constructor(i){this.options=i}static createConnection(i,o){new g(i).connect(o)}connect(i){let o=new S.Socket,{proxy:s,destination:e}=this.options;o.connect({port:s.port,host:s.host},()=>{if(s.type===5)this.connectSocks5(o,i);else this.connectSocks4(o,i)}),o.on("error",(t)=>{i(t)})}connectSocks4(i,o){let{destination:s,proxy:e}=this.options,t=s.port,n=e.userId||"",r;if(this.isIPv4(s.host)){let h=s.host.split(".").map(Number);r=Buffer.from(h)}else r=Buffer.from([0,0,0,1]);let c=Buffer.concat([Buffer.from([4]),Buffer.from([1]),Buffer.from([t>>8&255,t&255]),r,Buffer.from(n),Buffer.from([0])]);if(!this.isIPv4(s.host)){let h=Buffer.concat([c,Buffer.from(s.host),Buffer.from([0])]);i.write(h)}else i.write(c);i.once("data",(h)=>{if(h.length<8){o(Error("Invalid SOCKS4 response"));return}let l=h[1];if(l!==90){o(Error(`SOCKS4 connection failed with status: ${l}`));return}o(null,{socket:i})})}connectSocks5(i,o){let{destination:s,proxy:e}=this.options,t;if(e.userId&&e.password)t=[0,2];else t=[0];let n=Buffer.from([5,t.length,...t]);i.write(n),i.once("data",(r)=>{if(r.length<2||r[0]!==5){o(Error("Invalid SOCKS5 greeting response"));return}let c=r[1];if(c===255){o(Error("No acceptable authentication methods"));return}if(c===2)this.authenticateSocks5(i,o);else this.sendConnectRequest(i,o)})}authenticateSocks5(i,o){let{proxy:s}=this.options,e=s.userId||"",t=s.password||"",n=Buffer.concat([Buffer.from([1]),Buffer.from([e.length]),Buffer.from(e),Buffer.from([t.length]),Buffer.from(t)]);i.write(n),i.once("data",(r)=>{if(r.length<2||r[0]!==1){o(Error("Invalid SOCKS5 auth response"));return}if(r[1]!==0){o(Error("SOCKS5 authentication failed"));return}this.sendConnectRequest(i,o)})}sendConnectRequest(i,o){let{destination:s}=this.options,e=s.port,t,n;if(this.isIPv4(s.host)){n=1;let c=s.host.split(".").map(Number);t=Buffer.from(c)}else if(this.isIPv6(s.host)){n=4;let c=s.host.split(":"),h=[];for(let l of c){let w=Number.parseInt(l,16);h.push(w>>8&255,w&255)}t=Buffer.from(h)}else n=3,t=Buffer.concat([Buffer.from([s.host.length]),Buffer.from(s.host)]);let r=Buffer.concat([Buffer.from([5,1,0,n]),t,Buffer.from([e>>8&255,e&255])]);i.write(r),i.once("data",(c)=>{if(c.length<10||c[0]!==5){o(Error("Invalid SOCKS5 connect response"));return}let h=c[1];if(h!==0){let w=h===void 0?"No SOCKS5 status returned":{1:"General SOCKS server failure",2:"Connection not allowed by ruleset",3:"Network unreachable",4:"Host unreachable",5:"Connection refused",6:"TTL expired",7:"Command not supported",8:"Address type not supported"}[h]||`Unknown error (${h})`;o(Error(`SOCKS5 connection failed: ${w}`));return}o(null,{socket:i})})}isIPv4(i){if(!/^(?:\d{1,3}\.){3}\d{1,3}$/.test(i))return!1;return i.split(".").map(Number).every((e)=>e>=0&&e<=255)}isIPv6(i){return i.includes(":")&&i.split(":").length>=3}}var E;((s)=>{s[s.SOCKS4=0]="SOCKS4";s[s.SOCKS5=1]="SOCKS5"})(E||={});function d(i){if(Array.isArray(i))return i.slice();if(typeof i==="object"&&i!==null){let o={};for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s))o[s]=d(i[s]);return o}return i}async function C(i){let o=y+i;try{let s=await fetch(o);if(s.ok)return I(await s.text())}catch(s){console.error("Error in getting WhoIs server data from IANA",s)}return""}function I(i){return i.match(/^whois:[ \t]+(\S+)/m)?.[1]??""}function R(i){if(i==="com")return"whois.verisign-grs.com";return p[i]}function v(i){let o=i.split(".");for(let s=o.length-1;s>0;s--){let e=o.slice(s).join(".");if(p[e])return e}return o[o.length-1]}function O(i){return b[i]}class m{static iterParse(i,o){let s=(t,n)=>{let r=o[t];if(Array.isArray(r))r.push(n);else o[t]=n},e=null;for(let t of i.split(/\r?\n/)){let n=t.trim();if(n.startsWith(">>>")||n.startsWith("Record maintained by"))break;if(!n)continue;let r=n.indexOf(":"),c=r===-1?null:n.slice(0,r).trim();if(c!==null&&c in o){let h=n.slice(r+1).trim();if(h)s(c,h),e=null;else e=c;continue}if(e!==null)s(e,n),e=null}return o}static parseData(i,o){if(!o)o={"Domain Name":"","Creation Date":"","Updated Date":"","Registry Expiry Date":"","Domain Status":[],Registrar:""};return o=m.iterParse(i,o),o}}async function B(i,o,s,e,t,n){let r=new TextDecoder(t),c=new TextEncoder;if(!n){let l=new z.Socket;return l.setTimeout(30000),new Promise((w,u)=>{try{l.connect({port:e,host:s},()=>{if(o!=="")l.write(c.encode(`${o} ${i}\r
3
- `));else l.write(c.encode(`${i}\r
4
- `))}),l.on("data",(a)=>{w(typeof a==="string"?a:r.decode(new Uint8Array(a.buffer,a.byteOffset,a.byteLength)))}),l.on("error",(a)=>{u(a)}),l.on("timeout",()=>{l.destroy(),u(Error(`WHOIS request to ${s}:${e} timed out after 30s`))})}catch(a){u(a)}})}let h={proxy:{host:n.ip,port:n.port,type:n.type===1?5:4},command:"connect",destination:{host:s,port:e}};if(n.username&&n.password)h.proxy.userId=n.username,h.proxy.password=n.password;return new Promise((l,w)=>{g.createConnection(h,(u,a)=>{if(u)w(u);else{if(!a)w(Error("No socket info received!"));if(o!=="")a?.socket.write(c.encode(`${o} ${i}\r
5
- `));else a?.socket.write(c.encode(`${i}\r
6
- `));a?.socket.on("data",(k)=>{l(r.decode(k))}),a?.socket.resume()}})})}async function x(i,o=!1,s=null){let e,t=43,n="",r,c="utf-8";if(!s)e=v(i),r=null;else e=s.tld?s.tld:v(i),c=s.encoding?s.encoding:"utf-8",r=s.proxy?s.proxy:null,n=s.server?s.server:"",t=s.serverPort?s.serverPort:43;if(n===""){let w=R(e);if(!w){if(f.debug(`No WhoIs server found for TLD: ${e}! Attempting IANA WhoIs database for server!`),w=await C(e),!w)return f.debug("WhoIs server could not be found!"),{_raw:"",parsedData:null};f.debug(`WhoIs sever found for ${e}: ${n}`)}n=w}let l=O(n)||"";try{f.debug(`Attempting WHOIS lookup for ${i} on server ${n}`);let w=await B(i,l,n,t,c,r);if(f.debug("Raw WHOIS data received:",w),!o){let a=m.parseData(w,null);return{_raw:w,parsedData:a}}let u=null;if(s?.parseData)u=d(s.parseData);try{let a=m.parseData(w,u);return{_raw:w,parsedData:a}}catch(a){return console.error("Error in parsing WhoIs data!",a),{_raw:w,parsedData:null}}}catch(w){return f.debug(`Error in WHOIS lookup for ${i} on server ${n}`,w),{_raw:"",parsedData:null}}}function _(i,o=null){return f.debug(`Lookup called for ${i}`),x(i,!0,o)}async function L(i,o=!1,s=1,e=!1,t=null){let n=[];if(o){if(s>i.length)s=i.length;for(let r=0;r<i.length;r+=s){let c=i.slice(r,r+s),h=await Promise.all(c.map(async(l)=>await x(l,e,t)));n.push(...h)}}else for(let r=0;r<i.length;r++){let c=await x(i[r],e,t);n.push(c)}return n}export{y as IANA_CHK_URL,b as PARAMETERS,E as ProxyType,p as SERVERS,g as SocksClient,m as WhoIsParser,L as batchWhois,C as findWhoIsServer,O as getParameters,v as getTLD,R as getWhoIsServer,_ as lookup,I as parseIanaWhoisServer,B as tcpWhois,x as whois};
2
+ import D from"net";import{log as p}from"@stacksjs/logging";var R="https://www.iana.org/whois?q=",O={"whois.denic.de":"-T dn,ace","whois.nic.fr":"-V Md5.2"},k={"br.com":"whois.centralnic.net","cn.com":"whois.centralnic.net","de.com":"whois.centralnic.net","eu.com":"whois.centralnic.net","gb.com":"whois.centralnic.net","gb.net":"whois.centralnic.net","gr.com":"whois.centralnic.net","hu.com":"whois.centralnic.net","in.net":"whois.centralnic.net","no.com":"whois.centralnic.net","qc.com":"whois.centralnic.net","ru.com":"whois.centralnic.net","sa.com":"whois.centralnic.net","se.com":"whois.centralnic.net","se.net":"whois.centralnic.net","uk.com":"whois.centralnic.net","uk.net":"whois.centralnic.net","us.com":"whois.centralnic.net","uy.com":"whois.centralnic.net","za.com":"whois.centralnic.net","jpn.com":"whois.centralnic.ne","web.com":"whois.centralnic.ne",com:"whois.verisign-grs.com","za.net":"whois.za.net",net:"whois.verisign-grs.com","eu.org":"whois.eu.org","za.org":"whois.za.org",org:"whois.pir.org","llyw.cymru":"whois.nic.llyw.cymru","gov.scot":"whois.nic.gov.scot","gov.wales":"whois.nic.gov.wales",edu:"whois.educause.edu",gov:"whois.dotgov.gov",int:"whois.iana.org","e164.arpa":"whois.ripe.net",arpa:"whois.iana.org",aero:"whois.aero",asia:"whois.nic.asia",biz:"whois.nic.biz",cat:"whois.nic.cat",coop:"whois.nic.coop",info:"whois.afilias.net",jobs:"whois.nic.jobs",mobi:"whois.afilias.net",museum:"whois.nic.museum",name:"whois.nic.name",post:"whois.dotpostregistry.net",pro:"whois.nic.pro",tel:"whois.nic.tel",travel:"whois.nic.travel",xxx:"whois.nic.xxx",ac:"whois.nic.ac",ae:"whois.aeda.net.ae",af:"whois.nic.af",ag:"whois.nic.ag",ai:"whois.nic.ai",am:"whois.amnic.net",ar:"whois.nic.ar",as:"whois.nic.as","priv.at":"whois.nic.priv.at",at:"whois.nic.at",au:"whois.auda.org.au",aw:"whois.nic.aw",ax:"whois.ax",be:"whois.dns.be",bf:"whois.registre.bf",bg:"whois.register.bg",bh:"whois.nic.bh",bi:"whois1.nic.bi",bj:"whois.nic.bj",bm:"whois.afilias-srs.net",bn:"whois.bnnic.bn",bo:"whois.nic.bo",br:"whois.registro.br",by:"whois.cctld.by",bw:"whois.nic.net.bw",bz:"whois.afilias-grs.info","co.ca":"whois.co.ca",ca:"whois.cira.ca",cc:"ccwhois.verisign-grs.com",cd:"whois.nic.cd",ch:"whois.nic.ch",ci:"whois.nic.ci",cl:"whois.nic.cl",cm:"whois.netcom.cm","edu.cn":"whois.edu.cn",cn:"whois.cnnic.cn","uk.co":"whois.uk.co",co:"whois.nic.co",cr:"whois.nic.cr",cx:"whois.nic.cx",cz:"whois.nic.cz",de:"whois.denic.de",dk:"whois.dk-hostmaster.dk",dm:"whois.dmdomains.dm",do:"whois.nic.do",dz:"whois.nic.dz",ec:"whois.nic.ec",ee:"whois.tld.ee",eu:"whois.eu",fi:"whois.fi",fj:"www.whois.fj",fm:"whois.nic.fm",fo:"whois.nic.fo",fr:"whois.nic.fr",gd:"whois.nic.gd",ge:"whois.nic.ge",gf:"whois.mediaserv.net",gg:"whois.gg",gh:"whois.nic.gh",gi:"whois2.afilias-grs.net",gl:"whois.nic.gl",gp:"whois.nic.gp",gq:"whois.dominio.gq",gs:"whois.nic.gs",gy:"whois.registry.gy",hk:"whois.hkirc.hk",hm:"whois.registry.hm",hn:"whois.nic.hn",hr:"whois.dns.hr",ht:"whois.nic.ht",hu:"whois.nic.hu",id:"whois.id",ie:"whois.weare.ie",il:"whois.isoc.org.il",im:"whois.nic.im",in:"whois.registry.in",io:"whois.nic.io",iq:"whois.cmc.iq",ir:"whois.nic.ir",is:"whois.isnic.is",it:"whois.nic.it",je:"whois.je",jp:"whois.jprs.jp",ke:"whois.kenic.or.ke",kg:"whois.kg",ki:"whois.nic.ki",kn:"whois.nic.kn",kr:"whois.kr",kw:"whois.nic.kw",ky:"whois.kyregistry.ky",kz:"whois.nic.kz",la:"whois.nic.la",lb:"whois.lbdr.org.lb",lc:"whois2.afilias-grs.net",li:"whois.nic.li",lk:"whois.nic.lk",ls:"whois.nic.ls",lt:"whois.domreg.lt",lu:"whois.dns.lu",lv:"whois.nic.lv",ly:"whois.nic.ly",ma:"whois.registre.ma",md:"whois.nic.md",me:"whois.nic.me",mg:"whois.nic.mg",mk:"whois.marnet.mk",ml:"whois.dot.ml",mm:"whois.registry.gov.mm",mn:"whois.nic.mn",mq:"whois.mediaserv.net",mr:"whois.nic.mr",ms:"whois.nic.ms",mt:"whois.nic.org.mt",mu:"whois.nic.mu",mw:"whois.nic.mw",mx:"whois.mx",my:"whois.mynic.my",mz:"whois.nic.mz",na:"whois.na-nic.com.na",nc:"whois.nc",nf:"whois.nic.nf",ng:"whois.nic.net.ng",nl:"whois.domain-registry.nl",no:"whois.norid.no",nu:"whois.iis.nu",nz:"whois.irs.net.nz",om:"whois.registry.om",pe:"kero.yachay.pe",pf:"whois.registry.pf",pk:"whois.pknic.net.pk","co.pl":"whois.co.pl",pl:"whois.dns.pl",pm:"whois.nic.pm",pr:"whois.afilias-srs.net",ps:"whois.pnina.ps",pt:"whois.dns.pt",pw:"whois.nic.pw",qa:"whois.registry.qa",re:"whois.nic.re",ro:"whois.rotld.ro",rs:"whois.rnids.rs","ac.ru":"whois.free.net","edu.ru":"whois.informika.ru","com.ru":"whois.flexireg.net","msk.ru":"whois.flexireg.net","net.ru":"whois.nic.net.ru","nov.ru":"whois.flexireg.net","org.ru":"whois.nic.net.ru","pp.ru":"whois.nic.net.ru","spb.ru":"whois.flexireg.net",ru:"whois.tcinet.ru",rw:"whois.ricta.org.rw",sa:"whois.nic.net.sa",sb:"whois.nic.net.sb",sc:"whois2.afilias-grs.net",sd:"whois.sdnic.sd",se:"whois.iis.se",sg:"whois.sgnic.sg",sh:"whois.nic.sh",si:"whois.register.si",sk:"whois.sk-nic.sk",sl:"whois.nic.sl",sm:"whois.nic.sm",sn:"whois.nic.sn",so:"whois.nic.so",ss:"whois.nic.ss",st:"whois.nic.st","msk.su":"whois.flexireg.net","nov.su":"whois.flexireg.net","spb.su":"whois.flexireg.net",su:"whois.tcinet.ru",sx:"whois.sx",sy:"whois.tld.sy",tc:"whois.nic.tc",td:"whois.nic.td",tf:"whois.nic.tf",tg:"whois.nic.tg",th:"whois.thnic.co.th",tk:"whois.dot.tk",tl:"whois.nic.tl",tm:"whois.nic.tm",tn:"whois.ati.tn",to:"whois.tonic.to",tr:"whois.trabis.gov.tr",tv:"whois.nic.tv",tw:"whois.twnic.net.tw",tz:"whois.tznic.or.tz","biz.ua":"whois.biz.ua","co.ua":"whois.co.ua","pp.ua":"whois.pp.ua",ua:"whois.ua",ug:"whois.co.ug","ac.uk":"whois.nic.ac.uk","gov.uk":"whois.gov.uk",uk:"whois.nic.uk","fed.us":"whois.nic.gov",us:"whois.nic.us",uy:"whois.nic.org.uy",uz:"whois.cctld.uz",vc:"whois2.afilias-grs.net",ve:"whois.nic.ve",vg:"whois.nic.vg",vu:"whois.dnrs.vu",wf:"whois.nic.wf",ws:"whois.website.ws",yt:"whois.nic.yt","ac.za":"whois.ac.za","co.za":"whois.registry.net.za","gov.za":"whois.gov.za","net.za":"net-whois.registry.net.za","org.za":"org-whois.registry.net.za","web.za":"web-whois.registry.net.za",zm:"whois.zicta.zm","xn--2scrj9c":"whois.registry.in","xn--3e0b707e":"whois.kr","xn--3hcrj9c":"whois.registry.in","xn--45br5cyl":"whois.registry.in","xn--45brj9c":"whois.registry.in","xn--4dbrk0ce":"whois.isoc.org.il","xn--80ao21a":"whois.nic.kz","xn--90a3ac":"whois.rnids.rs","xn--90ae":"whois.imena.bg","xn--90ais":"whois.cctld.by","xn--clchc0ea0b2g2a9gcd":"whois.sgnic.sg","xn--d1alf":"whois.marnet.mk","xn--e1a4c":"whois.eu","xn--fiqs8s":"cwhois.cnnic.cn","xn--fiqz9s":"cwhois.cnnic.cn","xn--fpcrj9c3d":"whois.registry.in","xn--fzc2c9e2c":"whois.nic.lk","xn--gecrj9c":"whois.registry.in","xn--h2breg3eve":"whois.registry.in","xn--h2brj9c8c":"whois.registry.in","xn--h2brj9c":"whois.registry.in","xn--j1amh":"whois.dotukr.com","xn--j6w193g":"whois.hkirc.hk","xn--kprw13d":"whois.twnic.net.tw","xn--kpry57d":"whois.twnic.net.tw","xn--lgbbat1ad8j":"whois.nic.dz","xn--mgb9awbf":"whois.registry.om","xn--mgba3a4f16a":"whois.nic.ir","xn--mgbaam7a8h":"whois.aeda.net.ae","xn--mgbah1a3hjkrd":"whois.nic.mr","xn--mgbbh1a71e":"whois.registry.in","xn--mgbbh1a":"whois.registry.in","xn--mgberp4a5d4ar":"whois.nic.net.sa","xn--mgbgu82a":"whois.registry.in","xn--mgbtx2b":"whois.cmc.iq","xn--mgbx4cd0ab":"whois.mynic.my","xn--node":"whois.itdc.ge","xn--o3cw4h":"whois.thnic.co.th","xn--ogbpf8fl":"whois.tld.sy","xn--p1ai":"whois.tcinet.ru","xn--pgbs0dh":"whois.ati.tn","xn--q7ce6a":"whois.nic.la","xn--qxa6a":"whois.eu","xn--rvc1e0am3e":"whois.registry.in","xn--s9brj9c":"whois.registry.in","xn--wgbh1c":"whois.dotmasr.eg","xn--wgbl6a":"whois.registry.qa","xn--xkc2al3hye2a":"whois.nic.lk","xn--xkc2dl3a5ee0h":"whois.registry.in","xn--y9a3aq":"whois.amnic.net","xn--yfro4i67o":"whois.sgnic.sg","xn--ygbi2ammx":"whois.pnina.ps"};import q from"net";class y{options;constructor(i){this.options=i}static createConnection(i,o){new y(i).connect(o)}connect(i){let o=new q.Socket,{proxy:s,destination:e}=this.options;o.connect({port:s.port,host:s.host},()=>{if(s.type===5)this.connectSocks5(o,i);else this.connectSocks4(o,i)}),o.on("error",(c)=>{i(c)})}connectSocks4(i,o){let{destination:s,proxy:e}=this.options,c=s.port,n=e.userId||"",t;if(this.isIPv4(s.host)){let a=s.host.split(".").map(Number);t=Buffer.from(a)}else t=Buffer.from([0,0,0,1]);let r=Buffer.concat([Buffer.from([4]),Buffer.from([1]),Buffer.from([c>>8&255,c&255]),t,Buffer.from(n),Buffer.from([0])]);if(!this.isIPv4(s.host)){let a=Buffer.concat([r,Buffer.from(s.host),Buffer.from([0])]);i.write(a)}else i.write(r);i.once("data",(a)=>{if(a.length<8){o(Error("Invalid SOCKS4 response"));return}let u=a[1];if(u!==90){o(Error(`SOCKS4 connection failed with status: ${u}`));return}o(null,{socket:i})})}connectSocks5(i,o){let{destination:s,proxy:e}=this.options,c;if(e.userId&&e.password)c=[0,2];else c=[0];let n=Buffer.from([5,c.length,...c]);i.write(n),i.once("data",(t)=>{if(t.length<2||t[0]!==5){o(Error("Invalid SOCKS5 greeting response"));return}let r=t[1];if(r===255){o(Error("No acceptable authentication methods"));return}if(r===2)this.authenticateSocks5(i,o);else this.sendConnectRequest(i,o)})}authenticateSocks5(i,o){let{proxy:s}=this.options,e=s.userId||"",c=s.password||"",n=Buffer.concat([Buffer.from([1]),Buffer.from([e.length]),Buffer.from(e),Buffer.from([c.length]),Buffer.from(c)]);i.write(n),i.once("data",(t)=>{if(t.length<2||t[0]!==1){o(Error("Invalid SOCKS5 auth response"));return}if(t[1]!==0){o(Error("SOCKS5 authentication failed"));return}this.sendConnectRequest(i,o)})}sendConnectRequest(i,o){let{destination:s}=this.options,e=s.port,c,n;if(this.isIPv4(s.host)){n=1;let r=s.host.split(".").map(Number);c=Buffer.from(r)}else if(this.isIPv6(s.host)){n=4;let r=s.host.split(":"),a=[];for(let u of r){let h=Number.parseInt(u,16);a.push(h>>8&255,h&255)}c=Buffer.from(a)}else n=3,c=Buffer.concat([Buffer.from([s.host.length]),Buffer.from(s.host)]);let t=Buffer.concat([Buffer.from([5,1,0,n]),c,Buffer.from([e>>8&255,e&255])]);i.write(t),i.once("data",(r)=>{if(r.length<10||r[0]!==5){o(Error("Invalid SOCKS5 connect response"));return}let a=r[1];if(a!==0){let h=a===void 0?"No SOCKS5 status returned":{1:"General SOCKS server failure",2:"Connection not allowed by ruleset",3:"Network unreachable",4:"Host unreachable",5:"Connection refused",6:"TTL expired",7:"Command not supported",8:"Address type not supported"}[a]||`Unknown error (${a})`;o(Error(`SOCKS5 connection failed: ${h}`));return}o(null,{socket:i})})}isIPv4(i){if(!/^(?:\d{1,3}\.){3}\d{1,3}$/.test(i))return!1;return i.split(".").map(Number).every((e)=>e>=0&&e<=255)}isIPv6(i){return i.includes(":")&&i.split(":").length>=3}}var A;((s)=>{s[s.SOCKS4=0]="SOCKS4";s[s.SOCKS5=1]="SOCKS5"})(A||={});function S(i){if(Array.isArray(i))return i.slice();if(typeof i==="object"&&i!==null){let o={};for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s))o[s]=S(i[s]);return o}return i}async function N(i){let o=R+i;try{let s=await fetch(o);if(s.ok)return j(await s.text())}catch(s){console.error("Error in getting WhoIs server data from IANA",s)}return""}function j(i){return i.match(/^whois:[ \t]+(\S+)/m)?.[1]??""}function T(i){if(i==="com")return"whois.verisign-grs.com";return k[i]}function B(i){let o=i.split(".");for(let s=o.length-1;s>0;s--){let e=o.slice(s).join(".");if(k[e])return e}return o[o.length-1]}function F(i){return O[i]}class b{static iterParse(i,o){let s=(c,n)=>{let t=o[c];if(Array.isArray(t))t.push(n);else o[c]=n},e=null;for(let c of i.split(/\r?\n/)){let n=c.trim();if(n.startsWith(">>>")||n.startsWith("Record maintained by"))break;if(!n)continue;let t=n.indexOf(":"),r=t===-1?null:n.slice(0,t).trim();if(r!==null&&Object.hasOwn(o,r)){let a=n.slice(t+1).trim();if(a)s(r,a),e=null;else e=r;continue}if(e!==null)s(e,n),e=null}return o}static parseData(i,o){if(!o)o={"Domain Name":"","Creation Date":"","Updated Date":"","Registry Expiry Date":"","Domain Status":[],Registrar:""};return o=b.iterParse(i,o),o}}var P=1048576;function W(i,o){if(/[\r\n\0]/.test(i))throw Error(`Invalid WHOIS ${o}: control characters are not allowed`)}async function K(i,o,s,e,c,n){W(i,"domain"),W(o,"query options");let t=new TextDecoder(c),r=new TextEncoder,a=o!==""?`${o} ${i}\r
3
+ `:`${i}\r
4
+ `,u=(w,l,m)=>{let g=[],v=0,I=!1,d=(f)=>{if(I)return;if(I=!0,w.destroy(),f){m(f);return}let x=new Uint8Array(v),z=0;for(let C of g)x.set(C,z),z+=C.byteLength;l(t.decode(x))};w.setTimeout(30000),w.on("data",(f)=>{let x=typeof f==="string"?r.encode(f):new Uint8Array(f.buffer,f.byteOffset,f.byteLength);if(v+=x.byteLength,v>P){d(Error(`WHOIS response from ${s}:${e} exceeded ${P} bytes`));return}g.push(x)}),w.on("end",()=>d()),w.on("close",()=>d()),w.on("error",(f)=>d(f)),w.on("timeout",()=>d(Error(`WHOIS request to ${s}:${e} timed out after 30s`)))};if(!n){let w=new D.Socket;return new Promise((l,m)=>{try{u(w,l,m),w.connect({port:e,host:s},()=>{w.write(r.encode(a))})}catch(g){w.destroy(),m(g)}})}let h={proxy:{host:n.ip,port:n.port,type:n.type===1?5:4},command:"connect",destination:{host:s,port:e}};if(n.username&&n.password)h.proxy.userId=n.username,h.proxy.password=n.password;return new Promise((w,l)=>{y.createConnection(h,(m,g)=>{if(m)l(m);else{if(!g?.socket){l(Error("No socket info received!"));return}u(g.socket,w,l),g.socket.write(r.encode(a)),g.socket.resume()}})})}async function E(i,o=!1,s=null){let e,c=43,n="",t,r="utf-8";if(!s)e=B(i),t=null;else e=s.tld?s.tld:B(i),r=s.encoding?s.encoding:"utf-8",t=s.proxy?s.proxy:null,n=s.server?s.server:"",c=s.serverPort?s.serverPort:43;if(n===""){let h=T(e);if(!h){if(p.debug(`No WhoIs server found for TLD: ${e}! Attempting IANA WhoIs database for server!`),h=await N(e),!h)return p.debug("WhoIs server could not be found!"),{_raw:"",parsedData:null};p.debug(`WhoIs sever found for ${e}: ${n}`)}n=h}let u=F(n)||"";try{p.debug(`Attempting WHOIS lookup for ${i} on server ${n}`);let h=await K(i,u,n,c,r,t);if(p.debug("Raw WHOIS data received:",h),!o){let l=b.parseData(h,null);return{_raw:h,parsedData:l}}let w=null;if(s?.parseData)w=S(s.parseData);try{let l=b.parseData(h,w);return{_raw:h,parsedData:l}}catch(l){return console.error("Error in parsing WhoIs data!",l),{_raw:h,parsedData:null}}}catch(h){return p.debug(`Error in WHOIS lookup for ${i} on server ${n}`,h),{_raw:"",parsedData:null}}}function J(i,o=null){return p.debug(`Lookup called for ${i}`),E(i,!0,o)}async function Z(i,o=!1,s=1,e=!1,c=null){let n=[];if(o){let t=Math.max(1,Math.min(i.length||1,Math.floor(Number.isFinite(s)?s:1)));for(let r=0;r<i.length;r+=t){let a=i.slice(r,r+t),u=await Promise.all(a.map(async(h)=>await E(h,e,c)));n.push(...u)}}else for(let t=0;t<i.length;t++){let r=await E(i[t],e,c);n.push(r)}return n}export{R as IANA_CHK_URL,O as PARAMETERS,A as ProxyType,k as SERVERS,y as SocksClient,b as WhoIsParser,Z as batchWhois,N as findWhoIsServer,F as getParameters,B as getTLD,T as getWhoIsServer,J as lookup,j as parseIanaWhoisServer,K as tcpWhois,E as whois};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/whois",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.734",
5
+ "version": "0.75.755",
6
6
  "description": "Easily get whois info.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -60,9 +60,9 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "dependencies": {
63
- "@stacksjs/logging": "0.75.734"
63
+ "@stacksjs/logging": "0.75.755"
64
64
  },
65
65
  "devDependencies": {
66
- "better-dx": "^0.2.39"
66
+ "better-dx": "^0.2.41"
67
67
  }
68
68
  }