Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

ip - Have the address of the client in python

My request is : I have my web pages created in python (wherein there is html code), each pages has a button to go to the next page. Is it possible to get the address of the client when we submit an html form for example ? I mean, to have into the URL address of the client.

If that possible, I'll show my code, else I delete my question.

that's my html code :

ip = cgi.escape(os.environ["REMOTE_ADDR"])

<html>

path install: ${install_path}<br/><br/>

os: ${os}<br/><br/>

unix user: ${user_name}<br/><br/>

<form name="sd" method="get" action="ip/cgi/scriptGet.py">
    Name: <input type="text" name="name"><br/><br/>
    Pseudo: <input type="text" name="pseudo"/><br/><br/>
    <input type="submit" value="OK"/>
</form>

and here my python code:

import os, sys, platform, getpass, tempfile
import webbrowser
import string
import json
import cgi, cgitb, os   

def main( server_IP,install_path):

  template = open('scriptHmtl.phtml').read()

  contenu = string.Template(template).substitute(
            install_path = install_path,
            os = user_os,
            user_name = user_login
            )

if __name__ == "__main__":
  server_IP = sys.argv[1]
  install_path = sys.argv[2]

main(server_IP,install_path)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use cgi and REMOTE_ADDR and use like this :

cgi.escape(os.environ["REMOTE_ADDR"])

Put that in a variable and call the variable into action of your html form ....


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...