How to get a viewer's IP address with python?

后端 未结 3 1189
抹茶落季
抹茶落季 2020-12-19 21:49

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 thei

3条回答
  •  长情又很酷
    2020-12-19 22:13

    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

提交回复
热议问题