文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PortScan

PortScan

时间:2009-07-24  来源:leogeng1

老大给分配的第一个小项目,用python写一个扫描端口!   #!/usr/bin/env python # Package definitions.
__program__   = 'PortScan'
__version__   = '0.1a'
__date__      = '2009/24/07'
__author__    = 'leogeng'
__licence__   = 'GPL'
__copyright__ = 'Copyright (C) 2009 Lars Strand'
import socket
import sys
from time import time,ctime
from socket import *
host = sys.argv[1]
start = int(sys.argv[2])
end   = int(sys.argv[3])
 
def scan_tcp(host, start_port, end_port):
    for port in range(start_port, end_port + 1):
        try:
            s = socket(AF_INET, SOCK_STREAM)
        except:
            print "socket error"
            sys.exit(1)
        s.settimeout(0.1)
        try:
            s.connect((host, port))
        except:
            pass
        else:
            s.close()
            #serv = socket.getservbyport(port)
            #print str(port) + "\t" + serv
            print str(port) + ' tcp port is open'
           
def scan_udp(host, start_port, end_port):
     for port in range(start_port, end_port + 1):
         try:
            s = socket(AF_INET, SOCK_DGRAM)
         except:
            print "socket error"
            sys.exit(1)  
         s.settimeout(0.1)
         try:
             s.sendto("",(host,port))
             s.recvfrom(10)
         except timeout:
             #serv = socket.getservbyport(port)
             #print str(port) + "\t" + serv
             print str(port) + ' udp port is open'
         except error:
             continue
         finally:
             s.close()
       
def main():
    print "Start at " + ctime(time())
    scan_tcp(host, start, end)
    scan_udp(host, start, end)
    print 'Stop at ' + ctime(time())
 
if __name__ == '__main__':
    main()
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载