determining an assigned IP address
Donn Cave
donn at u.washington.edu
Mon Jun 26 12:26:51 EDT 2000
Quoth Jonathan Epstein <Jonathan_Epstein at nih.gov>:
| The following Perl code works:
|
| use Sys::Hostname;
| use Socket;
|
| $ip=gethostbyname(hostname());
| $theip=inet_ntoa($ip);
|
| It should be relatively straightforward to convert this to Python.
Indeed, just omit half of it! The inet_ntoa() in particular is
already done by socket.gethostbyname(). hostname() is
socket.gethostname(). Usually this will even return the address
you want. When it doesn't, see my previous follow-up.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list