中级
实现屏幕IP白名单校验
未完成
中级参考
代码结构已给出,请填写 ____ 处
def solve():
import ipaddress
SUBNETS = ['____','____','____']
def ip_ok(____):
try:
ip_obj = ipaddress.ip_address(____)
for s in SUBNETS:
if ip_obj in ipaddress.ip_network(____): return True, s
return False, None
except: return False, '____'
tests = [(____),(____),(____),(____)]
print(____)
for ip, expected in tests:
ok, subnet = ip_ok(____)
result = '____' if ok==expected else '____'
print("____"+ip+"____"+str(____)+"____"+str(____)+"____"+result+"____")
示例
输入
solve()
期望输出
IP whitelist check: 10.1.5.22: ok=True subnet=10.0.0.0/8 [PASS] 192.168.1.100: ok=True subnet=192.168.0.0/16 [PASS] 8.8.8.8: ok=False subnet=None [PASS] 172.16.0.1: ok=True subnet=172.16.0.0/12 [PASS]
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199