Need Pymongo Library
Easy_install Pymongo
Script:
Import Socketimport sysimport Pymongo ipcons = []def Scanner (IP): global ipcons SK = Socket.socket (socket.af_inet, S Ocket. SOCK_STREAM) Sk.settimeout (0.3) Try:sk.connect ((ip,27017)) ipcons.append (IP) sk.close () ex CEPT 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): s Tart,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 EXC Eption as E:print "error" Print ipcons for ipaddr in Ipcons:connmon (ipaddr) print "================="
Python bulk scan MongoDB unauthorized access script