#!/usr/bin/env python
#coding:utf-8
import os,sys,socket
if len(sys.argv) != 3 :
print './tcpporttest.py IP PORT'
sys.exit()
HOST = sys.argv[1]
PORT = sys.argv[2]
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ADDR = (str(HOST),int(PORT))
for i in range(1,10):
status = s.connect_ex(ADDR)
os.system('sleep 1')
if status != 0:
print 'Connection to %s %s port [tcp] failure' % (HOST,PORT)
else:
print 'Connection to %s %s port [tcp] succeeded!' % (HOST,PORT)
break
Python 测试端口是否可以联通
测试连接9次,连接成功则立即退出!
阅读(3610) | 评论(0) | 转发(0) |