Created
October 11, 2017 09:10
-
-
Save ferstar/fb9156300827f6eb18aa5e219970cfec to your computer and use it in GitHub Desktop.
初学 Python ,求大佬指导个 Python 思路 https://www.v2ex.com/t/396718
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 sys | |
def main(fp): | |
print('ip\tmask') | |
with open(fp, 'r') as fh: | |
for line in fh: | |
line_trim = line.strip() | |
if line_trim.startswith('ip address'): | |
lst = line_trim.split() | |
ip, mask = lst[2], lst[3] | |
print('{}\t{}'.format(ip, mask)) | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print("usage: {} <ip_file>".format(sys.argv[0])) | |
sys.exit(1) | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python ip_mask.py ip.txt # 输出 ip mask 192.168.234.17 255.255.255.240 192.168.23.65 255.255.255.192 192.168.4.1 255.255.255.0