Python 创建文件并写入主机名和 IP 地址
import socket
filename = 'D:\test\test8.txt'
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
with open(filename, 'w') as f:
f.write('Hostname: {}
'.format(hostname))
f.write('IP Address: {}'.format(ip_address))
原文地址: http://www.cveoy.top/t/topic/osAh 著作权归作者所有。请勿转载和采集!