#1 CMD 명령어 실행 import os os.system("명령어") CMD창에서 명령어를 입력한것과 같게 작동합니다. 실행 위치는 파이썬 프로그램의 실행위치와 같습니다. #2 CMD 명령어 실행과 결과 얻기 import subprocess result = subprocess.getstatusoutput("명령어") CMD창에서 명령어를 입력한것과 같게 작동합니다. 실행 위치는 파이썬 프로그램의 실행위치와 같습니다. 실행 결과는 result 변수에 저장됩니다.
코딩/Python
import base64 base64.decode(open("원본 파일 경로"), open("디코드된 결과물이 나올 경로")) base64.encode(open("원본 파일 경로"), open("인코드된 결과물이 나올 경로")) base64로 디코드, 인코드 할 수 있습니다.
import getpass user_name = getpass.getuser() print(user_name) 현재 로그인되어있는 windows 사용자의 이름을 가져옵니다.
import ctypes lib = ctypes.windll.LoadLibrary('user32.dll') handle = lib.GetForegroundWindow() buffer = ctypes.create_unicode_buffer(255) lib.GetWindowTextW(handle, buffer, ctypes.sizeof(buffer)) active = buffer.value print(active) active 변수가 활성화된 창의 제목입니다.
import turtle as t import time # x, y축 그리기 t.pendown() t.goto(0, 1000) t.goto(0,0) t.goto(1000,0) t.penup() # 준비 x, y = 1, 1 x += 1 y = 400 // x t.goto(x, y) t.pendown() # 그래프 그리기 for i in range(600): t.goto(x, y) x += 1 y = 2000 // x print(x, y)
1. 클라이언트의 IP주소 # IP 가져오기 request.environ.get('HTTP_X_REAL_IP', request.remote_addr) 2. 클라이언트가 요청한 전체 url # 요청한 url request.full_path 3. 클라이언트가 요청한 method # http 메소드(GET 또는 POST) request.method 4. POST요청 처리 form 태그 안에 있는 입력 태그중 name이 title인 태그의 값을 가져옴 request.form.get('title') 5. GET요청 처리 # http://example.com/?name=값 에서 값을 가져옴 request.args.get("name") 6. 대략적인 정보 # str(request) 댓글 오류지적 환영합니다.
from tkinter import Tk, Label # 창 생성 window = Tk() # 레이블 생성 label = Label(window, text="hello world!") # 레이블을 창에 배치 label.pack() # 텍스트 속성을 변경 (= configure) label.config(text="changed!") # 메인루프 window.mainloop() 더보기 파이썬 tkinter label 텍스트 글자 문장 넣기 윈도우 gui
# import from PIL import ImageGrab # 캡쳐 screen = ImageGrab.grab() # 캡쳐된 사진의 point좌표의 색상값을 가져옴 color = screen.getpixel(point) """ point : (x,y) color : (r,g,b) """ 더보기 파이썬 화면 픽셀 색깔 색상 rgb
Python - pyautogui - Mouse 01. import import pyautogui 02. 문장 입력 pyautogui.write("abcd") abcd를 입력합니다. 한글은 안되는데, 키보드 자체의 언어가 한글로 되어있다면 가능합니다 예시) pyautogui.write("dkssudgktpdy") => 안녕하세요 03. hotkey pyautogui.hotkey("enter") 키 목록 더보기 KEY_NAMES = [ "\t", "\n", "\r", " ", "!", '"', "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ..
HOST = '0.0.0.0' PORT = 5000 BUFSIZE = 8192 ADDR = (HOST, PORT) serverSocket = socket(AF_INET, SOCK_STREAM) serverSocket.bind(ADDR) # 클라이언트에게 데이터 받기 data = clientSocekt.recv(65535) print(data.decode()) # 받은 내용 출력 # 잘 받았다는 의미로 받은 데이터를 다시 보내줌 clientSocekt.send(data) # 연결 끊기 clientSocekt.close() serverSocket.close() 5000번 포트로 외부접속을 위한 소켓서버를 생성합니다. 데이터를 받은 후 그대로 다시 보내줍니다. 클라이언트의 코드 2021/02/05 - [Sni..