用户将输入主机名或IP地址。如果用户输入的是IP地址,我希望保持不变,但如果用户输入的是主机名,我希望使用以下方法将其转换为IP地址:
def convert(hostname):
command = subprocess.Popen(['host', hostname],
stdout=subprocess.PIPE).communicate()[0]
progress1 = re.findall(r'\d+.', command)
progress1 = ''.join(progress1)
return progress1
我该如何做呢?