def Display(self, title, Type, dbquery, group='None'): # Display all info id = 0 print head for n in self.summary: print "\033[35;1m%s\033[0m =>" % n, print print print '\033[32;1m id %s\033[0m' % title print data = map(str, dbquery) num = DBQuery().ReturnIPNum() #print 'data : ', data #print 'num : ', num IpList = DBQuery().DisHostIp(group) for i in data: id += 1 if title == 'group': # Show the IP number print '\033[32;1m %s. %s \033[36;1m[%s]\033[0m \033[0m' % (id , i, num[id - 1]) elif title == 'ip': # display hostname and ip try: print '\033[32;1m %s. %s \033[36;1m[%s]\033[0m \033[0m' % (id , IpList[id - 1]['hostname'], IpList[id - 1]['ip']) except IndexError: pass else: print '\033[32;1m %s. %s \033[0m' % (id , i) Type[id] = str(i) print tail
def FastLogin(self): data = map(str, DBQuery().AuthIP()) ip_user = [v.replace('\t', ' ') for v in data] # raw_input tab def complete(text, state): for i in ip_user: if i.startswith(text): if not state: return i else: state -= 1 readline.parse_and_bind("tab: complete") readline.set_completer(complete) while True: ip_user = raw_input('Please input ip and user > ').strip().split() if 'q' in ip_user: self.Main() elif len(ip_user) == 2: remote_ip, remote_user = ip_user[0], ip_user[1] self.Connection(remote_ip, remote_user) break else: continue
def Display(self, title, type, dbquery): # Display all info id = 0 print head for n in self.summary: print "\033[35;1m%s\033[0m =>" % n, print print print '\033[32;1m id %s\033[0m' % title print data = map(str, dbquery) num = DBQuery().ReturnIPNum() print 'data : ', data print 'num : ', num for i in data: print i, '...............' location = data.index(i) number = num[location] id = id + 1 if title == 'group': print '\033[32;1m %s. %s \033[36;1m[%s]\033[0m \033[0m' % ( id, i, number) else: print '\033[32;1m %s. %s \033[0m' % (id, i) type[id] = str(i) print tail
def Main(self): # Display all groups. self.summary = [] self.Display('group', self.GroupList, DBQuery().DisGroup()) # Query the database, display menu self.InputKey( self.GroupList, self.ChooseRemoteIP ) # Determine the user to enter the keywords, (self.GroupList is type | self.ChooseRemoteIP is next page function)
def Connection(self, remote_ip, remote_user): try: socket.inet_aton(remote_ip) valid_ip = 'ok' conn = DBQuery().Summary(remote_ip, remote_user, username) print conn os.system(conn) self.Main() except: valid_ip = 'no' print '\033[31;1mPlease enter a valid IP\033[0m'
def Connection(self, remote_ip, remote_user): try: valid_ip = 'ok' socket.inet_aton(remote_ip) conn = DBQuery().Summary(remote_ip, remote_user, username) #print conn os.system(conn) except: valid_ip = 'no' print '\033[31;1mInput is not a valid address or address does not exist\033[0m' print 'valid_ip', valid_ip,'------------'
def Search(self): # search keyword. Type(self.GroupList, self.IPList , self.UserList) search(user search input key) data = DBQuery().DisHostIp('all') remote_list = {} while True: search = raw_input('Please input the key words [ q ] > ').strip() if search == 'q': self.Main() elif len(search) == 0: continue else: break key = 0 print head print '\033[35;1m id search result\033[0m' print for i in data: if search in i['hostname'].lower() or search in i['ip'].lower(): key += 1 print '\033[32;1m %s. %s \033[36;1m[%s]\033[0m \033[0m' % ( key, i['hostname'], i['ip']) remote_list[key] = i['ip'] else: pass if key == 0: print '\033[31;1m %s Not found\033[0m' % search self.Search() print tail while True: try: choose = raw_input('Please input id [ q | p ] > ').strip() if choose == 'q': self.Main() if choose == 'p': self.Search() elif len(choose) == 0: continue elif int(choose) in remote_list.keys(): #print remote_list[int(choose)],'==========' self.summary.append(remote_list[int(choose)]) self.ChooseRemoteUser(remote_list[int(choose)]) else: print '\033[31;1m Please input a valid id number\033[0m' continue except ValueError: print '\033[31;1m Please input id number \033[0m'
def ChooseRemoteIP(self, group): # The IP under the display group. self.summary = [] self.Display('ip', self.IPList, DBQuery().DisIP(group), group) self.InputKey(self.IPList, self.ChooseRemoteUser)
def ChooseRemoteUser(self, ip): # Show the IP of users self.Display('user', self.UserList, DBQuery().DisRemotUser(ip)) self.InputKey(self.UserList, self.Summary)