RTCIceCandidate interface's read-only address property is a string providing the address of the device which is the source of the candidate. address is null by default if not otherwise specified.

address field's value is set when the RTCIceCandidate() constructor is used. You can't specify the address in the options object, but the address is automatically extracted from the candidate a-line, if it's formatted properly.

句法

var address = RTCIceCandidate.address;
					

A DOMString providing the IP address from which the candidate comes.

注意: port is null — and port is supported by the 用户代理 — passing the candidate to addIceCandidate() will fail, throwing an OperationError 异常。

Security notes

It's important to note here that although WebRTC does not require the two peers on an RTCPeerConnection to know one another's true IP addresses, the address property on RTCIceCandidate can expose more information about the source of the remote peer than the user expects. The IP address can be used to derive information about the remote device's location, network topology, and so forth. It can also be used for fingerprinting purposes.

The candidate IP addresses are always exposed to the application through address , and unsavory applications can in turn potentially reveal the address to the user. This can occur without the remote peer's consent.

Applications being built with user privacy and security in mind can choose to limit the permitted candidates to relay candidates only. Doing so prevents the remote user's address from being exposed, but reduces the pool of available candidates to choose from. To do this, configure the ICE agent's ICE transport policy using RTCConfiguration ,像这样:

var rtcConfig = {
  iceServers: [
    {
      urls: "turn:myturn.server.ip",
      username: "username",
      credential: "password"
    }
  ],
  iceTransportPolicy: "relay"
}
					

通过设置 RTCConfiguration.iceTransportPolicy to "relay" , any host candidates (candidates where the IP address is the peer's own IP address) are left out of the pool of candidates, as are any other candidates which aren't relay candidates.

用法注意事项

Consider this SDP attribute line (a-line) which describes an ICE candidate:

a=candidate:4234997325 1 udp 2043278322 192.168.0.56 44323 typ host
					

The fifth field, "192.168.0.56" is the IP address in this candidate's a-line string.

范例

This code snippet uses the value of address to implement an IP address based ban feature.

if (ipBanList.includes(candidate.address)) {
  rejectCandidate(candidate);
} else {
  acceptCandidate(candidate);
}
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceCandidate: address' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
address Chrome 74 Edge 79
79
≤18 — 79 Alternate Name
Alternate Name Uses the non-standard name: ip
Firefox ? IE 不支持 No Opera ? Safari ? WebView Android 74 Chrome Android 74 Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android 11.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

使用非标名称。

使用非标名称。

元数据

  • 最后修改: