在Windows IIS系统中,可以通过配置web.config
文件来屏蔽特定IP地址或IP段的访问。以下是配置示例:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<ipSecurity allowUnlisted="true">
<clear/> <!-- 清除所有之前的IP规则 -->
<add ipAddress="127.0.0.1"/> <!-- 允许单个IP地址访问 -->
<!-- 删除: <add ipAddress="127.255.255.0" subnetMask="255.255.255.0"/> <!-- 屏蔽整个IP段 -->
<!-- 删除: <add ipAddress="192.168.1.0" subnetMask="255.255.255.0"/> <!-- 屏蔽另一个IP段 -->
</ipSecurity>
</security>
</system.webServer>
</configuration>
解释:
allowUnlisted="true"
:允许未列出的IP地址访问。<clear/>
:清除所有之前的IP规则。<add ipAddress="127.0.0.1"/>
:允许单个IP地址访问。- 注释掉的行表示被屏蔽的IP段,可以根据需要添加或删除。