- import os
- def hostname():
- sys = os.name
- if sys == 'nt':
- hostname = os.getenv('computername')
- return hostname
- elif sys == 'posix':
- host = os.popen('echo $HOSTNAME')
- try:
- hostname = host.read()
- return hostname
- finally:
- host.close()
- else:
- return 'Unkwon hostname'
Python获取主机名
最新推荐文章于 2023-08-15 15:09:30 发布