On Wed, Sep 11, 2013 at 9:02 PM, Vardhan Varma <vardhanva...@gmail.com>wrote:
> On Wed, Sep 11, 2013 at 8:42 PM, Pranjal Mittal < > pranjal.mittal.ec...@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.mak...@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@python.org > https://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers