[Tutor] Getting my IP

pd pd@localhost.localdomain
Sat, 30 Jun 2001 20:29:21 +1000 (EST)


On Sat, 30 Jun 2001, Daniel wrote:
Thanks,
	This did the trick. Although I have been a user of unix
systems for a couple of years, I only recently switched to linux for my
home computing. I didnt know about the ifconfig command. Needless to say,
it looks like I will be having a look at the os module tonight.


> This is the first thing that came to my mind,  you might have to replace
> the interface to match with yours and change the slicing but you
> should still get the idea of what I'm doing,  just a cheesy os.popen  :)
> 
> >>> import os
> >>> ip = os.popen('/sbin/ifconfig eth0 |grep inet').read()[20:-37]
> >>> ip
> '10.0.1.3  '
> 
> 
> 
> 					--
> 					DEV
> 
> 
> On Sat, 30 Jun 2001, pd wrote:
> 
> > Hi,
> >    I dont think I made myself clear when I posted my original
> > message. The purpose of the script is to post the ip address
> > of my home pc to a webpage running on a remote host. This is what is going
> > on.
> > 
> > 1. I execute the script on my home pc.
> > 2. The script fetches a html page from the web.
> > 3. It reads the html page into a list.
> > 4. It searches the list for a specific point (<!--IP-->) .
> > 5. It inserts my IP address into the list after the marker.
> > 6. It writes the processed list to a html file.
> > 7. It sends this modified html file via ftp to
> > my webpage.
> > 
> > Any details that I need to enter are stored inside a config file which the
> > script accesses It is almost done except I cannot figure out how to find
> > out what *my* ip address is. Up until now I have just included it as a
> > variable (myIP = 218.13.23.45) for testing purposes. When I use 
> > the following line of code, I get my loopback address, as opposed to my 
> > dynamic IP address.
> > 
> > >>> from socket import *
> > >>> gethostbyname(gethostname())
> > '127.0.0.1'
> > 
> > 
> > I do not know much about networking/programming/sockets so detailed
> > answers will be greatly appreciated. I am using python 2.0, on a linux
> > box. 
> > 
> > 
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>