python 端口扫描

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

#iptable=[]
nmapport=[21, 22, 23, 80, 110]

def retbanner(ip, port):
    try:
        socket.setdefaulttimeout(2)
        s=socket.socket()
        s.connect((ip, port))
        banner=s.recv(1024)
        return banner
    except Exception, e:
        return "[-] Errors: "+str(e)


def IpTbale():
    for i in range(1, 255):
        for port in nmapport:
            ip="192.168.0.{0}".format(i)
            str="checking {0}:{1}".format(ip, port)
            print str
            retbanner(ip, port)


if __name__ == '__main__':
    IpTbale()

  

posted @ 2016-08-23 21:37  Rocky_Ansi  阅读(648)  评论(0编辑  收藏  举报