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.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 2996
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Discussions

Who is online

Users browsing this forum: Google Feedfetcher and 4 guests