shell-scripts/tutorials/basic/12-port-check.sh

27 lines
678 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#Program:
# 检查机器的开放服务比如Http服务(80), https服务(443)ssh服务(22),邮箱服务(25)
#History:
# 2024/07/14 LouisFonda<yigencong@yahoo.com>
testfile=/dev/shm/netstat_checking.txt # 保存端口信息到内存
netstat -tunl > ${testfile}
echo -e "本机开通了如下服务"
testing=$(grep ":80" ${testfile})
if [ "${testing}" != "" ]; then
echo "http服务"
fi
testing=$(grep ":443" ${testfile})
if [ "${testing}" != "" ]; then
echo "https服务"
fi
testing=$(grep ":22" ${testfile})
if [ "${testing}" != "" ]; then
echo "ssh服务"
fi
testing=$(grep ":25" ${testfile})
if [ "${testing}" != "" ]; then
echo "email服务"
fi