import win32api,win32con
import os, re
def execCmd(cmd):
r = os.popen(cmd)
text = r.read()
r.close()
return text
# ===============================================
result = []
t = '未知网卡'
for r in execCmd("ipconfig /all").splitlines()[2:]:
if len(r) > 0:
if r[0] != ' ':
t = r
elif 'IPv6' in r and '%' not in r:
result += [{
't':t,
'r':r,
'ip':re.findall(r"(?<![:.\w])(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}(?![:.\w])", r, re.I)[0]
}]
# ===============================================
for i, l in zip(range(len(result)),result):
title = 'IP地址选择【{}/{}】'.format(i+1,len(result))
wb = '\n'.join([
l['t'],
l['r'],
'是否选择本行?选"是"选择本行,选"否"继续后面的选择,选"取消"取消运行'
])
msgbox_result = win32api.MessageBox(0, wb, title ,win32con.MB_YESNOCANCEL)
if msgbox_result == 6:
print(l['ip'])
break
elif msgbox_result == 7:
pass
else:
print('')
break
保存在同一目录下后,使用时只要在
index6
填入shell:python [file_name]
即可