Advertisement
AntonioVillanueva

Direcciones IP python

Feb 5th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def get_ip_addresses():
  2.     ips = {}
  3.     for ifaceName in interfaces():
  4.         addresses = [i['addr']
  5.                      for i in ifaddresses(ifaceName).setdefault(AF_INET,
  6.                                                 [{'addr':'No IP addr'}])]
  7.         if len(addresses):
  8.             ips[ifaceName] = addresses[0]
  9.     return ips
  10.  
  11.  
  12. print ( get_ip_addresses())
  13.  
  14.  
  15. """
  16. #from netifaces import interfaces, ifaddresses, AF_INET
  17. for ifaceName in interfaces():
  18.    addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}] )]
  19.    print ( '%s: %s' %(ifaceName, ', '.join(addresses)))
  20. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement