473,508 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python CGI grab user IP Address

15 New Member
Hi guys.
Im having a little trouble with one of my phyon cgi scripts.

Basically i need to a function that runs on the server size as a python cgi script but returns the IP address of the web based user on the website. I then use the IP as an ideantifier for some other processes and data logging.

The script i have is:

def getIP():
"""Get host IP address"""
IP = socket.gethostbyname(socket.gethostname())
x = 0
outstr = ''
while (x < len(IP)):
if (IP[x] != '.'):
outstr = outstr + IP[x]
x += 1

return (str(outstr))

The while loop is just to get rid of the '.' in the string as i dont need them.

The problem is that while socket.gethostbyname(socket.gethostname()) returns the correct result when run locally on my machines it simply returns the IP address of my web host server when i run it on the host side.

Any ideas how to return the IP address of the user to the host so i can use it.
Ive seen services such as http://www.showmyip.com/ but i am wary of using these as the project is for my thesis.

I have also seen code that uses cgi.os.environ['REMOTE_ADDR']
but this gives me errors when i try to return it.

Cheers.
Ed
Sep 8 '08 #1
0 2281

Sign in to post your reply or Sign up for a free account.

Similar topics

33
2692
by: Quest Master | last post by:
I am interested in developing an application where the user has an ample amount of power to customize the application to their needs, and I feel this would best be accomplished if a scripting...
12
13286
by: Larry R. Baker | last post by:
Is it possible to grab a client side IP Address using JavaScript in an htm page? I have a web page hosted on a non-ASP server and I want a piece of code in JavaScript to grab the IP address of the...
8
3016
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
2
9625
by: K.H. | last post by:
Hi Does anyone know how I can grab a video stream from an IP-address? There's a video web server for live image transmission in the Internet. Data transfer is accomplished via TCP/IP. The web cam...
267
10508
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
852
27941
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
0
1910
by: David | last post by:
On Sun, May 4, 2008 at 5:28 PM, Valerio Valerio <vdv100@gmail.comwrote: I assume what you want to do is allow the user to drag the mouse across your desktop, and your program, running in the...
3
4223
by: Phillip B Oldham | last post by:
Hi. I'm stretching my boundaries in programming with a little python shell-script which is going to loop through a list of domain names, grab the whois record, parse it, and put the results into a...
0
7133
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...
0
7336
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
7405
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...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4724
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...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
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 ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.