Skip to content

Instantly share code, notes, and snippets.

@J1nH4ng
Last active February 14, 2025 14:05
Show Gist options
  • Save J1nH4ng/9f8222b3f5ba0b13c9a9678feda248a2 to your computer and use it in GitHub Desktop.
Save J1nH4ng/9f8222b3f5ba0b13c9a9678feda248a2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Description: compare IP is right.
# Author: J1nH4ng<[email protected]>
# Date: 2025-02-14
# Version: V1.0.0.20250214_public
expected_ip=$1
current_ip=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)
if [ "$current_ip" == "$expected_ip" ]; then
echo -e "\033[1;32m验证通过\033[0m -- 当前 IP 地址为:\033[1;33m${current_ip}\033[0m"
else
echo -e "\033[1;31m验证失败\033[0m -- 当前 IP 地址为:\033[1;33m${current_ip}\033[0m,预期 IP 地址为:\033[1;33m${expected_ip}\033[0m,请退出检查配置!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment