mpaste/mpaste.py

58 lines
1.5 KiB
Python
Raw Normal View History

import requests
import json
import socket
def publish_to_mozilla(content):
url = 'https://pastebin.mozilla.org/api/'
data = {
'content': content,
'expires': '86400', # 24 hours
'format': 'text',
'lexer': '_text'
}
response = requests.post(url, data=data)
if response.status_code == 200:
return f"https://pastebin.mozilla.org/{response.text}"
return None
def publish_to_termbin(content):
host = 'termbin.com'
port = 9999
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
sock.sendall(content.encode('utf-8'))
response = sock.recv(1024).decode('utf-8').strip()
sock.close()
return response
except Exception as e:
print(f"Error connecting to Termbin: {e}")
return None
def publish_to_multiple_pastebins(file_path):
# Read the file content
with open(file_path, 'r') as file:
file_content = file.read()
results = {}
# Publish to Mozilla Pastebin
mozilla_url = publish_to_mozilla(file_content)
if mozilla_url:
results['Mozilla Pastebin'] = mozilla_url
# Publish to Termbin
termbin_url = publish_to_termbin(file_content)
if termbin_url:
results['Termbin'] = termbin_url
return results
# Example usage
file_path = 'test.txt'
results = publish_to_multiple_pastebins(file_path)
for service, url in results.items():
print(f"{service}: {url}")