17.09.2016 г.

Python scan for open port Tkinter

       

#####IMPORT SOME MODULE'S#####
from Tkinter import *
import socket, sys, time
from datetime import datetime
from threading import *

name = socket.gethostname()
name_pr = socket.gethostbyname(name)
firstclick = True

def on_entry_click(event):
    """function that gets called whenever enter_1 is clicked"""        
    global firstclick

    if firstclick: # if this is the first time they clicked it
        firstclick = False
        enter_2.delete(0, "end") # delete all the text in the entry

#####GET HOST NAME AND PORT#####
class Scan_for_port:#####
    def __init__(self, host, port):
        self.host = host    #HOSTNAME
        self.port = port    #PORTS COLECT

    def rep(self):
        #RETURN LIST WIT INCLUDE HOSTNAME AND PORT OR PORT'S
        return [self.host, self.port]


#####CALLBACK FOR BUTTON IS HERE#####
def callback():
    data1 = enter_1.get()   #GET HOSTNAME
    date2 = enter_2.get()    #GET PORTS
    if len(date2.split(",")) > 1: #IF USER USE COMMA FOR SEPARATE FOR PORTS
        total_info = [str(data1), [int(i) for i in date2.split(",")]]
    elif len(date2.split("-")) > 1: #IF USER USE - FOR SEPARATE FOR PORTS 
        total_info = [str(data1), [int(i) for i in (range(int(date2.split("-")[0]),\
(int(date2.split("-")[-1])+1)))]]
    else:     #IF USER WRITE ONLY ONE PORT
        total_info = [str(data1), [int(date2)]]
 
    total_info_result = Scan_for_port(total_info[0], total_info[1])
    return total_info_result.rep()


#####SOCKET CONFIG IS HERE#####
def scan(host, ports):
    lock_object = Semaphore(value=1)
    t1 = datetime.now()
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((host,ports))
        s.send("Hello\r\n")
        result = s.recv(100)
        lock_object.acquire()
        mylist.insert(END, "[+]{port} is open {result}".format(port=ports,\
        result=str(result)))
        mylist.see(END)
        mylist.update()
    except:
        lock_object.acquire()
    finally:
        lock_object.acquire()
        s.close()
 
def main():
    t1 = datetime.now()
    host, ports = callback()
    for port in ports:
        socket.setdefaulttimeout(1)
        t = Thread(target=scan, args=(host, int(port)))
        t.start()



#####TKINTER CONFIGURATIONS IS HERE#####
root = Tk()
root.title("CHECK OPEN PORT'S")
root.geometry("280x350+100+100")
root.resizable(0,0)   #DISABLE RESIZE FOR WINDOWS!!!
root.config(bg="#000000")

button1 = Button(root,text="RUN", padx=5, pady=5, command=main)
button1.config(bg="#D2691E", fg="#000000")
button1.config(font=('times', 10, 'underline italic'))
button1.config(bd=4, relief=RAISED)
button1.grid(row=1, column=3,rowspan=2, sticky=NE)

label = Label(root, text="Ente host ip ",bg="#000000", fg="#D2691E")
label.config(font='times')
label.grid(row=1,column=1, sticky=NW, padx=2)

enter_1 = Entry(root, bg='white', fg="black")
enter_1.insert(0, name_pr)
enter_1.focus()
enter_1.grid(row=1,column=2, sticky=N)

label2 = Label(root, text="Enter port's ",bg="#000000", fg="#D2691E")
label2.config(font='times')
label2.grid(row=2,column=1, sticky=NW, padx=2)
enter_2 = Entry(root, bg='white', fg="black")
enter_2.insert(0, "use 1,2 or 1-2 for range")
enter_2.bind('', on_entry_click)
enter_2.grid(row=2,column=2, sticky=N)


mylist = Listbox(root,bg="#000000",fg="#D2691E")
mylist.grid(row=3,column=1, columnspan=4 , rowspan=4, ipadx=80, ipady=100)



if __name__ == '__main__':
    root.mainloop()

       
 

12.09.2016 г.

