识别设备hostname
hosname格式:hostname#,后边会带一个#特殊字符,通过正则把#前的字符串提取出来识别设备hostname。
import re
with open('端口识别结果.txt', 'r', encoding='utf-8') as file:
for line in file:
match = re.search(r'\"(.*?)\#', line)
if match:
content = match.group(1)
print(content)