FurqanSoftware / node-whois

A simple WHOIS client for NodeJS
https://npmjs.org/package/whois
Other
250 stars 77 forks source link

IPV6 Lookup Fails #130

Open Takeda0x64 opened 2 weeks ago

Takeda0x64 commented 2 weeks ago

Explanation

When performing a WHOIS lookup using the whois.lookup() function on an IPv6 address (e.g., 2001:4860:4860::8888), the response is returning No match found. However, when executing the same lookup using the WHOIS command in the CLI, the correct information is displayed, such as the net range, organization details, and relevant WHOIS data.

Expected Behavior: The node-whois module should return complete and accurate WHOIS information for IPv6 addresses, similar to what is received via the CLI.

Actual Behavior: The module returns incomplete or incorrect results when querying IPv6 addresses

Steps to Reproduce:

1- Call the method wiht Ipv6 input (e.g., 2001:4860:4860::8888) :

whois.lookup("2001:4860:4860::8888", (err,data) =>{
    console.log(data);
})    

The output is :


#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/resources/registry/whois/tou/
#
# If you see inaccuracies in the results, please report at
# https://www.arin.net/resources/registry/whois/inaccuracy_reporting/
#
# Copyright 1997-2024, American Registry for Internet Numbers, Ltd.
#

No match found for n + .

#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/resources/registry/whois/tou/
#
# If you see inaccuracies in the results, please report at
# https://www.arin.net/resources/registry/whois/inaccuracy_reporting/
#
# Copyright 1997-2024, American Registry for Internet Numbers, Ltd.
#

Perform the same lookup using the whois CLI:

whois 2001:4860:4860::8888

CLI response :

#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/resources/registry/whois/tou/
#
# If you see inaccuracies in the results, please report at
# https://www.arin.net/resources/registry/whois/inaccuracy_reporting/
#
# Copyright 1997-2024, American Registry for Internet Numbers, Ltd.
#

NetRange:       2001:4860:: - 2001:4860:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
CIDR:           2001:4860::/32
NetName:        GOOGLE-IPV6
NetHandle:      NET6-2001-4860-1
Parent:         ARIN-004 (NET6-2001-4800-0)
NetType:        Direct Allocation
OriginAS:       AS15169
Organization:   Google LLC (GOGL)
RegDate:        2005-03-14
Updated:        2012-02-24
Ref:            https://rdap.arin.net/registry/ip/2001:4860::

OrgName:        Google LLC
OrgId:          GOGL
Address:        1600 Amphitheatre Parkway
City:           Mountain View
StateProv:      CA
PostalCode:     94043
Country:        US
RegDate:        2000-03-30
Updated:        2019-10-31
Comment:        Please note that the recommended way to file abuse complaints are located in the following links. 
Comment:        
Comment:        To report abuse and illegal activity: https://www.google.com/contact/
Comment:        
Comment:        For legal requests: http://support.google.com/legal 
Comment:        
Comment:        Regards, 
Comment:        The Google Team
Ref:            https://rdap.arin.net/registry/entity/GOGL

OrgAbuseHandle: ABUSE5250-ARIN
OrgAbuseName:   Abuse
OrgAbusePhone:  +1-650-253-0000 
OrgAbuseEmail:  network-abuse@google.com
OrgAbuseRef:    https://rdap.arin.net/registry/entity/ABUSE5250-ARIN

OrgTechHandle: ZG39-ARIN
OrgTechName:   Google LLC
OrgTechPhone:  +1-650-253-0000 
OrgTechEmail:  arin-contact@google.com
OrgTechRef:    https://rdap.arin.net/registry/entity/ZG39-ARIN

RNOCHandle: ZG39-ARIN
RNOCName:   Google LLC
RNOCPhone:  +1-650-253-0000 
RNOCEmail:  arin-contact@google.com
RNOCRef:    https://rdap.arin.net/registry/entity/ZG39-ARIN

RTechHandle: ZG39-ARIN
RTechName:   Google LLC
RTechPhone:  +1-650-253-0000 
RTechEmail:  arin-contact@google.com
RTechRef:    https://rdap.arin.net/registry/entity/ZG39-ARIN

RAbuseHandle: ZG39-ARIN
RAbuseName:   Google LLC
RAbusePhone:  +1-650-253-0000 
RAbuseEmail:  arin-contact@google.com
RAbuseRef:    https://rdap.arin.net/registry/entity/ZG39-ARIN

#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/resources/registry/whois/tou/
#
# If you see inaccuracies in the results, please report at
# https://www.arin.net/resources/registry/whois/inaccuracy_reporting/
#
# Copyright 1997-2024, American Registry for Internet Numbers, Ltd.
Takeda0x64 commented 2 weeks ago

I created a patch to resolve the bug, and now everything works as expected. The issue was in the domainToASCII function, which returns an empty string when passed an IPv6 address.

if server.punycode isnt false and options.punycode isnt false
       idn = url.domainToASCII(addr)
if options.encoding
       socket.setEncoding options.encoding
       socket.write server.query.replace '$addr', idn

The patch sets both server.punycode and options.punycode to false, ensuring that they do not pass the condition check so domainToASCII will not be invoked if IPv4 or IPv6 is passed :

when net.isIP(addr) isnt 0
   server = @SERVERS['_']['ip']
   server.punycode = false
   options.punycode = false
Takeda0x64 commented 2 weeks ago

Also IPV6 test passes

 ✔ should work with google.com
 ✔ should work with 50.116.8.109
 ✔ should work with 2001:0db8:11a3:09d7:1f34:8a2e:07a0:765d
 ✔ should honor specified WHOIS server
 ✔ should honor specified WHOIS server with port override