import socket

filename = 'D:\\test\\test8.txt'
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)

with open(filename, 'w') as f:
    f.write("Hostname: {}\n".format(hostname))
    f.write("IP Address: {}".format(ip_address))
用python实现在在D盘的test目录里新建test8txt并向文件中写入当前主机的主机名和ip地址

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

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