Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 8th, 2008, 08:36 PM
Newbie
 
Join Date: Jun 2007
Posts: 15
Default Python CGI grab user IP Address

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

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles