简体   繁体   English

如何在onBeforeRequest中接收客户端的公共IP地址

[英]how to receive the public IP address of client in onBeforeRequest

I would like to write an extension to block requests to a specific website according to the IP address.我想根据 IP 地址编写一个扩展来阻止对特定网站的请求。 I've already written this code that blocks all requests related to *://*.google.com/* .我已经编写了这段代码来阻止与*://*.google.com/*相关的所有请求。 My question is how can I block requests in onBeforeRequest based on the IP addresses?我的问题是如何根据 IP 地址阻止onBeforeRequest中的请求?

var urls = [
    '*://*.google.com/*',
  ];

  var types = ['main_frame', 'sub_frame']
  
  var response = async function(d){
    return true
  };
  
  chrome.webRequest.onBeforeRequest.addListener(response, { urls: urls, types: types }, ['blocking'] );

This isn't possible.这是不可能的。 The documentation for onBeforeRequest shows that this isn't information that's available to an extension at this point. onBeforeRequest的文档显示,这不是目前可用于扩展的信息。

This makes sense, however, as at this point in the lifecycle the browser most likely hasn't made any DNS queries for the IP address of the server at the domain - it simply wouldn't be able to know without making those queries.然而,这是有道理的,因为在生命周期的这一点上,浏览器很可能还没有对域中服务器的 IP 地址进行任何 DNS 查询 - 如果不进行这些查询,它根本无法知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM