python脚本练习

#从粘贴板读取输入,并简单筛选IP地址,打印至桌面并复制至粘贴板
import
pyperclip, re, os IpRegex = re.compile(r'''( (\d{1,3}) #IP address A class \. (\d{1,3}) #IP address B class \. (\d{1,3}) #IP address C class \. (\d{1,3}) #IP address D class )''', re.VERBOSE) text = str(pyperclip.paste()) matches = [] for groups in IpRegex.findall(text): matches.append(groups[0]) if len(matches) > 0: pyperclip.copy('\n'.join(matches)) print('\n'.join(matches)) else: print('No ip address.')

缺失:

1)未对IP地址是否合规进行判断,并且显示无法鉴别错误;

2)不支持IPv6地址;

——————————————————————————————————————————————————————————————————————————————————————

Python小白,逐步完善

posted @ 2022-07-28 20:52  Diligent_Maple  阅读(51)  评论(0)    收藏  举报