NewFuture / DDNS

:triangular_flag_on_post: 自动更新域名解析到本机IP(支持dnspod,阿里DNS,CloudFlare,华为云,DNSCOM...)
https://ddns.newfuture.cc/
MIT License
4.31k stars 657 forks source link

[feature]随手写了段代码,用于【多网卡】下的【手动】IPv6地址选择,有需要自行取用 #307

Closed hs-t closed 2 years ago

hs-t commented 2 years ago
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]即可