python实现
vi port.py
import socket
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sk.settimeout(1)
try:
sk.connect((‘127.0.0.1‘,22))
print ‘Server port 22 OK!‘
except Exception:
print ‘Server port 22 not connect!‘
sk.close()
shell实现
vi port.sh
#/bin/bash
port=`ssh 192.168.93.136 ‘netstat -atnulp | grep -w 0.0.0.0:22 | wc -l‘`
if [[ $port -eq 1 ]]
then
echo -e " \033[32m port 22 ok !! \033[0m"
else [[ $port -eq 0 ]]
echo -e " \033[32m port 22 not ok !! \033[0m"
fi
[[email protected] opt]# sh port.sh
port 22 ok !!
[[email protected] opt]# python port.py
Server port 22 OK!
时间: 2024-12-21 03:09:48