Last active
January 3, 2024 14:02
-
-
Save FlyTechVideos/338304baff39ef01230ef5d72566f33e to your computer and use it in GitHub Desktop.
Simple web server which logs accesses and data [https://www.youtube.com/watch?v=TB3OEG0bKwc]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from flask import Flask, request, send_from_directory | |
from datetime import datetime | |
from user_agents import parse | |
app = Flask(__name__) | |
def censor_ip(ip): | |
if ":" in ip: # IPv6 doesn't have . so we have to check this here | |
return ip.split(":")[0] + ":[...]" | |
else: | |
return ip.split(".")[0] + ".xxx.xxx.xxx" | |
def log_open_email(): | |
email = request.args.get("e") | |
subject = request.args.get("s") | |
ua = parse(request.headers.get("User-Agent")) | |
ip = censor_ip(request.headers.get('X-Forwarded-For', request.remote_addr)) | |
browser = f"{ua.browser.family} {ua.browser.version_string}" | |
os = f"{ua.os.family} {ua.os.version_string}" | |
print(f"{datetime.now()}: '{subject}' opened by {email}, on {browser} on {os} ({ip})") | |
@app.route("/<name>") | |
def get_file(name): | |
log_open_email() | |
return send_from_directory(".", name) | |
@app.after_request | |
def add_header(response): | |
# Prevent caching so the picture always gets reloaded by clients | |
response.cache_control.max_age = 0 | |
return response | |
if __name__ == "__main__": | |
# The request log is annoying so I'm turning it off | |
import logging | |
logging.getLogger("werkzeug").disabled = True | |
app.run(host="0.0.0.0") |
If you really want to uncensor the ip address, use the following code instead of using the original code :
from flask import Flask, request, send_from_directory
from datetime import datetime
from user_agents import parse
app = Flask(__name__)
def log_open_email():
email = request.args.get("e")
subject = request.args.get("s")
ua = parse(request.headers.get("User-Agent"))
ip = request.headers.get('X-Forwarded-For', request.remote_addr)
browser = f"{ua.browser.family} {ua.browser.version_string}"
os = f"{ua.os.family} {ua.os.version_string}"
print(f"{datetime.now()}: '{subject}' opened by {email}, on {browser} on {os} ({ip})")
@app.route("/<name>")
def get_file(name):
log_open_email()
return send_from_directory(".", name)
@app.after_request
def add_header(response):
# Prevent caching so the picture always gets reloaded by clients
response.cache_control.max_age = 0
return response
if __name__ == "__main__":
# The request log is annoying so I'm turning it off
import logging
logging.getLogger("werkzeug").disabled = True
app.run(host="0.0.0.0")
Nice
I made a tinyurl for this witch is https://tinyurl.com/Flyemaillog
Hey FlyTech
I am your biggest fan
I wanted to ask:
Can you please make a file without IP censorship
I want to check on VPN's and proxies
Thank You
P.S: Is there a way to tunnel on ngrok to only one link everytime we use it without paying
Even if its not on the link we want
But on one certain link always like 07339ed98.ngrok.io
I am making a web chat server in which I need to use it
(and also for tunnelling tcp protocols for MineCraftYou know you can't call yourself the biggest fan of someone.
fact
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For not censoring IP, change this line:
to: