Created
April 15, 2019 01:09
-
-
Save acdimalev/6a8f7f47d03005a40d2149272fc464ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import pyroute2 | |
ip = pyroute2.IPRoute() | |
addrs = [ | |
'/'.join(( | |
dict(addr.get('attrs', [])).get('IFA_ADDRESS'), | |
str(addr.get('prefixlen')), | |
)) | |
for addr in ip.get_addr( | |
scope=0, # global | |
family=socket.AF_INET, | |
) | |
] | |
for addr in addrs: | |
print(addr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import pyroute2 | |
ip = pyroute2.IPRoute() | |
addrs = [ | |
'/'.join(( | |
dict(addr.get('attrs', [])).get('IFA_ADDRESS'), | |
str(addr.get('prefixlen')), | |
)) | |
for addr in ip.get_addr( | |
scope=0, # global | |
family=socket.AF_INET6, | |
) | |
] | |
for addr in addrs: | |
print(addr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment