records.txt文件中?

可以使用以下代码:

with open('records.txt', 'w') as f:
    f.write('活动主机IP地址\t\tMAC地址\n')
    for ip, mac in active_hosts.items():
        f.write(ip + '\t' + mac + '\n')

其中,active_hosts是一个字典,包含了局域网内扫描到的活动主机的IP地址和MAC地址。在上述代码中,首先在文件中写入表头,然后遍历字典中的每一项,将IP地址和MAC地址写入文件中。每一行的内容用\t分隔,使用\n换行。最后,with语句结束时,文件会自动关闭。

def save_records active_hosts = scan_networkifname with openrecordstxt w as f fwrite活动主机IP地址ttMAC地址n for ip mac in ip_mac_dictitems fwriteip + t + mac + n fwriten

原文地址: https://www.cveoy.top/t/topic/fnBR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录