[BangPypers] Python "Wat"s
Vardhan Varma
vardhanvarma at gmail.com
Wed Sep 11 17:32:47 CEST 2013
On Wed, Sep 11, 2013 at 8:42 PM, Pranjal Mittal <
pranjal.mittal.ece10 at iitbhu.ac.in> wrote:
> Here you go-
>
> import socket
> socket.gethostbyaddr(socket.gethostname())[2]
>
>
> On Wed, Sep 11, 2013 at 8:16 PM, ashish makani <ashish.makani at gmail.com
> >wrote:
>
> > Found this quick, nifty way to determine the ip address of the machine
> your
> > py script is running on
> >
> > import commands
> > commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:]
>
>
Several machines have multiple IP addresses, and 0x7f000001 is least
interesting one..
On most modern linux distros, 'hostname -I' also works.
>>> commands.getoutput('hostname -I').split()
['192.168.1.120', '11.22.103.1']
More information about the BangPypers
mailing list