Skip to content

[Python] Get ip address

It is very easy to get the ip address in python, some say socket will do the work but the ip address from the socket does not guarantee to be really ip address. Therefore, a library called ‘netifaces’ helped us to do the trick.

Normally you just use: netifaces.interfaces() to get all information, those information vary on different platform (Linux, Mac, Windows). The follow snippet prints out the relevant interfaces information on Windows system

So the real ip address on windows system is:

and on Mac:



Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.