Skip to content

Instantly share code, notes, and snippets.

@FlyTechVideos
Last active January 3, 2024 14:02
Show Gist options
  • Save FlyTechVideos/338304baff39ef01230ef5d72566f33e to your computer and use it in GitHub Desktop.
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]
#!/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")
@PyMaster22
Copy link

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 MineCraft

You know you can't call yourself the biggest fan of someone.

@gh-doot
Copy link

gh-doot commented Jul 30, 2020

image

  • ????????

@Vbbab
Copy link

Vbbab commented Aug 28, 2020

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 MineCraft

For not censoring IP, change this line:

ip = censor_ip(request.headers.get('X-Forwarded-For', request.remote_addr))

to:

ip = request.headers.get('X-Forwarded-For', request.remote_addr)

@InsertX2k
Copy link

InsertX2k commented Feb 16, 2021

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")

@APie357
Copy link

APie357 commented Mar 5, 2021

@AphmauYoutube45
Copy link

Nice

@vtf6259
Copy link

vtf6259 commented Apr 17, 2023

I made a tinyurl for this witch is https://tinyurl.com/Flyemaillog

@vtf6259
Copy link

vtf6259 commented Apr 17, 2023

image

  • ????????

if you do pip install flask and pip install user_agents it should work

@gh-doot
Copy link

gh-doot commented May 15, 2023

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 MineCraft

You 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