SHARE
TWEET

get_all_private_addrs

DeaD_EyE Jun 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ipaddress import ip_address
  2. from netifaces import (
  3.     interfaces, ifaddresses, AF_INET,
  4.     )
  5.  
  6.  
  7. def get_all_private_ips(address_family=AF_INET):
  8.     res = []
  9.     for interface in interfaces():
  10.         addresses = ifaddresses(interface)
  11.         for addr in addresses.get(address_family, []):
  12.             addr = ip_address(addr['addr'])
  13.             if addr.is_private and not addr.is_loopback:
  14.                 res.append(str(addr))
  15.     return res
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top