473,549 Members | 3,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2954
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.uiu c.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********@jim dabell.com> wrote in message news:<pg******* *************@g iganews.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
1685
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 problem i have is that if they have blocked pop-ups then that window won't show up and the order will get confirmed without approval. Is there a...
3
1253
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 address 0001 : xxxx memory address 0002 : xxxx
6
1163
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, http://test.user.com/abcd.asp?username=xyz&password=abcd); That is working fine but the problem is
6
1258
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 pulling in data from a sql table. For some reason, when I include the following line: <tr><td><b><%if rs("Street_dir")<> "" then response.write...
2
3312
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” is simply a ticket-number. I’ve made a form in which I am to choose an existing Ticket and write a description for it pluss other things. The...
1
2341
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 shows. However when no matching records are there, the subform does not show. I want it to always show. If I switch to design view, and then back to...
3
3356
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 winform it is slow around 7 seconds and after that it takes no time. Is there a way to speed up the process to show the winform the first time? ...
6
7960
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 "include not found", rather much of the page is blank where the included menus, etc would be, and the CSS is not attached. thanks so much!!! ...
1
2312
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 txtEmailAddress control is not null and contains an address. Some rows shown in the detail section of the form will have email addresses, some will not. If a...
0
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.