The Artima Developer Community
Sponsored Link

Python Answers Forum
Getting IP Address

1 reply on 1 page. Most recent reply: Oct 27, 2005 2:27 PM by Storm To

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Getting IP Address Posted: Jun 8, 2005 1:15 AM
Reply to this message Reply
Advertisement
My problem is as follows:
I'm trying to set up a set of python programs over a network of computers, which will communicate through UDP sockets (I chose UDP because QoS is not a priority, and I wish to limit the overhead). Now, I want the programs to determine their own IP address (the address of the machine they're running on), instead of filling it in myself.

However, when I do this:

ip = socket.gethostbyname( socket.gethostname() )

the variable ip is filled with 127.0.0.1 (localhost). Is there another way to get the IP address of the machine, the way it is used in the network? Thanks in advance.


Storm To

Posts: 5
Nickname: storm
Registered: Oct, 2005

Re: Getting IP Address Posted: Oct 27, 2005 2:27 PM
Reply to this message Reply
Try this

socket.getaddrinfo(socket.gethostname(), None)[0][4][0]

Flat View: This topic has 1 reply on 1 page
Topic: Python Jobs Yahoo Group Previous Topic   Next Topic Topic: HTTP POST problem in python

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use