Socket.SetIPProtectionLevel(IPProtectionLevel) Socket.SetIPProtectionLevel(IPProtectionLevel) Socket.SetIPProtectionLevel(IPProtectionLevel) Socket.SetIPProtectionLevel(IPProtectionLevel) Method


设置套接字的 IP 保护级别。Set the IP protection level on a socket.

 void SetIPProtectionLevel(System::Net::Sockets::IPProtectionLevel level);
public void SetIPProtectionLevel (System.Net.Sockets.IPProtectionLevel level);
member this.SetIPProtectionLevel : System.Net.Sockets.IPProtectionLevel -> unit
Public Sub SetIPProtectionLevel (level As IPProtectionLevel)


IPProtectionLevel IPProtectionLevel IPProtectionLevel IPProtectionLevel

要为此套接字设置的 IP 保护级别。The IP protection level to set on this socket.


level 参数不能为 UnspecifiedThe level parameter cannot be Unspecified. IP 保护级别不能设置为未指定。The IP protection level cannot be set to unspecified.


使用SetIPProtectionLevel方法, 可以限制 IPv6 或 IP 套接字侦听指定的作用域, 如具有相同链接本地或站点本地前缀的地址。The SetIPProtectionLevel method enables restricting an a IPv6 or IP socket to listen on a specified scope, such as addresses with the same link local or site local prefix. 此套接字选项使应用程序可以对 IPv6 或 IP 套接字设置访问限制。This socket option enables applications to place access restrictions on IPv6 or IP sockets. 通过应用此类限制,可让在专用局域网上运行的应用程序能够通过简单的方式很好地增强自身的安全性,以便防范外部攻击。Such restrictions enable an application running on a private LAN to simply and robustly harden itself against external attacks. 如果level将参数设置为Unrestricted, 还可以使用此套接字选项来删除访问限制。This socket option can also be used to remove access restrictions if the level parameter is set to Unrestricted. 此套接字选项可以扩大或缩小侦听套接字的范围,从而使得公共用户和私人用户可以在适当情况下对站点进行无限制的访问,或者可以根据需要对同一站点进行有限制的访问。This socket option widens or narrows the scope of a listening socket, enabling unrestricted access from public and private users when appropriate, or restricting access only to the same site, as required.

此套接字选项具有 IPProtectionLevel 枚举中指定的已定义保护级别。This socket option has defined protection levels specified in the IPProtectionLevel enumeration.

方法用于启用或禁用Socket实例的网络地址遍历 (NAT)。 SetIPProtectionLevelThe SetIPProtectionLevel method is used to enable or disable Network Address Traversal (NAT) for a Socket instance. 可以使用 Teredo、6to4 或 ISATAP 隧道来提供 NAT 遍历。NAT traversal may be provided using Teredo, 6to4, or an ISATAP tunnel.

当参数设置为EdgeRestrictedRestrictedSocket , 这会显式禁用实例的 NAT 遍历。 levelWhen the level parameter is set to EdgeRestricted, or Restricted, this explicitly disables NAT traversal for a Socket instance.

当参数设置为EdgeRestricted时, 这可能会Socket允许 NAT 遍历系统上的防火墙规则。 levelWhen the level parameter is set to EdgeRestricted, this may allow NAT traversal for a Socket depending on firewall rules in place on the system.