Last active
February 19, 2019 07:30
-
-
Save tawateer/4d9aa1e152ee0458a7259425bcab4183 to your computer and use it in GitHub Desktop.
根据网段和掩码查询起始和结束 IP
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from IPy import IP | |
file_path = "/Users/wateer/Downloads/1" | |
""" | |
file content like this: | |
183.232.67.128 255.255.255.240 | |
183.232.76.98 255.255.255.248 | |
219.135.102.128 255.255.255.224 | |
219.135.102.32 255.255.255.240 | |
221.5.37.34 255.255.255.248 | |
""" | |
def process(ip, mask): | |
x = IP(ip).make_net(mask) | |
return str(x[0]), str(x[-1]) | |
def main(): | |
with open(file_path) as f: | |
for i in f: | |
ip = i.strip().split()[0] | |
mask = i.strip().split()[1] | |
x = process(ip, mask) | |
print x[0], x[1] | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment