Skip to content

Instantly share code, notes, and snippets.

@otms61
Created July 25, 2014 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otms61/3ba3b480b8a97a3c9ccf to your computer and use it in GitHub Desktop.
Save otms61/3ba3b480b8a97a3c9ccf to your computer and use it in GitHub Desktop.
summarize ip address range
from ipaddress import ip_address, summarize_address_range
first = ip_address(u'192.168.1.0')
last = ip_address(u'192.168.1.255')
print list(summarize_address_range(first, last))
# output
# [IPv4Network(u'192.168.1.0/24')]
@otms61
Copy link
Author

otms61 commented Jul 25, 2014

python 2系で実行するにはipaddressというライブラリが必要
sudo easy_install ipaddress
で導入できる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment