python 检查端口存活状态

简介: !/usr/bin/env pythoncheck lvs portimport socket,syshost = '172.16.54.94'port = '9999'def conn(host,port):try:s = socket.

!/usr/bin/env python

check lvs port

import socket,sys
host = '172.16.54.94'
port = '9999'
def conn(host,port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((str(host),int(port)))
s.settimeout(2)
print 'Server port %s OK!' % port
sys.exit(0)
except Exception:
print 'Server %s port %s not connect!' % (host,port)
sys.exit(1)
s.close()
conn(host,port)

目录
相关文章
|
2天前
|
Python
python检查值是否在开放范围内(不包括边界)
【5月更文挑战第11天】python检查值是否在开放范围内(不包括边界)
7 3
|
2天前
|
Python
python检查浮点数是否在范围内
【5月更文挑战第11天】python检查浮点数是否在范围内
8 1
|
2天前
|
Python
python检查整数是否在范围内
【5月更文挑战第11天】python检查整数是否在范围内
7 2
|
4天前
|
Python
Python值范围检查
【5月更文挑战第9天】Python值范围检查
10 1
|
4天前
|
IDE 开发工具 Python
Python类型检查
【5月更文挑战第9天】Python类型检查
10 1
|
4天前
|
测试技术 开发者 Python
Python检查函数和方法的输入/输出
【5月更文挑战第5天】Python检查函数和方法的输入/输出
13 1
|
4天前
|
数据安全/隐私保护 开发者 Python
【Python 基础】检查字符串是否只包含数字和字母?
【5月更文挑战第8天】【Python 基础】检查字符串是否只包含数字和字母?
|
4天前
|
存储 算法 数据处理
Python中检查一个数字是否是科技数的完整指南
Python中检查一个数字是否是科技数的完整指南
22 3
|
4天前
|
监控 Python
Python监控主机是否存活,并发报警邮件
Python监控主机是否存活,并发报警邮件
|
4天前
|
机器学习/深度学习 数据可视化 算法
Python支持向量回归SVR拟合、预测回归数据和可视化准确性检查实例
Python支持向量回归SVR拟合、预测回归数据和可视化准确性检查实例