title: How to get all IP addresses using Python (Windows)?
body: <p>I've been reading about the following solutions here, but it only works for one IP Address only. I'm not able to print the rest of the IPs (multiple network/wireless cards).</p>
  
  <p><strong>References</strong></p>
  
  <ol>
  <li><p><a href="http://net-informations.com/python/net/ipadress.htm" rel="nofollow noreferrer">http://net-informations.com/python/net/ipadress.htm</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib?page=2&amp;tab=votes#tab-top">Finding local IP addresses using Python&#39;s stdlib</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/270745/how-do-i-determine-all-of-my-ip-addresses-when-i-have-multiple-nics">How do I determine all of my IP addresses when I have multiple NICs?</a></p></li>
  </ol>
  
  <pre class="lang-none prettyprint-override"><code>C:\&gt;ipconfig | findstr IPv4
     IPv4 Address. . . . . . . . . . . : 192.168.1.1
     IPv4 Address. . . . . . . . . . . : 192.168.5.1
  
  C:\&gt;python
  Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import socket
  &gt;&gt;&gt; print (socket.gethostbyname(socket.gethostname()))
  192.168.5.1
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Please let me know how to print all IP Addresses in Python.</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>As suggested by Rahul, I've tried the following code but it didn't return anything on the screen.</p>
  
  <pre><code>c:\Python\Codes&gt;more ip.py
  from netifaces import interfaces, ifaddresses, AF_INET
  
  def ip4_addresses():
      ip_list = []
      for interface in interfaces():
          for link in ifaddresses(interface)[AF_INET]:
              ip_list.append(link['addr'])
      return ip_list
  
  c:\Python\Codes&gt;
  
  c:\Python\Codes&gt;ip.py
  
  c:\Python\Codes&gt;
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>I've also tried Elemag's code as suggested <a href="https://stackoverflow.com/a/33946251/9013730">here</a>. It works on Python interpreter but not when I save the code to .py</p>
  
  <pre><code>c:\Python\Codes&gt;python
  Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt;
  &gt;&gt;&gt; [netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr'] for iface in netifaces.interfaces() if netifaces.AF_INET in netifa
  ces.ifaddresses(iface)]
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  NameError: name 'netifaces' is not defined
  &gt;&gt;&gt;
  &gt;&gt;&gt; import netifaces
  &gt;&gt;&gt; [netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr'] for iface in netifaces.interfaces() if netifaces.AF_INET in netifa
  ces.ifaddresses(iface)]
  ['192.168.1.10', '192.168.56.1', '127.0.0.1']
  &gt;&gt;&gt;
  &gt;&gt;&gt; ^Z
  </code></pre>
  
  <p>It's not working when I save the code into .py</p>
  
  <pre><code>c:\Python\Codes&gt;more test.py
  [netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr'] for iface in netifaces.interfaces() if netifaces.AF_INET in netifaces.
  ifaddresses(iface)]
  
  c:\Python\Codes&gt;test.py
  Traceback (most recent call last):
    File "c:\Python\Codes\test.py", line 1, in &lt;module&gt;
      [netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr'] for iface in netifaces.interfaces() if netifaces.AF_INET in netifa
  ces.ifaddresses(iface)]
  NameError: name 'netifaces' is not defined
  
  c:\Python\Codes&gt;
  
  c:\Python\Codes&gt;more test.py
  import netifaces
  [netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr'] for iface in netifaces.interfaces() if netifaces.AF_INET in netifaces.
  ifaddresses(iface)]
  
  c:\Python\Codes&gt;
  
  c:\Python\Codes&gt;test.py
  
  c:\Python\Codes&gt;
  </code></pre>