如果您可以在浏览器中访问比 TCP 更低的级别

If you can go lower level than TCP in the browser

我正在学习 Network Protocols,看到最底层附近是原始以太网协议:

Ethernet: this is the basic protocol that sends data to another machine on your local network using your MAC address. This is the building block for all the rest as you need to send data to the router if you want to communicate with the outside world.

上面是网际协议(IP),例如TCP和UDP。在 TCP 之上是 HTTP,或者 SSL,您可以在其之上放置 HTTP(因此是 HTTPS)。

浏览器似乎只允许您进入 IP 级别(TCP 用于正常的消息传递连接,UDP 用于视频等)。但我想知道,是否有可能比浏览器中的更低。如果没有,那么想知道为什么不。如果是这样,那么可能是一个例子。

出于安全原因,浏览器只允许使用一组明确定义的协议。如果不是这种情况,Javascript 网站上可能会发送任意数据包并导致恶意行为。

因此,浏览器 API 仅限于提供 HTTP、websockets 和 webrtc。

在美好的过去(直到大约 3 年前)浏览器通过允许 运行 第 3 方插件解决了这个问题,并且有(现在仍然有)这些插件的 API,例如 NPAPI 和 ActiveX 控件。所以你可以创建一个插件来做任何你想做的事情,用原始套接字或你自己的协议发送数据。 Flash 插件是最好的例子,还有许多鲜为人知的插件,用于特定的网络应用程序,例如网络会议、聊天、安全数据交换等......一些浏览器仍然支持这些插件 - IE、Opera、Firefox,但是 Chrome 并且 Edge 完全禁用了它们。原因是安全问题 - 如果您可以将自己的本机代码加载到浏览器中,那么您可以完全访问 OS,拦截浏览器中的所有数据,等等......作为这种禁用自由的替代品,一些浏览器试图发明新的更安全的 API,例如 Chrome 的 PPAPI。主要是失败的尝试。浏览器对 websockets 的采用缓解了这种情况,但仍然有很多网络事物在浏览器中是不可能的。一个臭名昭著的例子是浏览器中缺乏对 UDP 多播的支持。以前你可以用你自己的 NPAPI 插件来做;现在浏览器没有提供替代品,所以你的 browser-based multicast-involved 应用程序已经死了。

“It seems that the browser only lets you go down to the level of the IP (TCP for your normal message passing connections, and UDP for things like video).”

首先TCP和UDP是不是IP的例子。它们是 Transport 层协议,即 IP 之上的一层。

5 层模型的这种表示应该有助于区分:

  • 其次,如果'深入到以太网级别'你的意思是用浏览器的开发工具检查数据包,你不能那样做。您只能看到 HTTP 数据包。

如果您想观察所有流量,可以使用 Wireshark - or Fiddler 等工具来捕获和检查不同层的数据包。

  • 如果您询问浏览器是否可以使用 应用层 以外的任何层。不,它不能。这也是为什么您只能观察 HTTP 数据包的原因,因为那是浏览器运行的层。

信息从一层传播到另一层,但不跳过层:

您的网页请求使用了所有层。它从应用层开始,即面向用户的层,一直向下堆栈,直到网络层将您的请求传输到服务器的网络层,然后向上堆栈获取网页。

The packet is the basic unit of information that is transferred across a network. The packet consists, at a minimum, of a header with the sending and receiving hosts' addresses, and a body with the data to be transferred. As the packet travels through the TCP/IP protocol stack, the protocols at each layer either add or remove fields from the basic header. When a protocol on the sending host adds data to the packet header, the process is called data encapsulation. Moreover, each layer has a different term for the altered packet, as shown in the following figure.

您可以在这篇关于 Data Encapsulation and the TCP/IP Protocol Stack

的文章中详细了解数据包在协议栈中传输的方式