Just doing a basic forum with a python file allowing the user to login and/or create an account. Thought I would do a little bit more and have each user logged in with their IP address and then be able to post with a unique ID generated from their IP address, like most imageboards.
I can write the code pretty easily, but I am having trouble finding how to get the user's IP address without using Flask.
EDIT: this is the code i just checked, and it seems to be working
#!/usr/bin/python
import md5, cgi,cgitb,codecs
def Maker():
form=cgi.FieldStorage()#for use later
a=form.keys()#for use later
page = 'Content-type: text/html\n\n'
page +='<html><head><title>Test Form</title></head>\n'
from socket import gethostname, gethostbyname
ip = gethostbyname(gethostname())
page+= ip
return page
print Maker()
EDIT: that code isnt working, still looking for help
It sounds like you're running this as a CGI script. The user's IP address will be in the REMOTE_ADDR
environment variable, os.environ["REMOTE_ADDR"]
.
I think this might work
from socket import gethostname, gethostbyname
ip = gethostbyname(gethostname())
or If you are using CGI you can get it from the REMOTE_ADDR
environmental
variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With