这个域名解析出什么
按模型,resolve("api", {"api": "10.0.0.1"}) 交回什么?
贯穿本节的全链路模型(判题机不联网、镜像没 dig/tcpdump,这是它的确定模型,见 spine.py):一次访问要依次走通四步——解析(DNS) → 连接(TCP) → 加密(TLS) → 请求(HTTP);证据 ev 是 {步名: 是否 OK}。
采证据:resolve(域名, 解析表)=A 记录 IP(没有交空串)、tcp_ok(端口, 监听表)=端口在听、http_status(路由表, 路径)=状态码(没有交 404)。
def resolve(host, table):
"""DNS A 查询:解析表里有就交回 IP,没有交回空串。"""
return table.get(host, "")
def tcp_ok(port, listening):
"""端口在监听列表里才算连得上。"""
return port in listening
def http_status(routes, path):
"""路由表里取该路径的状态码,没有交回 404。"""
return routes.get(path, 404)
print(resolve("api", {"api": "10.0.0.1"}))
全部评论