Show image, with options to resize it.

 #IMPORT SOME MODULE NEED pip install pillow  
 #if not esists  
 import os, sys, Tkinter  
 from PIL import Image, ImageTk  
 #FIRST GLOBAL PARAM TO PATH  
 #USES Pictures folder of user that run script  
 PIC = os.path.expanduser('~')+"\Pictures"  
 #CALCULATE RESULT IS HERE  
 list_with_pic = []  
 old_label_image = None  
 #FUNCTION CLOSE PICTURE WHEN PUSH LEFT MOUSE BOTTON  
 def button_click_exit_mainloop (event):  
   """FUNCTION CLOSE PICTURE WHEN PUSH LEFT MOUSE BOTTON"""  
   event.widget.quit() # this will cause mainloop to unblock.  
 #THIS SEARCH FOR PICTURES IN PIC FOLDER  
 #RETURN ABSOLUTE PATH  
 def search_picture(PATH):  
   """THIS SEARCH FOR PICTURES IN PIC FOLDER / RETURN ABSOLUTE PATH"""  
   for root_p, dirname, filename in os.walk(PATH):  
     for file in filename:  
       if file.endswith(("jpg","png")):  
         yield os.path.join(root_p, file)  
 #RETURN RESULT SPARES MEMORY  
 def return_orig():  
   """RETURN RESULT SPARES MEMORY"""  
   for result in search_picture(PIC):  
     yield result  
 #SHOW PICTURES USE TKINTER TO VISUALIZE  
 def show_pic():  
   """SHOW PICTURES USE TKINTER TO VISUALIZE"""  
   len_of_pictures = [] #CALCULATE RESULT  
   for m in return_orig():  
     len_of_pictures.append(m)  
   print ""  
   #PRINT TOTAL LEN OF FOUND PICTURE'S  
   print "The total len of pictures is {}".format(len(len_of_pictures))  
   print ""  
   #ASK TO OPEN PICTURE FOR VIEW OR NOT, TKINTER CLOSE WHEN HIT N/n or somthing else  
   ask = raw_input("Do you want to open all image's : Y or N _\b" )  
   if ask == 'Y' or ask == 'y':  
     root = Tkinter.Tk()  
     root.bind("<Button>", button_click_exit_mainloop)  
     root.geometry('+%d+%d' % (200,200))  
     for root_d, dirname, filename in os.walk(PIC):  
         for file in filename:  
           if file.endswith(("jpg","png")):  
             list_with_pic.append(os.path.join(root_d, file))  
     for result in list_with_pic:  
       #OPEN IMAGE  
       image1 = Image.open(result)  
       #ORIGINAL GEOMETRY IS HERE TAKE FROM IMAGE  
       root.geometry('%dx%d' % (image1.size[0],image1.size[1]))  
       tk_pik = ImageTk.PhotoImage(image1)  
       #LABEL IS HERE SHOW IN TOP OF THE TKINTER CANVAS  
       label_image = Tkinter.Label(root, image=tk_pik)  
       #PLACE TO POSITION  
       label_image.place(x=0,y=0,width=image1.size[0],height=image1.size[1])  
       root.title(result)  
       if old_label_image is not None:  
         old_label_image.destroy()  
       odl_lavel_image = label_image  
       root.mainloop()  
   #IF ASK IS N/n exit from program  
   elif ask == 'N' or ask == 'n':  
     print "Refused by the user"  
     sys.exit()  
   else:  
     sys.exit()  
 #THIS USE TO RESIZE A PICTURE'S  
 def resize_pic():  
   """THIS USE TO RESIZE A PICTURE'S"""  
   if os.path.exists(PIC):  
     TUMBNAILS = "thumbnail"  
     if os.path.exists(PIC+'\\'+TUMBNAILS):  
       TUMBNAILS = PIC+'\\'+TUMBNAILS  
     else:  
       os.makedirs(PIC+'/'+TUMBNAILS)  
       TUMBNAILS = PIC+'\\'+TUMBNAILS  
   #ASK TO USER PUSH WIDTH AND HEIGHT OF THUMBNAIL  
   width = raw_input("Enter width :")  
   height = raw_input("Enter height :")  
   for result in return_orig():  
     image = Image.open(result)  
     image = image.resize((int(width), int(height)), Image.ANTIALIAS)  
     image.save(TUMBNAILS+'\\'+result.split('\\')[-1], 'jpeg', quality=90)  
 def ask_for_what():  
   print "-------------------------------------------"  
   print "1 - For list pictures with original size -"  
   print "2 - Corect pictures to tumbnails     -"  
   print "-------------------------------------------"  
   answer = raw_input('Choice whant you want :')  
   print ""  
   print "You choice {answer}".format(answer=answer)  
   if answer == '1':  
     show_pic()  
   elif answer == '2':  
     resize_pic()  
   else:  
     "???"  
 if __name__ == "__main__":  
   print "Default path is {path}".format(path=PIC)  
   print ""  
   PIC = raw_input("Enter for Default or write absolute path to pictures :")  
   if PIC == "":  
     PIC = os.path.expanduser('~')+"\Pictures"  
   else:  
     PIC = PIC  
   ask_for_what()  

3.09.2016 г.

Show google passwords

# -*- coding: utf-8 -*-
#IMPORT SOME MODULE'S
import sqlite3
import win32crypt
import os
from collections import defaultdict
import pprint

#GLOBAL PARAM'S
GOOGLE_FILE = "Login Data"
GOOGLE_PATH = os.path.expanduser('~')+"\AppData\Local\Google\Chrome\User Data\Default"
STORE_RESULT = defaultdict(list)

#STORE PATH FOR "SEARCH_FOR_FILE" FUNCTION
Files = []

#FILE WHERE DRAW RESULT
OUTPUT_FILE = "RESULT.txt"

#SEARCH FOR GLOBAL PARAM IN PATH
def search_for_file():
  for root, dirname, filename in os.walk(GOOGLE_PATH):
for file in filename:
if GOOGLE_FILE == file:
Files.append(os.path.join(root, file))

def sqlite_connect(Files):
  for found in Files:
c = sqlite3.connect(found)
cursor = c.cursor()
select_statement = "SELECT origin_url, username_value, password_value FROM logins"
result = cursor.execute(select_statement)
main_res = result.fetchall()
for url, name, password in main_res:
username_and_pass = []
pwd = win32crypt.CryptUnprotectData(password, None, None, None, 0)
username_and_pass.append(tuple((name, pwd[1])))
STORE_RESULT[url] = username_and_pass


if __name__ == "__main__":
  search_for_file()
sqlite_connect(Files)
with open(OUTPUT_FILE, 'w') as f:
for i, v in STORE_RESULT.items():
f.write(i)
f.write(str(v).encode("utf-8"))
f.write("\n")
pprint.pprint(dict(STORE_RESULT))