parent
91a9673c8a
commit
9c67d1ad81
@ -0,0 +1,52 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
# 定义颜色 |
||||||
|
RED='\033[0;31m' |
||||||
|
GREEN='\033[0;32m' |
||||||
|
NC='\033[0m' # No Color |
||||||
|
|
||||||
|
# 检测网络连接的函数 |
||||||
|
function network() { |
||||||
|
if ping -c 2 www.baidu.com &> /dev/null; then |
||||||
|
printf "[ ${GREEN}OK${NC} ]\n" |
||||||
|
else |
||||||
|
printf "[ ${RED}Failed${NC} ]\n" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# 检测SSH服务是否开启的函数 |
||||||
|
function ssh_service() { |
||||||
|
if systemctl status sshd &> /dev/null; then |
||||||
|
printf "[ ${GREEN}OK${NC} ]\n" |
||||||
|
else |
||||||
|
printf "[ ${RED}Failed${NC} ]\n" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# 检测防火墙是否开启的函数 |
||||||
|
function firewall() { |
||||||
|
if systemctl status firewalld &> /dev/null; then |
||||||
|
printf "[ ${GREEN}OK${NC} ]\n" |
||||||
|
else |
||||||
|
printf "[ ${RED}Failed${NC} ]\n" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# 检测SELinux状态的函数 |
||||||
|
function selinux() { |
||||||
|
se_status=$(getenforce) |
||||||
|
if [ "$se_status" = "Enforcing" ] || [ "$se_status" = "Permissive" ]; then |
||||||
|
printf "[ ${GREEN}OK${NC} ]\n" |
||||||
|
else |
||||||
|
printf "[ ${RED}Failed${NC} ]\n" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# 执行函数并直接使用其输出 |
||||||
|
echo "当前时间: [ $(date '+%F %X') ]" |
||||||
|
echo "网络地址: [ $(ip -4 a show dev ens33 | awk 'NR==2{print $2}') ]" |
||||||
|
echo -n "网络连接: "; network |
||||||
|
echo -n "远程连接: "; ssh_service |
||||||
|
echo -n "防火墙: "; firewall |
||||||
|
echo -n "SELinux: "; selinux |
||||||
|
|
Loading…
Reference in new issue