Python-通过socket实现一个小型的端口检测工具

实验机器IP:192.168.220.139,端口开放情况

代码

# -*- coding:utf-8 -*-
__author__ = "MuT6 Sch01aR"

import socket

def PortScan(ip, port):
    try:
        connSkt = socket.socket()
        connSkt.connect((ip,port))
        print('[+]%d open'%port)
        connSkt.close()
    except:
        print('[-]%d close' %port)

PortScan('192.168.220.139',7909)

运行结果

 

posted @ 2018-02-18 19:26  Sch01aR#  阅读(332)  评论(0编辑  收藏  举报