redis-cli.py python redis-cli redis Management terminal

Source: Internet
Author: User

Python redis-cli.py Python3 redis-cli Command-line administration tool

Due to the recent test of redis unauthorized access vulnerability, found that the machine does not have Redis installed, can not run redis-cli, so he wrote a simple redis-cli terminal, the function is not complete, just support simple landing and other operations.

mini redis-cli tools

After my tests, it is still possible to execute a simple command.

The code has been uploaded to GitHub https://github.com/b4zinga/PythonTools/blob/master/redis-cli.py

#!/usr/bin/env Python# Coding:utf-8# date:2018-03-20 13:45:00# Author:b4zinga# Email: [Email protected]# Function:mini REDIS-CLI ToolsImportSocketImportSysImportResocket.setdefaulttimeout (3)defSendCommand (host, port): sock=Socket.socket ()Try: sock.Connect((Host,port))except Exception  asErr:Print(Err) Sys.exit (0) while True: cmd= input(' > ')ifCmd== ' exit ': BreakCmd=Makecmd (CMD)Try: Sock.send (Cmd.encode ()) while True: recv=SOCK.RECV (1024x768)Print(Handlerecv (recv))if Len(recv)<1024x768:# Loop receives 1024, if the length is less than 1024 the default is no content, break                     Break        except Exception  asErr:Print(err) Sock.close ()defMakecmd (cmd): command= "*"Cmd=Cmd.split () command=Command+ Str(Len(CMD))+ '\ r \ n'     forCinchCmd:command=Command+ ' $ ' + Str(Len(c))+ '\ r \ n' +C+ '\ r \ n'    returnCommanddefHANDLERECV (recvdate): recvdate=Recvdate.decode ()ifRecvdate.startswith (' * '): Recvdate=recvdate[2:].strip ('\ r \ n') recvdate=Re.sub (' \$\d+\\R\\N ',"', recvdate)returnRecvdateif __name__ == ' __main__ ': Usage="""====================================================Mini REDIS-CLI tools.Usage:redis-cli.py <IP> <port>Default IP 127.0.0.1Default Port 6379Example:redis-cli.py 127.0.0.1 6379redis-cli.py 127.0.0.1\ nredis-cli.py 192.168.1.133 6378====================================================    """    if '-H ' inchsys.argvor '--help ' inchsys.argvor Len(SYS.ARGV)> 3:Print(usage) Sys.exit (0)if Len(SYS.ARGV)== 1: Sys.argv.append (' 127.0.0.1 ')if Len(SYS.ARGV)== 2: Sys.argv.append (6379) SendCommand (sys.argv[1],int(sys.argv[2]))

redis-cli.py python redis-cli redis Management terminal

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.