Skip to content

Instantly share code, notes, and snippets.

@piyush01123
Last active November 18, 2022 10:26
Show Gist options
  • Save piyush01123/6eb812595e1fd14e35e7805d5d54c3db to your computer and use it in GitHub Desktop.
Save piyush01123/6eb812595e1fd14e35e7805d5d54c3db to your computer and use it in GitHub Desktop.
Simple flask app to track visitors. Can also be used to test if your proxy server or vpn is running properly.
from flask import Flask, request
from datetime import datetime
import json,os
app = Flask(__name__)
@app.route('/', methods=["GET","POST"])
def index():
if request.method=="POST":
ip_data = request.get_json()
print(ip_data)
if os.path.isfile("visitors.json"):
cur = json.load(open("visitors.json",'r'))
else:
cur = []
cur.append({"datetime": datetime.now().ctime(), "ip_data": ip_data})
fh = open("visitors.json",'w')
json.dump(cur,fh,indent=4)
return "ok"
return """
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
$( document ).ready(function() {
console.log( "ready!" );
let apiKey = '2b7ec0f66e5a4653b7a533fad70243e9';
$.getJSON('https://ipgeolocation.abstractapi.com/v1/?api_key=' + apiKey, function(data) {
// $.post("/ip", data, function(d,st){alert("POSTED "+d);});
console.log(data);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/",
data: JSON.stringify(data),
success: function (d) {
console.log("POSTED "+d);
},
// dataType: "json"
});
});
});
</script>
<p> Hello Word </p>
"""
app.run('0.0.0.0',8000,debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment