python 批量掃描mongodb 未授權訪問指令碼

來源:互聯網
上載者:User

標籤:

需要 pymongo庫
easy_install pymongo
指令碼:

import socketimport sysimport pymongo ipcons = []def Scanner(ip):    global ipcons    sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    sk.settimeout(0.3)     try:        sk.connect((ip,27017))        ipcons.append(ip)        sk.close()    except Exception:        pass def ip2num(ip):    ip=[int(x) for x in ip.split(‘.‘)]    return ip[0] <<24 | ip[1]<<16 | ip[2]<<8 |ip[3]     def num2ip(num):    return ‘%s.%s.%s.%s‘ %( (num & 0xff000000) >>24,                                (num & 0x00ff0000) >>16,                                (num & 0x0000ff00) >>8,                                num & 0x000000ff )     def get_ip(ip):    start,end = [ip2num(x) for x in ip.split(‘ ‘) ]    return [ num2ip(num) for num in range(start,end+1) if num & 0xff ]     startIp = sys.argv[1]endIp = sys.argv[2]iplist = get_ip(sys.argv[1]+" "+sys.argv[2])for i in iplist:    Scanner(i) def connMon(ip_addr):    print ‘ Connect mongodb: ‘ + ip_addr + ‘:27017‘    try:        conn = pymongo.MongoClient(ip_addr,27017,socketTimeoutMS=3000)        dbname = conn.database_names()        print "success"    except Exception as e:        print "error" print ipcons    for ipaddr in ipcons:    connMon(ipaddr)    print "================="

  

python 批量掃描mongodb 未授權訪問指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.