Python判断端口连通性

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket,sys

def MySQL_Connet(MySQL_ip):
    MySQL_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    result = MySQL_sock.connect_ex((MySQL_ip,56000))
    if result == 0:
        print ('DateBase Port is Open')
    else:
        print ("DateBase Port is Not open")
        sys.exit(120)

def Redis_Con(Redis_ip):
    Redis_sk=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    Redis_Result=Redis_sk.connect_ex((Redis_ip,6379))
    if Redis_Result == 0:
        print('Redis Port is Open')
    else:
        print('Redis Port is Not Open')
        sys.exit(121)

if __name__ == '__main__':
    MySQL_Connet('127.0.0.1')
    Redis_Con('127.0.0.1')

  

posted @ 2019-01-04 14:23  阿进,fighting  阅读(3744)  评论(0编辑  收藏  举报