Setting address of whois service for ruby whois gem

耗尽温柔 提交于 2019-12-24 11:05:20

问题


Using the ruby whois gem, how do I set the server address of the whois service?

Setting the bind_host, I get an error.

> whois_client = Whois::Client.new(bind_host: "192.0.47.59", bind_port: 43)
=> #<Whois::Client:0x00000008188e7e50 @timeout=10, @settings={:bind_host=>"192.0.47.59", :bind_port=>43}>
> record = whois_client.lookup('wandajackson.com')
Whois::ConnectionError: Errno::EADDRNOTAVAIL: Can't assign requested address - bind(2) for "192.0.47.59" port 43
    from (irb):4

回答1:


I'm pretty sure bind_host doesn't refer to the host used for the whois lookup, but instead refers to the adapter binding on the server running your code. By default it binds to 0.0.0.0, or all the adapters on the local server.

If you want to have the whois gem use a custom server address for looking up whois information then it appears that you have to specify it in one of the following ways:

# Define a server for the .com TLD
Whois::Server.define :tld, "com", "your.whois.server.address"
Whois.whois("google.com")

# Define a new server for an range of IPv4 addresses
Whois::Server.define :ipv4, "10.0.0.0/8", "your.whois.server.address"
Whois.whois("10.0.0.1")

# Define a new server for an range of IPv6 addresses
Whois::Server.define :ipv6, "2001:2000::/19", "your.whois.server.address"
Whois.whois("2001:2000:85a3:0000:0000:8a2e:0370:7334")

These examples were taken from https://www.rubydoc.info/gems/whois/Whois/Server.



来源:https://stackoverflow.com/questions/52431103/setting-address-of-whois-service-for-ruby-whois-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!