gpt4 book ai didi

python - 使用 web.py 如何在某人访问我的页面时获取他们的 IP

转载 作者:太空宇宙 更新时间:2023-11-03 17:36:42 25 4
gpt4 key购买 nike

我找到了this question这似乎就是我正在寻找的。

它说使用web.ctx['ip']

但我无法让它正常工作,我想要的只是变量中访问者的 IP。到目前为止我一直在尝试这个:

import web

urls = (
'/', 'index'
)

class index:
def GET(self):
return "Hello, world!"
return web.ctx['ip'] #Trying to get it to just *show* so
#I can put it into a variable

print web.ctx['ip'] #Nothing happens here either

if __name__ == "__main__":
app = web.application(urls, globals())
app.run()

提前致谢,我想我已经很接近了,我只需要一点帮助。也许我需要导入其他东西?

最佳答案

您在获得IP地址之前就返回了,只需按以下方式重新排序您的代码并删除return“Hello, world!”:

class index:
def GET(self):
print web.ctx['ip']
return web.ctx['ip']

关于python - 使用 web.py 如何在某人访问我的页面时获取他们的 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31126384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com