-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.py
94 lines (77 loc) · 2.66 KB
/
upload.py
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
83
84
85
86
87
88
89
90
91
92
93
import requests
import os
import json
import re
class FileBin:
def __init__(self, file_path):
self.file_path = file_path
self.file_name = os.path.basename(file_path)
self.bin = '09cefunin2hpufcs'
self.file_size = str(os.path.getsize(file_path))
print(f"File size is {self.file_size} bytes")
if not self.check_bin():
self.get_bin()
def check_bin(self):
headers = {
'accept': 'application/json',
}
response = requests.get(f'https://filebin.net/{self.bin}', headers=headers)
return True if response.status_code == 200 else False
def get_bin(self):
response = requests.get("https://filebin.net/")
if response.status_code == 200:
html_content = response.text
# Use a regular expression to find all anchor tags with rel="nofollow"
nofollow_links = re.findall(r'<a[^>]+rel="nofollow"[^>]*href=["\'](.*?)["\']', html_content)[0]
bin = nofollow_links.split("/")[-1]
self.bin = bin
return bin
else:
print('Failed to retrieve content')
return False
def upload(self):
with open(self.file_path, 'rb') as f:
# Set up the headers with the file name
headers = {
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Referer': 'https://filebin.net/',
'bin': self.bin,
'filename': self.file_name,
'Content-Type': 'application/octet-stream',
'Content-Length': self.file_size,
'Origin': 'https://filebin.net',
'Connection': 'keep-alive',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Priority': 'u=1',
}
# Send the POST request with the file in the body and filename in the header
response = requests.post(f'https://filebin.net/{self.bin}/{self.file_name}', headers=headers, data=f)
# Check if the request was successful
if response.status_code == 201:
print('File uploaded successfully')
# Process response if needed
print(json.dumps(response.json(), indent=4))
return self.download()
else:
print('Failed to upload file', response.json(), response)
def download(self):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
'Referer': 'https://filebin.net/',
'Connection': 'keep-alive',
# 'Cookie': 'verified=2024-05-24',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Priority': 'u=1',
}
response = requests.get(f'https://filebin.net/{self.bin}/{self.file_name}', headers=headers)
if response.status_code == 200:
return response.url