• 用Python写的一个简单的端口扫描程序


    python做这个事情很轻松,如果省去不必要的参数输入部分,代码可以更简单  :-)

    直接上代码吧:

    #-------------------------------------------------------------------------------
    #
     Name:        PortScan
    #
     Purpose:     扫描目标主机的端口开放情况
    #
    #
     Author:      xxh
    #
    #
     Created:     05-12-2011
    #
     Copyright:   (c) xxh 2011
    #
     Licence:     <your licence>
    #
    -------------------------------------------------------------------------------
    #
    !/usr/bin/env python

    import socket

    def main():
        sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sk.settimeout(1000)
        ip=input('请输入目标主机:(默认:127.0.0.1)')
        if ip=='':
            ip='127.0.0.1'



        s=input('请输入目标主机开始端口:(默认:80)')
        if s=='':
            startport=80
        else:
            startport=int(s)

        s=input('请输入目标主机结束端口:(默认:80)')
        if s=='':
            endport=80
        else:
            endport=int(s)

        for port in range(startport,endport+1):
            print('正在扫描端口:%d' % port)
            try:
                sk.connect((ip,port))
                print('Server %s port %d OK!' % (ip,port))
            except Exception:
                print('Server %s port %d is not connected!' % (ip,port))
        sk.close()


    if __name__ == '__main__':
        main()
  • 相关阅读:
    "alert(1) to win" writeup
    "CoolShell puzzle game" writeup
    Maximum Subarray(最大连续子序列和)
    hacking 学习站
    爬虫:备份人人网状态
    ichunqiu在线挑战--网站综合渗透实验 writeup
    ichunqiu在线挑战--我很简单,请不要欺负我 writeup
    IDF-CTF-简单的js加密 writeup
    IDF-CTF-cookie欺骗 writeup
    IDF-CTF-不难不易的js加密 writeup
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/2276885.html
Copyright © 2020-2023  润新知