美文网首页
python对C段的端口扫描

python对C段的端口扫描

作者: CSeroad | 来源:发表于2018-07-28 17:40 被阅读221次

    再接再厉,继续实现端口的扫描。只需要在上次的代码上做一些修改即可。这次写个对C段的扫描的脚本。

    #coding=utf-8

    #python2.7

    import socket

    import threading

    import time

    ip=raw_input(unicode("请输入IP地址:","utf-8").encode("gbk"))

    socket.setdefaulttimeout(1)

    lock = threading.Lock()

    def scan(ip,port):

    try:

    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

    s.connect((ip,port))

    lock.acquire()

    print('[+] %s %d open' % (ip,port))

    lock.release()

    s.close()

    except:

    pass

    def portscan():

    ports=[22,80,443,445,1524,3306]

    threads=[]

    for p in range(len(ports)):

    p=ports[p]

    t=threading.Thread(target=scan, args=(ip,p))

    threads.append(t)

    t.start()

    for t in threads:

    t.join()

    if __name__=='__main__':

    for x in range(0,255):

    i=ip.rfind('.')

    ip=ip[:i+1]+str(x+1)

    #print(u'开始扫描%s>>>>>>'% ip)

    #t1=time.time()

    portscan()

    #print(u'扫描端口完成用时 time:%f' % (time.time()-t1))

    再看一下格式。

    c_port.py

    看一下效果图。

    success

    相关文章

      网友评论

          本文标题:python对C段的端口扫描

          本文链接:https://www.haomeiwen.com/subject/gjnomftx.html