473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Showing IP address of a user...

Hello,

I was wondering how I can show an IP address of a person who visits a
Python web-page? Would I have to use Environment variables to access
Apache's server variables which hold such values like in PHP or what?
Jul 18 '05 #1
6 2949
Fazer wrote:
I was wondering how I can show an IP address of a person who visits a
Python web-page? Would I have to use Environment variables to access
Apache's server variables which hold such values like in PHP or what?


This is defined by the Common Gateway Interface, so it should be the
same across all HTTP servers. It's certainly going to work the same way
across all languages on the same HTTP server.

os.environ is your friend:

import os
print 'Content-Type: text/plain'
print
print os.environ['REMOTE_ADDR']

(<URL:http://hoohoo.ncsa.uiuc.edu/cgi/> has the specification of all the
environment variables, in case you need more.)

M

Jul 18 '05 #2
Jeremy Yallop wrote:
os.environ['REMOTE_ADDR']


Ofcourse, this is only available when you're in a CGI-like
environment. When running inside mod_python, or something
else, I doubt that this environment variable is available.
In those cases, there is usually a specific way of obtaining
the client's address, either directly or via the socket
that represents the network connection. But this depends
on what you're running!
--Irmen

Jul 18 '05 #3
Fazer wrote:
Hello,

I was wondering how I can show an IP address of a person who visits a
Python web-page? Would I have to use Environment variables to access
Apache's server variables which hold such values like in PHP or what?


Use this little CGI script to find the answer to your question:

#!/usr/bin/env python
import cgi
cgi.test()

-- Gerhard

Jul 18 '05 #4
Thank you Marnanel and everyone who replied. This gives me a better understanding.
Jul 18 '05 #5
Fazer wrote:
I was wondering how I can show an IP address of a person who visits a
Python web-page? Would I have to use Environment variables to access
Apache's server variables which hold such values like in PHP or what?


I see you've already been given answers to this, however bear in mind that
what you are determining is the IP address of the client, not the IP
address of the person visiting the page. In many cases, the two are not
the same, such as when the visitor is using a proxy.

There's no reliable way of getting the IP address of the person, but you can
make things a little more reliable by examining the X_FORWARDED_FOR header
as well, since many proxies add this header to their requests (also bear in
mind that they may be private addresses, such as 10.0.0.1).

--
Jim Dabell

Jul 18 '05 #6
Jim Dabell <ji********@jimdabell.com> wrote in message news:<pg********************@giganews.com>...
Fazer wrote:
I was wondering how I can show an IP address of a person who visits a
Python web-page? Would I have to use Environment variables to access
Apache's server variables which hold such values like in PHP or what?


I see you've already been given answers to this, however bear in mind that
what you are determining is the IP address of the client, not the IP
address of the person visiting the page. In many cases, the two are not
the same, such as when the visitor is using a proxy.

There's no reliable way of getting the IP address of the person, but you can
make things a little more reliable by examining the X_FORWARDED_FOR header
as well, since many proxies add this header to their requests (also bear in
mind that they may be private addresses, such as 10.0.0.1).


Oh, thanks for the reference Jim! I will keep that in mind.
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: kiki | last post by:
Hello, I know this is a silly question! I have written some code that requires a pop-up window to come up for the user to confirm that he/she does want to purchase the goods they've ordered. The...
3
by: Darksun4 | last post by:
Hi all, I am making an emulator and I want to show all its memory contents. But i don't want to say : memory address 1 : xxxx memory address 2 : xxxx but something like that : memory...
6
by: Pankaj Jain | last post by:
HI All I have a problem in Opening a Web page URL from window form.I am using the following code System.Diagnostics.Process.Start( stdBrowser,...
6
by: Joey Martin | last post by:
I posted a message earlier, but I have more information to go from so I wanted to start a new post since the first is not really valid. I am using SQL 2000 database and MS Server 2003. I am...
2
by: Timbo | last post by:
Hi there, I’m not used to working in VB and I think this situation calls for excactly that. I use Access 97 SR-2. My first table is a table containing all the Tickets I got. The field ”Ticket”...
1
by: andrewbda | last post by:
I am having issues with showing a subform. Basically it is an address form, which is linked to a customer number on the main form. If there is an existing address record, the form always...
3
by: Torben Laursen | last post by:
I have a COM shared add-in written in C# that I use in Excel. One of the thinks that the user can do is to open some winforms. The problem that I have is that the first time the user opens a...
6
by: MaiyaHolliday | last post by:
Hello, I've recently installed apache on a new computer, and cannot figure out why my site will not process any includes. (it was working on my old one) There are no errors on the page such as...
1
by: RLN | last post by:
I have a form that is set to "continuous forms" view. Several rows of data are shown to the user at the same time. I want to set FieldX and FieldY to true and show them only if the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.