Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 是否只允许Google查看sitemap.xml?_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 是否只允许Google查看sitemap.xml?

Ruby on rails 是否只允许Google查看sitemap.xml?,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,我试图限制对sitemap.xml的访问,但前提是谷歌使用以下代码访问它: reverse_dns = Resolv.getname(request.remote_ip) throw_404 unless reverse_dns.include?("goog") || reverse_dns.include?("localhost") 但是如果没有ip地址的主机名,它就会失败。例如: Resolv::ResolvError:64.233.191.255没有名称 这是一个谷歌机器人的ip地址 任

我试图限制对
sitemap.xml
的访问,但前提是谷歌使用以下代码访问它:

reverse_dns = Resolv.getname(request.remote_ip)
throw_404 unless reverse_dns.include?("goog") || reverse_dns.include?("localhost")
但是如果没有ip地址的主机名,它就会失败。例如:

Resolv::ResolvError:64.233.191.255没有名称

这是一个谷歌机器人的ip地址


任何关于如何实现这一点或Stackoverflow如何实现这一点的想法(Stackexchange也将其sitemap.xml限制为Google)。

不要使用反向DNS,而是使用whois——因为Google的一些ip甚至没有反向DNS记录设置

因此,请使用
whois
gem在ip上创建完整的whois:

gem“whois”

IANA特殊用途通常在查询本地网络ip地址(127.0.0.1或10.0.1.1等)时使用

whois = Whois.whois(request.remote_ip).parts[0]['body']
throw_404 unless whois.include?("google") || whois.include?("IANA Special Use")