[BangPypers] Python "Wat"s
Jeffrey Jose
jeffjosejeff at gmail.com
Wed Sep 11 18:13:18 CEST 2013
On Wed, Sep 11, 2013 at 9:02 PM, Vardhan Varma <vardhanvarma at gmail.com>wrote:
> 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']
>
Hows this different better than socket.gethostbyaddr?
I dont have a machine with multiple IPs, doesnt this work there?
I come from a place where you use *batteries* as much as possible, and
where shelling out is the last resort.
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>
More information about the BangPypers
mailing list