[Tutor] IP Address
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Wed, 22 May 2002 11:38:50 -0700 (PDT)
On Wed, 22 May 2002, Chad Crabtree wrote:
> I would like to make a script that Would FTP Post my home computer's IP
> address to my homepage. However I just cannot figure out how to get the
> IP i've looked over the Module reference. I am just not seeing it.
Hi Chad,
Hmmm... I couldn't find it in the library reference either. However,
if you're running on a Unix system, you can use the 'ifconfig' file to
read your ip address. For example:
###
dyoo@hkn:~$ /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:A0:CC:65:1E:95
inet addr:128.32.138.82 Bcast:128.32.138.255
Mask:255.255.255.0
[extra stuff omitted]
###
So it's possible to use Python to run an outside program like ifconfig,
and read off the IP address from the program's output. The 'os.popen()'
command might be useful for this.
I did a quick search, and found the following script:
IP Address Change Detection Script:
http://opag.ca/resources/code/dhcpSMS.py
There was some discussion on writing a Python module that didn't depend on
running 'ifconfig' externally on the main Python list a while back:
http://mail.python.org/pipermail/python-list/1999-August/008794.html
I'm not quite sure on the status of the module; you might want to ask on
comp.lang.python to see if someone had the time to write it.
Good luck to you!