bash - 如何使用bash检查子域是否正确重定向到特定IP地址?
问题描述
我想用 bash 检查子域是否重定向到特定的 IP 地址。
这是我目前的检查方式;
ping -c 3 subdomain.example.com
我还需要检查 IPv6,我现在就是这样做的;
ping6 -c 3 subdomain.example.com
但我不知道如何使用 bash 脚本自动检查。
我不必ping
专门使用,但我只需要检查特定地址IPv4
和IPv6
地址是否都正确重定向到我的子域。
有没有办法做到这一点?
解决方案
然后这将执行您想要测试主机的 DNS 条目的操作。
#!/usr/bin/env bash
host="www.example.com"
ipv4="93.184.216.34"
ipv6="2606:2800:220:1:248:1893:25c8:1946"
if [[ "$(host -t A "$host" 2>/dev/null)" =~ address\ ([[:digit:].]+) ]] \
&& [[ ${BASH_REMATCH[1]} == "$ipv4" ]] \
&& [[ "$(host -t AAAA "$host" 2>/dev/null)" =~ address\ ([[:xdigit:]:]+) ]] \
&& [[ ${BASH_REMATCH[1]} == "$ipv6" ]]; then
printf 'Host %s is pointing to expected ip addresses:\nIPv4: %s\nand IPv6: %s\n' "$host" "$ipv4" "$ipv6"
fi
输出:
Host www.example.com is pointing to expected ip addresses:
IPv4: 93.184.216.34
and IPv6: 2606:2800:220:1:248:1893:25c8:1946
推荐阅读
- python - 是否可以实现多个目标?(OR-TOOLS 约束编程)
- python - 需要及时扩展的值
- javascript - 从 Chrome 扩展程序以编程方式设置受控表单值
- c - 在结构中创建动态列表
- python - 如何使用 xlwings 删除 Excel 过滤器
- c++ - OpenGL 因当前代码而崩溃(从书中开始)
- flutter - Flutter如何知道Expansion Tile List的深度?
- customization - 在 Acumatica 中,为什么我的 JournalEntry 扩展代表没有触发?
- java - Spring Batch - 读取字节流,处理,写入 2 个不同的 csv 文件,将它们转换为输入流并将其存储到 ECS,然后写入数据库
- python - 如何查找游戏代码是否有多个使用熊猫的用户?