-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPytermbin.py
More file actions
82 lines (72 loc) · 1.93 KB
/
Pytermbin.py
File metadata and controls
82 lines (72 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import socket
import subprocess
import tempfile
import os
HOST = "termbin.com"
PORT = 9999
banner = r"""
____ _______ _ _
| _ \ _ _|__ __|__ _ __ _ __ ___ | |__ (_)_ __
| |_) | | | | | |/ _ \ '__| '_ ` _ \| '_ \| | '_ \
| __/| |_| | | | __/ | | | | | | || |_) | | | | |
|_| \__, | |_|\___|_| |_| |_| |_||_.__/|_|_| |_|
|___/
PyTermbin
"""
def send_to_termbin(text):
s = socket.socket()
s.connect((HOST, PORT))
s.sendall(text.encode())
s.shutdown(socket.SHUT_WR)
url = s.recv(1024).decode().strip()
s.close()
return url
def paste_text():
print("\nPaste your text. Press CTRL+D when finished:\n")
import sys
data = sys.stdin.read()
return send_to_termbin(data)
def upload_file():
path = input("\nPath to .txt file: ").strip()
if not os.path.exists(path):
print("File not found.")
return None
with open(path, "r") as f:
data = f.read()
return send_to_termbin(data)
def capture_terminal():
print("\nStarting terminal capture session.")
print("Type 'exit' when finished.\n")
tmp = tempfile.NamedTemporaryFile(delete=False)
logfile = tmp.name
tmp.close()
subprocess.run(["script", "-q", logfile])
with open(logfile) as f:
data = f.read()
os.remove(logfile)
return send_to_termbin(data)
def menu():
print(banner)
print("1. Paste text")
print("2. Paste txt file")
print("3. Paste entire terminal")
print("4. Exit")
choice = input("\nSelect option: ")
if choice == "1":
url = paste_text()
elif choice == "2":
url = upload_file()
elif choice == "3":
url = capture_terminal()
elif choice == "4":
return
else:
print("Invalid option.")
return
if url:
print("\nTermbin URL:")
print(url)
print()
if __name__ == "__main__":
menu()