Ip address

Toby A Inkster usenet200701 at tobyinkster.co.uk
Sun Jan 28 09:54:00 EST 2007


Scripter47 wrote:

> How do i get my ip address?

Which IP address. One computer might have many IP addresses. (Indeed a
typical network-connected computer will tend to have at least one for each
connected network device, plus the special address 127.0.0.1 for the
loopback network.) How is Python supposed to know which IP address you
want?

If you don't care which address, the code supplied by Adam should work. If
you do care, then you'll probably need to write OS-specific code for each
platform you choose to support, probably parsing the output of ipconfig
(Windows) or ifconfig (Linux/UNIX/Mac) somehow.

Adam also says:
| If you are wanting to to communicate over the internet you will have 
| to get the IP of you rounter.

Not strictly true, but if your network uses NAT, and you want some host
outside your network to be able to *connect to you*, then yes, you need the
IP address of your router. If you're not using NAT, then you shouldn't
need to worry about your router, as IP addresses alone provide full
end-to-end routing. (Indeed that's the whole point of IP.)

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!



More information about the Python-list mailing list