Have the address of the client in python

2024/9/20 15:28:05

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)
Answer

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 ....

https://en.xdnf.cn/q/119310.html

Related Q&A

try/except issue in Python

I ran the following code as a practice purpose from one of the Python book and I want the output as shown in the URL provided below. So, when I am running the first activity in the question (from book …

Counting the number of vowels in a string using for loops in Python

Python Code:sentence = input(Enter a string:) vowel = A,a,E,e,I,i,O,o,U,u Count = 0 for vowel in sentence:Count += 1 print(There are {} vowels in the string: \{}\.format(Count,sentence))I am trying to …

Sum the values of specific rows if the rows have same values in specific column

I have a data frame like this:a b c 12456 11 123.1 12678 19 345.67 13278 19 1235.345or in another format <table><tr><td>12456</td><td>11</td><td>1…

Plotting Interpolated 3D Data As A 2D Image using Matplotlib

The data set is made of a list dfList containing pandas DataFrames, each DataFrame consisting of the column Y and an identical index column. I am trying to plot all the DataFrames as a 2D plot with pix…

Plotting a flow duration curve for a range of several timeseries in Python

Flow duration curves are a common way in hydrology (and other fields) to visualize timeseries. They allow an easy assessment of the high and low values in a timeseries and how often certain values are …

HTML variable value is not changing in Flask

I have written this code in Flaskans = 999 @app.route(/, methods=[POST, GET]) def home():flag = 0global anssession["ans"] = 0if (request.method == "POST"):jsdata = request.form[data…

How to add two lists with the same amount of indexs in python

I am still new to coding so i apologize for the basic question. How do I add to elements of two seperate lists? listOne = [0, 1 , 7, 8] listTwo = [3, 4, 5, 6] listThree = []for i in listOne:listAdd = …

How to crawl thousands of pages using scrapy?

Im looking at crawling thousands of pages and need a solution. Every site has its own html code - they are all unique sites. No clean datafeed or API is available. Im hoping to load the captured data i…

Object Transmission in Python using Pickle [duplicate]

This question already has answers here:Send and receive objects through sockets in Python(3 answers)Closed last year.I have the following class, a Point objectclass Point:def __init__(self):passdef __i…

Google App Engine: Modifying 1000 entities

I have about 1000 user account entities like this:class UserAccount(ndb.Model):email = ndb.StringProperty()Some of these email values contain uppercase letters like [email protected]. I want to select …