Coder Social home page Coder Social logo

Comments (9)

weppos avatar weppos commented on July 29, 2024

@njh I was able to run the same query. Are you running an high volume of requests? You may have been throttled.

from whois.

njh avatar njh commented on July 29, 2024

No, I am not running a high volume of requests.

My 'production' script looks up 13 domains, with a 1 second pause between each one.
But I have this problem when running the one-off test too. On a different IP at a different time.

I am now wondering if it is related to me using IPv6. This is what I found with lsof -ni:

TCP [2001:8b0:ffd5:3:xxxx]:64293->[2406:da00:ff00::34c9:6d7f]:nicname (SYN_SENT)

Do you have IPv6? I guess it is possible there is a problem with their IPv6 network / rate limiting.

from whois.

weppos avatar weppos commented on July 29, 2024

Do you have IPv6?

No, I believe I'm currently binding to an IPv4 address.

from whois.

weppos avatar weppos commented on July 29, 2024

Closing as not dependent by the library.

from whois.

njh avatar njh commented on July 29, 2024

Just been looking into this and it looks like Amazon's Registrar isn't responding to connections on port 43 when using IPv6. I have reported it on the AWS forum:
https://forums.aws.amazon.com/thread.jspa?threadID=317497

If you don't have IPv6, then ruby (or the OS?) won't attempt to connect to the IPv6 address, and happily connect to the working IPv4 address.

Would you accept a PR that switches from TCPSocket to Net::TCPClient?

This would improve IPv4-only connections too, as if a registrar publishes multiple IP addresses in DNS (as most do), it will attempt each one in turn.

from whois.

weppos avatar weppos commented on July 29, 2024

Thanks for researching into it @njh! I'm not thrilled about the idea of introducing a dependency to a third party library, especially to circumvent a specific provider issue.

I am interested to explore other options.

Can I ask you how did you find this issue? In Ruby, you can pass a binding IP address to the TPC socket. This library supports it by using bind_host.

c = Whois::Client.new(bind_host: "192.168.1.100")

Would you be able to test by binding the local IPv4 network? I will need to spend some time to determine who's responsible for choosing the IPv6 address over IPv4 when resolving the whois host.

from whois.

njh avatar njh commented on July 29, 2024

I started down this route because my personal domain checking script (that uses this gem) kept failing and timing out. I have IPv6 at home and on my VPS, so it took a while to realise that it was IPv6 related.

It is getting much better, but unfortunately it is not uncommon for some IPv6 networks and services to have periods of downtime. Partly because monitoring is in place for IPv4 but not IPv6.

However this improvement could have benefits for non-IPv6 users too. For example whois.verisign-grs.com has two IPv4 addresses associated with it:

$ host whois.verisign-grs.com
whois.verisign-grs.com has address 192.30.45.30
whois.verisign-grs.com has address 192.34.234.30
whois.verisign-grs.com has IPv6 address 2620:74:20::30
whois.verisign-grs.com has IPv6 address 2620:74:21::30

If one of the servers are down (for example 192.30.45.30), then it won't currently fail over to the other server (192.34.234.30). It will just timeout after attempting the first IP address.

Web browsers have tried to solve this problem using an approach called Happy Eyeballs / RFC8305.
However I think something simpler should be possible for whois.

  1. Lookup the hostname in DNS
  2. Loop through each of the IP addresses returned
  3. Attempt to connect to port 43 for each address
  4. If successful, send request and return result
  5. If unsuccessful, timeout after a few seconds and move on to the next address

It is a shame that ruby doesn't have a internal implementation to do this for you.
But I will see if I can write some proof of concept code, to avoid adding an external dependency.

from whois.

njh avatar njh commented on July 29, 2024

This little proof of concept is working for me. It loops through each of the addresses for a hostname and stops when it gets a response:

def whois_request(address, domain)
  result = nil
  Socket.tcp(address, 43, connect_timeout: 5) do |sock|
    sock.write("DOMAIN #{domain}\r\n")
    result = sock.readlines
  end
  result
end

Resolv.each_address('whois.verisign-grs.com') do |address|
  begin
    puts "Trying: #{address}"
    result = whois_request(address, 'aelius.com')
    unless result.nil?
      puts "Success! Read #{result.count} lines."
      break
    end
  rescue Errno::ETIMEDOUT => exp
    puts "Timed out while connecting to #{address}"
  end
end

Note that it uses Socket.tcp() instead of TCPSocket.new because the later doesn't support setting a connect timeout. I think Socket.tcp() was added in Ruby 2.x.

I did try your suggestion of binding the local socket to my IPv4 address and it does work as a workaround (thanks!). I even found that you can bind it to 0.0.0.0 to force IPv4 but not have to hard code a specific address:

whois = Whois::Client.new(:bind_host => "0.0.0.0")

However it feels like a very hacky solution to the problem.

from whois.

njh avatar njh commented on July 29, 2024

I have discovered that Resolv.each_address doesn't respect operating system preferences (for example the configuration in /etc/gai.conf).

Here is a revision that uses Addrinfo.foreach instead, which attempts connections in the correct order:

def whois_request(addrinfo, domain)
  result = nil
  Socket.tcp(addrinfo.ip_address, addrinfo.ip_port, connect_timeout: 5) do |sock|
    sock.write("DOMAIN #{domain}\r\n")
    result = sock.readlines
  end
  result
end

Addrinfo.foreach("whois.verisign-grs.com", "whois", nil, Socket::SOCK_STREAM, Socket::IPPROTO_TCP).each do |addrinfo|
  begin
    puts "Trying: #{addrinfo.inspect}"
    result = whois_request(addrinfo, 'aelius.com')
    unless result.nil?
      puts "Success! Read #{result.count} lines."
      break
    end
  rescue Errno::ETIMEDOUT => exp
    puts "Timed out while connecting to #{addrinfo.ip_address}"
  end
end

from whois.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.