Finding address of all NICs connected on machine

A forum for general discussion of the Python programming language.

Finding address of all NICs connected on machine

Postby pratik.prajapati » Thu Jul 10, 2014 11:19 am

Code: Select all
import socket
print socket.gethostbyname_ex(socket.gethostname())[2]


Above code is working fine for windows machine, but on linux machine it returns 127.0.0.1
Please advice how to correct above code to make it work on linux.
I know how to implement this using netifaces but i dont want to add any external dependency.
Last edited by stranac on Thu Jul 10, 2014 11:47 am, edited 1 time in total.
Reason: First post lock.
pratik.prajapati
 
Posts: 1
Joined: Thu Jul 10, 2014 11:13 am

Re: Finding address of all NICs connected on machine

Postby micseydel » Thu Jul 10, 2014 8:18 pm

I don't know much about this, but you could look at the code of the dependency you don't want see how that works.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1443
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests